Skip to content

Commit

Permalink
Add federate to rbac proxy
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Fernandez <mariofer@redhat.com>
  • Loading branch information
marioferh committed Jun 12, 2023
1 parent 076da3b commit 5c08866
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
5 changes: 5 additions & 0 deletions assets/prometheus-k8s/kube-rbac-proxy-secret.yaml
Expand Up @@ -15,4 +15,9 @@ stringData:
"user":
"name": "system:serviceaccount:openshift-monitoring:prometheus-k8s"
"verb": "get"
- "path": "/federate"
"resourceRequest": false
"user":
"name": "system:serviceaccount:openshift-monitoring:prometheus-k8s"
"verb": "get"
type: Opaque
2 changes: 1 addition & 1 deletion assets/prometheus-k8s/prometheus.yaml
Expand Up @@ -82,7 +82,7 @@ spec:
- args:
- --secure-listen-address=0.0.0.0:9092
- --upstream=http://127.0.0.1:9090
- --allow-paths=/metrics
- --allow-paths=/metrics,/federate
- --config-file=/etc/kube-rbac-proxy/config.yaml
- --tls-cert-file=/etc/tls/private/tls.crt
- --tls-private-key-file=/etc/tls/private/tls.key
Expand Down
22 changes: 20 additions & 2 deletions jsonnet/components/prometheus.libsonnet
Expand Up @@ -203,7 +203,25 @@ function(params)
data: {},
},

kubeRbacProxySecret: generateSecret.staticAuthSecret(cfg.namespace, cfg.commonLabels, 'kube-rbac-proxy'),
kubeRbacProxySecret: generateSecret.staticAuthSecret(
cfg.namespace,
cfg.commonLabels,
'kube-rbac-proxy',
{
authorization+: {
static+: [
{
user: {
name: 'system:serviceaccount:openshift-monitoring:prometheus-k8s',
},
verb: 'get',
path: '/federate',
resourceRequest: false,
},
],
},
},
),

// Secret holding the token to authenticate against the Telemetry server when using native remote-write.
telemetrySecret: {
Expand Down Expand Up @@ -397,7 +415,7 @@ function(params)
args: [
'--secure-listen-address=0.0.0.0:9092',
'--upstream=http://127.0.0.1:9090',
'--allow-paths=/metrics',
'--allow-paths=/metrics,/federate',
'--config-file=/etc/kube-rbac-proxy/config.yaml',
'--tls-cert-file=/etc/tls/private/tls.crt',
'--tls-private-key-file=/etc/tls/private/tls.key',
Expand Down
4 changes: 2 additions & 2 deletions jsonnet/utils/generate-secret.libsonnet
@@ -1,5 +1,5 @@
{
staticAuthSecret(cfgNamespace, cfgCommonLabels, cfgName):: {
staticAuthSecret(cfgNamespace, cfgCommonLabels, cfgName, additionalConfig={}):: {
apiVersion: 'v1',
kind: 'Secret',
metadata: {
Expand All @@ -23,7 +23,7 @@
},
],
},
},),
} + additionalConfig),
},
},
}
30 changes: 30 additions & 0 deletions test/e2e/telemeter_test.go
Expand Up @@ -17,6 +17,7 @@ package e2e
import (
"context"
"errors"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -98,3 +99,32 @@ func TestTelemeterRemoteWrite(t *testing.T) {
},
)
}

// TestTelemeterClient verifies that the telemeter client can collect metrics from the monitoring stack and forward them to the telemeter server.
func TestTelemeterClient(t *testing.T) {
{
f.PrometheusK8sClient.WaitForQueryReturn(
t,
5*time.Minute,
`metricsclient_request_send{client="federate_to",job="telemeter-client",status_code="200"}`,
func(v float64) error {
if v == 0 {
return fmt.Errorf("expecting metricsclient request send more than 0 but got none")
}
return nil
},
)

f.PrometheusK8sClient.WaitForQueryReturn(
t,
5*time.Minute,
`federate_samples{job="telemeter-client"}`,
func(v float64) error {
if v < 10 {
return fmt.Errorf("expecting federate samples from telemeter client more than 10 but got %f", v)
}
return nil
},
)
}
}

0 comments on commit 5c08866

Please sign in to comment.