k8ssandra / management-api-for-apache-cassandra

RESTful / Secure Management Sidecar for Apache Cassandra
Apache License 2.0
72 stars 51 forks source link

Add name filter parameter to /metrics endpoint #363

Closed burmanm closed 1 year ago

burmanm commented 1 year ago

Allows fetching a single metric by using a metric name filter. For example:

➜  management-api-for-apache-cassandra git:(master) ✗ curl 'localhost:9000/metrics?name=org_apache_cassandra_metrics_dropped_message_dropped_total'
# HELP org_apache_cassandra_metrics_dropped_message_dropped_total 
# TYPE org_apache_cassandra_metrics_dropped_message_dropped_total counter
org_apache_cassandra_metrics_dropped_message_dropped_total{host="32ad1821-f0ee-4f65-bea6-49364f5065a6",instance="10.244.2.3",cluster="Test Cluster",datacenter="dc2",rack="r1",pod_name="cluster2-dc2-r1-sts-0",node_name="kind-worker",message_type="INTERNAL_RSP",} 0.0
org_apache_cassandra_metrics_dropped_message_dropped_total{host="32ad1821-f0ee-4f65-bea6-49364f5065a6",instance="10.244.2.3",cluster="Test Cluster",datacenter="dc2",rack="r1",pod_name="cluster2-dc2-r1-sts-0",node_name="kind-worker",message_type="PAXOS_PREPARE_REQ",} 0.0
org_apache_cassandra_metrics_dropped_message_dropped_total{host="32ad1821-f0ee-4f65-bea6-49364f5065a6",instance="10.244.2.3",cluster="Test Cluster",datacenter="dc2",rack="r1",pod_name="cluster2-dc2-r1-sts-0",node_name="kind-worker",message_type="PAXOS2_CLEANUP_RSP2",} 0.0
org_apache_cassandra_metrics_dropped_message_dropped_total{host="32ad1821-f0ee-4f65-bea6-49364f5065a6",instance="10.244.2.3",cluster="Test Cluster",datacenter="dc2",rack="r1",pod_name="cluster2-dc2-r1-sts-0",node_name="kind-worker",message_type="PAXOS2_PREPARE_REFRESH_RSP",} 0.0

This relies on the internal Prometheus implementation for filtering (which sadly does not expose additional capabilities other than metric name filtering).

Fixes #349

burmanm commented 1 year ago

I couldn't think of an easy way to test this. Perhaps an IT test at some point with live Cassandra node..