Skip to content

Commit

Permalink
Default metrics filters for new metrics agent (#834)
Browse files Browse the repository at this point in the history
* Start stubbing out methods for agent config.
* Add reconciliation logic, tests.
* CRD upgrades, codegen upgrades.
* Make type names more concise.
* The Endpoint type within the CassandraAgentSpec needs to be a pointer as it must be optional from the perspective of the CR so that it can have defaulting behaviour in the controller.
* Replace Cassandra agent `filters` field with `relabels`.
* Update metric-collector.yaml to metrics-collector.yaml
* Make changes to default metrics so that new metrics name format is correctly parsed by regex.
  • Loading branch information
Miles-Garnsey authored Mar 8, 2023
1 parent 632ede9 commit a7cbbbc
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 26 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions apis/telemetry/v1alpha1/telemetry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ type McacTelemetrySpec struct {
}

type CassandraAgentSpec struct {
Endpoint Endpoint `json:"endpoint,omitempty"`
Filters []promapi.RelabelConfig `json:"filters,omitempty"`
Endpoint *Endpoint `json:"endpoint,omitempty"`
Relabels []promapi.RelabelConfig `json:"relabels,omitempty"`
}

type Endpoint struct {
Expand Down
10 changes: 7 additions & 3 deletions apis/telemetry/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13740,7 +13740,7 @@ spec:
port:
type: string
type: object
filters:
relabels:
items:
description: 'RelabelConfig allows dynamic
rewriting of the label set, being
Expand Down Expand Up @@ -14259,7 +14259,7 @@ spec:
port:
type: string
type: object
filters:
relabels:
items:
description: 'RelabelConfig allows dynamic
rewriting of the label set, being applied
Expand Down Expand Up @@ -16841,7 +16841,7 @@ spec:
port:
type: string
type: object
filters:
relabels:
items:
description: 'RelabelConfig allows dynamic rewriting
of the label set, being applied to samples before
Expand Down Expand Up @@ -25518,7 +25518,7 @@ spec:
port:
type: string
type: object
filters:
relabels:
items:
description: 'RelabelConfig allows dynamic rewriting
of the label set, being applied to samples before
Expand Down Expand Up @@ -28195,7 +28195,7 @@ spec:
port:
type: string
type: object
filters:
relabels:
items:
description: 'RelabelConfig allows dynamic rewriting
of the label set, being applied to samples before
Expand Down Expand Up @@ -29864,7 +29864,7 @@ spec:
port:
type: string
type: object
filters:
relabels:
items:
description: 'RelabelConfig allows dynamic rewriting
of the label set, being applied to samples before
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/reaper.k8ssandra.io_reapers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ spec:
port:
type: string
type: object
filters:
relabels:
items:
description: 'RelabelConfig allows dynamic rewriting of
the label set, being applied to samples before ingestion.
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/stargate.k8ssandra.io_stargates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ spec:
port:
type: string
type: object
filters:
relabels:
items:
description: 'RelabelConfig allows dynamic rewriting
of the label set, being applied to samples before
Expand Down Expand Up @@ -3242,7 +3242,7 @@ spec:
port:
type: string
type: object
filters:
relabels:
items:
description: 'RelabelConfig allows dynamic rewriting of
the label set, being applied to samples before ingestion.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/components/metrics-collector/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Ingress or port forwarding can be used to expose access to the Prometheus and Gr

2. How can I filter out metrics I don't care about?

Please read the [metric-collector.yaml](https://github.com/datastax/metric-collector-for-apache-cassandra/blob/master/config/metric-collector.yaml) section in the MCAC GitHub repo on how to add filtering rules.
Please read the [metrics-collector.yaml](https://github.com/datastax/metric-collector-for-apache-cassandra/blob/master/config/metrics-collector.yaml) section in the MCAC GitHub repo on how to add filtering rules.

3. What is the datalog? And what is it for?

Expand Down
1 change: 0 additions & 1 deletion docs/content/en/tasks/monitor/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ title: "Monitor K8ssandra"
linkTitle: "Monitor"
weight: 6
description: "Access tools to monitor your Apache Cassandra® cluster running in Kubernetes."
---
89 changes: 86 additions & 3 deletions pkg/telemetry/cassandra_agent/cassandra_agent_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import (
"path/filepath"
"time"

"github.com/adutra/goalesce"

cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
k8ssandraapi "github.com/k8ssandra/k8ssandra-operator/apis/k8ssandra/v1alpha1"
telemetryapi "github.com/k8ssandra/k8ssandra-operator/apis/telemetry/v1alpha1"
"github.com/k8ssandra/k8ssandra-operator/pkg/labels"
"github.com/k8ssandra/k8ssandra-operator/pkg/reconciliation"
"github.com/k8ssandra/k8ssandra-operator/pkg/result"
promapi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -21,10 +24,89 @@ import (
var (
agentConfigLocation = "/opt/management-api/configs/metrics-collector.yaml"
defaultAgentConfig = telemetryapi.CassandraAgentSpec{
Endpoint: telemetryapi.Endpoint{
Endpoint: &telemetryapi.Endpoint{
Port: "9000",
Address: "127.0.0.1",
},
Relabels: []promapi.RelabelConfig{
{
SourceLabels: []string{"table"},
Regex: ".+",
TargetLabel: "should_drop",
Replacement: "true",
},
{
SourceLabels: []string{"__name__"},
Regex: "org_apache_cassandra_metrics_table_live_ss_table_count",
TargetLabel: "should_drop",
Replacement: "false",
},
{
SourceLabels: []string{"__name__"},
Regex: "org_apache_cassandra_metrics_table_live_disk_space_used",
TargetLabel: "should_drop",
Replacement: "false",
},
{
SourceLabels: []string{"__name__"},
Regex: "org_apache_cassandra_metrics_table_memtable.*",
TargetLabel: "should_drop",
Replacement: "false",
},
{
SourceLabels: []string{"__name__"},
Regex: "org_apache_cassandra_metrics_table_all_memtables.*",
TargetLabel: "should_drop",
Replacement: "false",
},
{
SourceLabels: []string{"__name__"},
Regex: "org_apache_cassandra_metrics_table_compaction_bytes_written",
TargetLabel: "should_drop",
Replacement: "false",
},
{
SourceLabels: []string{"__name__"},
Regex: "org_apache_cassandra_metrics_table_pending_compactions",
TargetLabel: "should_drop",
Replacement: "false",
},
{
SourceLabels: []string{"__name__"},
Regex: "org_apache_cassandra_metrics_table_read_.*",
TargetLabel: "should_drop",
Replacement: "false",
},
{
SourceLabels: []string{"__name__"},
Regex: "org_apache_cassandra_metrics_table_write_.*",
TargetLabel: "should_drop",
Replacement: "false",
},
{
SourceLabels: []string{"__name__"},
Regex: "org_apache_cassandra_metrics_table_range.*",
TargetLabel: "should_drop",
Replacement: "false",
},
{
SourceLabels: []string{"__name__"},
Regex: "org_apache_cassandra_metrics_table_coordinator_.*",
TargetLabel: "should_drop",
Replacement: "false",
},
{
SourceLabels: []string{"__name__"},
Regex: "org_apache_cassandra_metrics_table_dropped_mutations",
TargetLabel: "should_drop",
Replacement: "false",
},
{
SourceLabels: []string{"should_drop"},
Regex: "true",
Action: "drop",
},
},
}
)

Expand All @@ -42,7 +124,8 @@ func (c Configurator) GetTelemetryAgentConfigMap() (*corev1.ConfigMap, error) {
var yamlData []byte
var err error
if c.TelemetrySpec.Cassandra != nil {
yamlData, err = yaml.Marshal(&c.TelemetrySpec.Cassandra)
mergedSpec := goalesce.MustDeepMerge(&defaultAgentConfig, c.TelemetrySpec.Cassandra)
yamlData, err = yaml.Marshal(&mergedSpec)
if err != nil {
return &corev1.ConfigMap{}, err
}
Expand Down Expand Up @@ -79,7 +162,7 @@ func (c Configurator) ReconcileTelemetryAgentConfig(dc *cassdcapi.CassandraDatac
recRes := reconciliation.ReconcileObject(c.Ctx, c.RemoteClient, c.RequeueDelay, *desiredCm)
switch {
case recRes.IsError():
fallthrough
return recRes
case recRes.IsRequeue():
return recRes
}
Expand Down
Loading

0 comments on commit a7cbbbc

Please sign in to comment.