Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
kube-prometheus
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
prometheus-operator
kube-prometheus
Commits
1af59f31
Commit
1af59f31
authored
5 years ago
by
Lili Cosic
Browse files
Options
Downloads
Patches
Plain Diff
tests/e2e: Add e2e test to make sure all deprecated metrics are being
dropped
parent
6562b02d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/e2e/main_test.go
+25
-3
25 additions, 3 deletions
tests/e2e/main_test.go
tests/e2e/prometheus_client.go
+42
-0
42 additions, 0 deletions
tests/e2e/prometheus_client.go
with
67 additions
and
3 deletions
tests/e2e/main_test.go
+
25
−
3
View file @
1af59f31
...
@@ -17,6 +17,7 @@ package e2e
...
@@ -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 {
...
@@ -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) {
...
@@ -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) {
...
@@ -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
)
}
}
}
}
This diff is collapsed.
Click to expand it.
tests/e2e/prometheus_client.go
+
42
−
0
View file @
1af59f31
...
@@ -15,6 +15,10 @@
...
@@ -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) {
...
@@ -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
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment