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. #23

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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, enableMetrics OverlappingMetrics) *Exporter {
idexter marked this conversation as resolved.
Show resolved Hide resolved
var m []Metric
m = append(m, Metrics...)
if enableMetrics {
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 {
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)
}

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

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

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

func TestCollector_Describe_WithOverlappingMetrics(t *testing.T) {
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() {
c.Collect(ch)
close(ch)
}()

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

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

func TestCollector_Collect_WithOverlappingMetrics(t *testing.T) {
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