Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions api-tests/alerting/alerting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ func TestTemplatesAPI(t *testing.T) {
Context: pmmapitests.Context,
})
require.NoError(t, err)
defer deleteTemplate(t, client, name)
t.Cleanup(func() {
deleteTemplate(t, client, name)
})

resp, err := client.ListTemplates(&alerting.ListTemplatesParams{
Reload: pointer.ToBool(true),
Expand Down Expand Up @@ -466,17 +468,18 @@ func TestTemplatesAPI(t *testing.T) {

templateNames[name] = struct{}{}
}
defer func() {
t.Cleanup(func() {
for name := range templateNames {
deleteTemplate(t, client, name)
}
}()
})

// list rules, so they are all on the first page
listAllTemplates, err := client.ListTemplates(&alerting.ListTemplatesParams{
PageSize: pointer.ToInt32(100),
PageIndex: pointer.ToInt32(0),
Context: pmmapitests.Context,
Reload: pointer.ToBool(true),
})
require.NoError(t, err)

Expand Down
Binary file added docs/assets/advisors/pmm-advisor-insights.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/managed/access-control.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Access Control

PMM Server supports managing access to individual metrics in VictoriaMetrics.
[vmproxy](https://github.com/percona/pmm/tree/main/vmproxy) is placed in front of VictoriaMetrics and helps add extra filters to each query to filter access to metrics, such as `{env=~"prod|staging"}`.
[vmproxy](https://github.com/percona/pmm/tree/v3/vmproxy) is placed in front of VictoriaMetrics and helps add extra filters to each query to filter access to metrics, such as `{env=~"prod|staging"}`.

Each Grafana user can be assigned multiple roles in PMM Server. A PMM Server role is different from Grafana roles (viewer, editor, admin).
A PMM Server role defines extra filters to be applied to a query. This way access to metrics can be limited per role.
Expand Down
31 changes: 17 additions & 14 deletions managed/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing notes

**pmm-managed** is a core component of PMM Server. As such, its development and testing is best done inside of a PMM Server container, which we call "devcontainer". You can take a look at PMM's architecture [here](https://www.percona.com/doc/percona-monitoring-and-management/details/architecture.html)
**pmm-managed** is a core component of PMM Server. As such, its development and testing is best done inside of a PMM Server container, which we call "devcontainer". You can take a look at PMM's architecture [here](https://docs.percona.com/percona-monitoring-and-management/3/reference/index.html).

# Devcontainer setup

Expand Down Expand Up @@ -94,24 +94,26 @@ If there is a need to change the logic of Advisor checks (actual logic executed

Changes to Advisors will be most visible in the list of all advisors by categories, such as https://pmmdemo.percona.com/graph/advisors/configuration.

<img width="1024" alt="image" src="https://github.com/percona/checked/assets/25495422/6b369cd6-f080-49aa-a132-72db5fbdf046">
![Advisors interface](../docs/assets/advisors/pmm-advisor-interface.png)

``advisors.summary`` = https://github.com/percona/checked/blob/223ae162ced83793bc00e5e6c29edfbf1bf5e27e/data/advisors/example.yml.example#L4
``advisors.summary`` = https://github.com/percona/pmm/blob/b951d3c14eb1d5e4d716a61811da599af869054b/managed/data/advisors/example.yml.example#L5

``advisors.description`` = https://github.com/percona/checked/blob/223ae162ced83793bc00e5e6c29edfbf1bf5e27e/data/advisors/example.yml.example#L6

### Advisor Checks

Advisors checks refer to the list of Advisors categorized by specific topics available on https://pmmdemo.percona.com/graph/advisors/configuration. It provides detailed information in the Insights section, which can be accessed by expanding the Advisor.

<img width="1024" alt="image" src="https://github.com/percona/checked/assets/25495422/7ec59008-f888-4c98-9be9-3eeb39dd6c0e">
![Advisors by categories](../docs/assets/advisors/pmm-configuration-advisors.png)

``checks.summary`` = https://github.com/percona/checked/blob/223ae162ced83793bc00e5e6c29edfbf1bf5e27e/data/checks/exampleV2.yml.example#L5
``chcks.description`` = https://github.com/percona/checked/blob/223ae162ced83793bc00e5e6c29edfbf1bf5e27e/data/checks/exampleV2.yml.example#L6


When an Advisor check identifies an issue in the user's infrastructure, it displays insights on the https://pmmdemo.percona.com/graph/advisors/insights page.
<img width="1024" alt="image" src="https://github.com/percona/checked/assets/25495422/b44089e0-7c1f-46b2-96d2-43d205e1c3fe">

![Advisor Insight](../docs/assets/advisors/pmm-advisor-insights.png)

``results.summary`` = https://github.com/percona/checked/blob/223ae162ced83793bc00e5e6c29edfbf1bf5e27e/data/checks/exampleV2.yml.example#L51
``results.descrioption`` = https://github.com/percona/checked/blob/223ae162ced83793bc00e5e6c29edfbf1bf5e27e/data/checks/exampleV2.yml.example#L52

Expand All @@ -120,7 +122,7 @@ Please note, there might be several results[] in one check file.

## Working with Percona Alerting

Please go through the Percona Alerting section in our [user documentation](https://docs.percona.com/percona-monitoring-and-management/get-started/alerting.html).
Please go through the Percona Alerting section in our [user documentation](https://docs.percona.com/percona-monitoring-and-management/3/alert/index.html).

### Contributing to Percona Alerting Templates

Expand All @@ -130,9 +132,9 @@ You can read more about the [Alert Templates format in our documentation]https:/

# Internals

There are three makefiles: `Makefile` (host), `Makefile.devcontainer`, and `Makefile.include`. `Makefile.devcontainer` is mounted on top of `Makefile` inside devcontainer (see `docker-compose.yml`) to enable `make env TARGET=target-name` usage.
There are three makefiles: `Makefile` (host), `Makefile.devcontainer`, and `Makefile.include`. `Makefile.devcontainer` is mounted on top of `Makefile` inside the devcontainer (see `docker-compose.yml`) to enable `make env TARGET=target-name` usage.

Devcontainer initialization code is located in `.devcontainer/setup.py`. It uses multiprocessing to run several commands in parallel to speed-up the setup.
Devcontainer initialization code is located in `.devcontainer/setup.py`. It provisions several binaries required for code development.

## Code Structure

Expand All @@ -147,15 +149,16 @@ Devcontainer initialization code is located in `.devcontainer/setup.py`. It uses
├── utils - utilities
```

# How to make PR
# How to make a Pull Request (PR)

- If the changes require multiple PRs spanning multiple repos, make sure to keep the branch names the same.
- If the PR requires any API changes, make sure to contribute to the API docs (/docs/api).
- If the PR changes any of `deps.go` files, make sure to run `make gen` to generate mock clients.

- If the changes require multiple PRs spanning multiple repos make sure to keep the branch names same.
- If the PR requires any API changes then make your changes in `main` branch of the [API repo](https://github.com/percona/pmm) and pull those changes in your pmm-managed branch by mentioning the API changes branch name in the `Gopkg.toml` constraint and running `dep ensure -v -update github.com/percona/pmm`.
- If the PR changes any files named `deps.go` make sure to run `make gen` to generate mock clients.
Before making PR, please run these commands locally:
Before making a PR, please run these commands locally:
- `make env TARGET=check-all` to run all checkers and linters.
- `make env TARGET=test-race` to run tests.
- For help, please post on the [PMM 2.x Forums](https://forums.percona.com/c/percona-monitoring-and-management-pmm/percona-monitoring-and-management-pmm-v2/)
- For help, please post on the [PMM 3.x Forums](https://forums.percona.com/c/percona-monitoring-and-management-pmm/pmm-3/)

## VSCode

Expand Down
1 change: 1 addition & 0 deletions managed/cmd/pi-validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func loadAndValidateChecks(dir string) (map[string]check.Check, error) {

if len(checks) != 1 {
validationErrors = append(validationErrors, fmt.Errorf("expected exactly one check in %s", fileName))
return nil, errors.Join(validationErrors...)
}
c := checks[0]

Expand Down
49 changes: 0 additions & 49 deletions managed/data/checks/exampleV1.yml.example

This file was deleted.

1 change: 1 addition & 0 deletions managed/data/checks/exampleV2.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ checks:
# Any other value (for example, string) is treated as script execution failure
# (Starlark does not support Python exceptions);
# it is recommended to use global function `fail` for that instead.

results = []

for row in docs[0]:
Expand Down
20 changes: 7 additions & 13 deletions managed/data/checks/mongodb_active_vs_available_connections.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
---
### MongoDB Platform Advisors Active vs Available Connections
checks:
- version: 1
- version: 2
name: mongodb_active_vs_available_connections
summary: MongoDB Active vs Available Connections
description: This check returns warnings if the ratio between active and available connections is higher than 75%
type: MONGODB_GETDIAGNOSTICDATA
#family: mongodb
family: MONGODB
#author: Corrado Pandiani
advisor: configuration_generic
interval: standard
queries:
- type: MONGODB_GETDIAGNOSTICDATA
script: |
def check(docs):
# for compatibility with PMM Server < 2.12
context = {
"format_version_num": format_version_num,
"parse_version": parse_version,
}
return check_context(docs, context)

def check_context(docs, context):
"""
This check returns warnings if number of active connections is too high.
"""

if len(docs) != 1:
rows = docs[0]
if len(rows) != 1:
return "Unexpected number of documents"

results = []

data = docs[0]["data"]
data = rows[0]["data"]
active_connections = data.get("serverStatus").get("connections").get("active")
available_connections = data.get("serverStatus").get("connections").get("available")
ratio = 100*active_connections/(active_connections+available_connections)
Expand Down
21 changes: 7 additions & 14 deletions managed/data/checks/mongodb_auth.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
---
checks:
- version: 1
- version: 2
name: mongodb_auth
summary: MongoDB authentication
description: Warns if MongoDB authentication is disabled.
type: MONGODB_GETCMDLINEOPTS
#family: mongodb
family: MONGODB
advisor: security_authentication
interval: standard
queries:
- type: MONGODB_GETCMDLINEOPTS
script: |
def check(docs):
# for compatibility with PMM Server < 2.12
context = {
"format_version_num": format_version_num,
"parse_version": parse_version,
}
return check_context(docs, context)
def check_context(docs, context):
"""
This check returns warnings if MongoDB authentication is disabled.
"""
if len(docs) != 1:
rows = docs[0]
if len(rows) != 1:
return "Unexpected number of documents"
results = []
parsed = docs[0]["parsed"]
parsed = rows[0]["parsed"]
print(repr(parsed))
security = parsed.get("security", {})
Expand Down
23 changes: 11 additions & 12 deletions managed/data/checks/mongodb_authmech_scramsha256.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
---
checks:
- version: 1
- version: 2
name: mongodb_authmech_scramsha256
summary: MongoDB Security AuthMech Check
description: This check returns warnings if MongoDB is not using the default SHA-256 hashing function as its SCRAM authentication method.
type: MONGODB_GETPARAMETER
#family: mongodb
family: MONGODB
#author: Kimberly Wilkins
advisor: security_configuration
interval: standard
queries:
- type: MONGODB_GETPARAMETER
script: |
read_url = "https://docs.percona.com/percona-platform/advisors/checks/{}.html"
def check(docs):
# for compatibility with PMM Server < 2.12
context = {
"format_version_num": format_version_num,
"parse_version": parse_version,
}
return check_context(docs, context)

def check_context(docs, context):
"""
This check returns a warning if MongoDB authentication is not using the default SCRAM-SHA-256.
"""
if len(docs) != 1:

rows = docs[0]
if len(rows) != 1:
return "Unexpected number of documents"

results = []
parsed = docs[0]["parsed"]
parsed = rows[0]["parsed"]
authMechanism = "SCRAM-SHA-256" not in parsed.get("authenicationMechanisms")

if authMechanism:
results.append({
"summary": "MongoDB is not using the default SCRAM-SHA-256 authenticationMechanisms - v4.0 and above",
Expand Down
22 changes: 10 additions & 12 deletions managed/data/checks/mongodb_bindip.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
---
checks:
- version: 1
- version: 2
name: mongodb_bindip
summary: MonogDB IP bindings
description: This check returns warnings if the MongoDB network binding is not set as recommended.
type: MONGODB_GETCMDLINEOPTS
#family: mongodb
family: MONGODB
#author: Divyanshu Soni
advisor: security_connection
interval: standard
queries:
- type: MONGODB_GETCMDLINEOPTS
script: |
read_url = "https://docs.percona.com/percona-platform/advisors/checks/{}.html"
def check(docs):
# for compatibility with PMM Server < 2.12
context = {
"format_version_num": format_version_num,
"parse_version": parse_version,
}
return check_context(docs, context)

def check_context(docs, context):
"""
This check returns warnings if MongoDB network binding is not set as recommended.
"""
if len(docs) != 1:

rows = docs[0]
if len(rows) != 1:
return "Unexpected number of documents"

results = []
parsed = docs[0]["parsed"]
parsed = rows[0]["parsed"]
print(repr(parsed))
net = parsed.get("net", {})
bindIP = (net.get("bindIp") == "0.0.0.0")
Expand Down
12 changes: 4 additions & 8 deletions managed/data/checks/mongodb_connection_sudden_spike.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ checks:
script: |
read_url = "https://docs.percona.com/percona-platform/advisors/checks/{}.html"

def check(docs):
def check_context(docs, context):
#Gathering initial connection count.
prev_conn = int(docs[0][0]["values"][0][1])
results = []
connections = []
cnt = 0
current_conn = []
Expand All @@ -42,18 +41,15 @@ checks:

prev_conn = int(type[1])

results = []

if cnt > 0:
return({
results.append({
"summary": "MongoDB sudden spike(> 50%) in connections than the usual count in last 24hrs",
"description": "In the last 24 hours, we observed that there were {} times that a sudden spike (> 50%) in the number of connections occurred that was higher than the most recent or normal number of connections. This increase could indicate or cause performance issues unless your overall system is designed to handle spikes of this type. Please check for any changes that may have occurred during that time span to cause this. Here are the stats respectively - Spiked Connections - {}, Previous Connections - {}, Percentage of Spike - {} ".format(cnt, current_conn, previous_conn, actual_perc),
"read_more_url": read_url.format("mongodb-connection-spike"),
"severity": "warning",
"labels": {},
})

def check_context(docs, context):
results = []
check_result = check(docs)
if check_result:
results.append(check_result)
return results
Loading
Loading