diff --git a/tests/e2e/main_test.go b/tests/e2e/main_test.go index 0086992bd1f35b487adf73b5f7a1a4bdc1a271d6..eb73108c7234e473fafe1bc2de36940347f03670 100644 --- a/tests/e2e/main_test.go +++ b/tests/e2e/main_test.go @@ -17,6 +17,7 @@ package e2e import ( "log" "os" + "strings" "testing" "time" @@ -57,7 +58,6 @@ func testMain(m *testing.M) int { } func TestQueryPrometheus(t *testing.T) { - t.Parallel() queries := []struct { query string expectN int @@ -72,8 +72,8 @@ func TestQueryPrometheus(t *testing.T) { query: `up{job="apiserver"} == 1`, expectN: 1, }, { - query: `up{job="kube-state-metrics"} == 1`, - expectN: 1, + query: `up{job="kube-state-metrics"} == 1`, + expectN: 1, }, { query: `up{job="prometheus-k8s"} == 1`, expectN: 1, @@ -116,3 +116,25 @@ func TestQueryPrometheus(t *testing.T) { t.Fatal(err) } } + +func TestDroppedMetrics(t *testing.T) { + // query metadata for all metrics and their metadata + md, err := promClient.metadata("{job=~\".+\"}") + if err != nil { + log.Fatal(err) + } + for _, k := range md.Data { + // check if the metric' help text contains Deprecated + if strings.Contains(k.Help, "Deprecated") { + // query prometheus for the Deprecated metric + n, err := promClient.query(k.Metric) + if err != nil { + log.Fatal(err) + } + if n > 0 { + t.Fatalf("deprecated metric with name: %s and help text: %s exists.", k.Metric, k.Help) + } + } + + } +} diff --git a/tests/e2e/prometheus_client.go b/tests/e2e/prometheus_client.go index b87ce3e5fff8ca7f4b32d392304d2c007eb8703b..89e25c0a3faa7af1a6638b22976c441473ef8c51 100644 --- a/tests/e2e/prometheus_client.go +++ b/tests/e2e/prometheus_client.go @@ -15,6 +15,10 @@ package e2e import ( + "bytes" + "encoding/json" + "fmt" + "k8s.io/client-go/kubernetes" "github.com/Jeffail/gabs" @@ -50,3 +54,41 @@ func (c *prometheusClient) query(query string) (int, error) { n, err := res.ArrayCountP("data.result") return n, err } + +type Metadata struct { + Status string `json:"status,omitempty"` + Data []Data `json:"data,omitempty"` +} + +type Data struct { + Metric string `json:"metric,omitempty"` + Help string `json:"help,omitempty"` +} + +// metadata makes a request against the Prometheus /api/v1/targets/metadata endpoint. +// It returns all the metrics and its metadata. +func (c *prometheusClient) metadata(query string) (Metadata, error) { + req := c.kubeClient.CoreV1().RESTClient().Get(). + Namespace("monitoring"). + Resource("pods"). + SubResource("proxy"). + Name("prometheus-k8s-0:9090"). + Suffix("/api/v1/targets/metadata").Param("match_target", query) + + var data Metadata + b, err := req.DoRaw() + if err != nil { + return data, err + } + + r := bytes.NewReader(b) + decoder := json.NewDecoder(r) + err = decoder.Decode(&data) + if err != nil { + return data, err + } + if data.Status != "success" { + return data, fmt.Errorf("status of returned response was not successful; status: %s", data.Status) + } + return data, err +}