Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-1901 Metrics endpoint and collectors filtering. #40

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ linters-settings:

linters:
enable-all: true
disable:
- scopelint # too many false positives
- gochecknoglobals # mostly useless

issues:
exclude-use-default: false
Expand Down
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,46 @@ scrape_configs:
- job_name: rds-basic
scrape_interval: 60s
scrape_timeout: 55s
metrics_path: /basic
honor_labels: true
static_configs:
- targets:
- 127.0.0.1:9042
params:
collect[]:
- basic

- job_name: rds-enhanced
scrape_interval: 10s
scrape_timeout: 9s
metrics_path: /enhanced
honor_labels: true
static_configs:
- targets:
- 127.0.0.1:9042
params:
collect[]:
- enhanced
```

`honor_labels: true` is important because exporter returns metrics with `instance` label set.

## Collectors

### Enabled by default

Name | Description
---------|-------------
basic | Basic metrics from https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MonitoringOverview.html#monitoring-cloudwatch.
enhanced | Enhanced metrics from https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.OS.html.

### Filtering enabled collectors

The `rds_exporter` will expose all metrics from enabled collectors by default.

For advanced use the `rds_exporter` can be passed an optional list of collectors to filter metrics. The `collect[]` parameter may be used multiple times. In Prometheus configuration you can use this syntax under the [scrape config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#<scrape_config>).

```
params:
collect[]:
- basic
- enhanced
```
24 changes: 20 additions & 4 deletions basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/percona/rds_exporter/sessions"
)

//go:generate go run generate/main.go generate/utils.go

var (
scrapeTimeDesc = prometheus.NewDesc(
"rds_exporter_scrape_duration_seconds",
Expand All @@ -22,6 +20,16 @@ var (
)
)

// OverlappingMetrics flag.
type OverlappingMetrics bool

const (
// EnableOverlapping flag for enabling overlapping metrics.
EnableOverlapping OverlappingMetrics = true
// DisableOverlapping flag for disabling overlapping metrics.
DisableOverlapping OverlappingMetrics = false
)

type Metric struct {
Name string
Desc *prometheus.Desc
Expand All @@ -35,11 +43,19 @@ type Exporter struct {
}

// New creates a new instance of a Exporter.
func New(config *config.Config, sessions *sessions.Sessions) *Exporter {
// enableOverlapping is using for backward compatibility.
// See: https://jira.percona.com/browse/PMM-1901.
func New(config *config.Config, sessions *sessions.Sessions, enableOverlapping OverlappingMetrics) *Exporter {
var m []Metric
m = append(m, Metrics...)
if enableOverlapping {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one cuddle assignment allowed before if statement (from wsl)

m = append(m, MetricsOverlappingWithEnhancedCollector...)
}

return &Exporter{
config: config,
sessions: sessions,
metrics: Metrics,
metrics: m,
l: log.With("component", "basic"),
}
}
Expand Down
42 changes: 38 additions & 4 deletions basic/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,36 @@ import (
"github.com/percona/rds_exporter/sessions"
)

func getExporter(t *testing.T) *Exporter {
func getExporter(t *testing.T, enableMetrics OverlappingMetrics) *Exporter {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func getExporter is unused (from unused)

t.Helper()

cfg, err := config.Load("../config.yml")
require.NoError(t, err)
client := client.New()
sess, err := sessions.New(cfg.Instances, client.HTTP(), false)
require.NoError(t, err)
return New(cfg, sess)
return New(cfg, sess, enableMetrics)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return statements should not be cuddled if block has more than two lines (from wsl)

}

func TestCollector_Describe(t *testing.T) {
c := getExporter(t)
c := getExporter(t, DisableOverlapping)
ch := make(chan *prometheus.Desc)
go func() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one cuddle assignment allowed before go statement (from wsl)

c.Describe(ch)
close(ch)
}()

const expected = 47
descs := make([]*prometheus.Desc, 0, expected)
for d := range ch {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one cuddle assignment allowed before range statement (from wsl)

descs = append(descs, d)
}

assert.Equal(t, expected, len(descs), "%+v", descs)
}

func TestCollector_Describe_WithOverlappingMetrics(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func TestCollector_Describe_WithOverlappingMetrics is unused (from unused)

c := getExporter(t, EnableOverlapping)
ch := make(chan *prometheus.Desc)
go func() {
c.Describe(ch)
Expand All @@ -42,7 +59,24 @@ func TestCollector_Describe(t *testing.T) {
}

func TestCollector_Collect(t *testing.T) {
c := getExporter(t)
c := getExporter(t, DisableOverlapping)
ch := make(chan prometheus.Metric)
go func() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one cuddle assignment allowed before go statement (from wsl)

c.Collect(ch)
close(ch)
}()

const expected = 91
metrics := make([]helpers.Metric, 0, expected)
for m := range ch {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one cuddle assignment allowed before range statement (from wsl)

metrics = append(metrics, *helpers.ReadMetric(m))
}

assert.Equal(t, expected, len(metrics), "%+v", metrics)
}

func TestCollector_Collect_WithOverlappingMetrics(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func TestCollector_Collect_WithOverlappingMetrics is unused (from unused)

c := getExporter(t, EnableOverlapping)
ch := make(chan prometheus.Metric)
go func() {
c.Collect(ch)
Expand Down
179 changes: 0 additions & 179 deletions basic/generate/main.go

This file was deleted.

34 changes: 0 additions & 34 deletions basic/generate/utils.go

This file was deleted.

Loading