tests/e2e: Add e2e test to make sure all deprecated metrics are being
dropped
This commit is contained in:
@@ -17,6 +17,7 @@ package e2e
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -57,7 +58,6 @@ func testMain(m *testing.M) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryPrometheus(t *testing.T) {
|
func TestQueryPrometheus(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
queries := []struct {
|
queries := []struct {
|
||||||
query string
|
query string
|
||||||
expectN int
|
expectN int
|
||||||
@@ -72,8 +72,8 @@ func TestQueryPrometheus(t *testing.T) {
|
|||||||
query: `up{job="apiserver"} == 1`,
|
query: `up{job="apiserver"} == 1`,
|
||||||
expectN: 1,
|
expectN: 1,
|
||||||
}, {
|
}, {
|
||||||
query: `up{job="kube-state-metrics"} == 1`,
|
query: `up{job="kube-state-metrics"} == 1`,
|
||||||
expectN: 1,
|
expectN: 1,
|
||||||
}, {
|
}, {
|
||||||
query: `up{job="prometheus-k8s"} == 1`,
|
query: `up{job="prometheus-k8s"} == 1`,
|
||||||
expectN: 1,
|
expectN: 1,
|
||||||
@@ -116,3 +116,25 @@ func TestQueryPrometheus(t *testing.T) {
|
|||||||
t.Fatal(err)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
|
|
||||||
"github.com/Jeffail/gabs"
|
"github.com/Jeffail/gabs"
|
||||||
@@ -50,3 +54,41 @@ func (c *prometheusClient) query(query string) (int, error) {
|
|||||||
n, err := res.ArrayCountP("data.result")
|
n, err := res.ArrayCountP("data.result")
|
||||||
return n, err
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user