-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add prometheus-adapter metrics component #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
savme
wants to merge
2
commits into
main
Choose a base branch
from
feat/hpa-prom-adapter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Prometheus Adapter Resource Metrics | ||
|
|
||
| Experimental `metrics.k8s.io` implementation backed by Prometheus Adapter. | ||
| Enable only in clusters where Prometheus or VictoriaMetrics is the source of | ||
| truth for Pod and Node CPU/memory usage. | ||
|
|
||
| This component owns the cluster-wide `v1beta1.metrics.k8s.io` APIService when | ||
| installed. Do not install it alongside another owner of the same APIService. | ||
|
|
||
| The adapter expects Datum instance resource metrics with Kubernetes identity | ||
| labels: | ||
|
|
||
| - `datum_compute_instance_cpu_usage_seconds_total{namespace, pod, container, node}` | ||
| - `datum_compute_instance_memory_working_set_bytes{namespace, pod, container, node}` | ||
|
|
||
| Runtime-specific producers, such as Unikraft telemetry, should translate their | ||
| local measurements into that shape before ingestion. The adapter then exposes | ||
| those samples through the standard Kubernetes Resource Metrics API used by HPA. | ||
|
|
||
| Infrastructure overlays must patch before enabling this component: | ||
|
|
||
| - `PROMETHEUS_URL` should point at the local Prometheus or VictoriaMetrics query | ||
| endpoint. | ||
| - `Certificate.spec.issuerRef` should point at the cluster's serving certificate | ||
| issuer. The default value is a placeholder `ClusterIssuer` named | ||
| `placeholder-issuer`. | ||
| - The component defaults to `compute-system`. If an overlay deploys it in a | ||
| different namespace, patch the `Certificate.spec.dnsNames` and the | ||
| `APIService` service namespace / `cert-manager.io/inject-ca-from` annotation | ||
| in the consuming overlay. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| apiVersion: apiregistration.k8s.io/v1 | ||
| kind: APIService | ||
| metadata: | ||
| name: v1beta1.metrics.k8s.io | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute | ||
| annotations: | ||
| cert-manager.io/inject-ca-from: compute-system/compute-prometheus-adapter-serving-cert | ||
| spec: | ||
| group: metrics.k8s.io | ||
| groupPriorityMinimum: 100 | ||
| service: | ||
| name: compute-prometheus-adapter | ||
| namespace: compute-system | ||
| port: 443 | ||
| version: v1beta1 | ||
| versionPriority: 100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: compute-prometheus-adapter-config | ||
| namespace: compute-system | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute | ||
| data: | ||
| config.yaml: | | ||
| resourceRules: | ||
| cpu: | ||
| containerQuery: | | ||
| sum by (<<.GroupBy>>) ( | ||
| rate(datum_compute_instance_cpu_usage_seconds_total{<<.LabelMatchers>>,container!=""}[2m]) | ||
| ) | ||
| nodeQuery: | | ||
| sum by (<<.GroupBy>>) ( | ||
| rate(datum_compute_instance_cpu_usage_seconds_total{<<.LabelMatchers>>}[2m]) | ||
| ) | ||
| resources: | ||
| overrides: | ||
| namespace: | ||
| resource: namespace | ||
| pod: | ||
| resource: pod | ||
| node: | ||
| resource: node | ||
| containerLabel: container | ||
| memory: | ||
| containerQuery: | | ||
| sum by (<<.GroupBy>>) ( | ||
| datum_compute_instance_memory_working_set_bytes{<<.LabelMatchers>>,container!=""} | ||
| ) | ||
| nodeQuery: | | ||
| sum by (<<.GroupBy>>) ( | ||
| datum_compute_instance_memory_working_set_bytes{<<.LabelMatchers>>} | ||
| ) | ||
| resources: | ||
| overrides: | ||
| namespace: | ||
| resource: namespace | ||
| pod: | ||
| resource: pod | ||
| node: | ||
| resource: node | ||
| containerLabel: container | ||
| window: 2m | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: compute-prometheus-adapter | ||
| namespace: compute-system | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute | ||
| spec: | ||
| serviceAccountName: compute-prometheus-adapter | ||
| securityContext: | ||
| runAsNonRoot: true | ||
| runAsUser: 65532 | ||
| runAsGroup: 65532 | ||
| seccompProfile: | ||
| type: RuntimeDefault | ||
| containers: | ||
| - name: adapter | ||
| image: registry.k8s.io/prometheus-adapter/prometheus-adapter:v0.12.0 | ||
| args: | ||
| - --secure-port=8443 | ||
| - --tls-cert-file=/certs/tls.crt | ||
| - --tls-private-key-file=/certs/tls.key | ||
| - --prometheus-url=$(PROMETHEUS_URL) | ||
| - --config=/etc/adapter/config.yaml | ||
| - --metrics-relist-interval=1m | ||
| - --metrics-max-age=2m | ||
| env: | ||
| - name: PROMETHEUS_URL | ||
| value: http://prometheus-operated.monitoring.svc:9090 | ||
| ports: | ||
| - containerPort: 8443 | ||
| name: https | ||
| protocol: TCP | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| readOnlyRootFilesystem: true | ||
| capabilities: | ||
| drop: | ||
| - ALL | ||
| livenessProbe: | ||
| httpGet: | ||
| path: /livez | ||
| port: 8443 | ||
| scheme: HTTPS | ||
| initialDelaySeconds: 15 | ||
| periodSeconds: 20 | ||
| readinessProbe: | ||
| httpGet: | ||
| path: /readyz | ||
| port: 8443 | ||
| scheme: HTTPS | ||
| initialDelaySeconds: 5 | ||
| periodSeconds: 10 | ||
| resources: | ||
| limits: | ||
| cpu: 100m | ||
| memory: 128Mi | ||
| requests: | ||
| cpu: 10m | ||
| memory: 64Mi | ||
| volumeMounts: | ||
| - name: config | ||
| mountPath: /etc/adapter | ||
| readOnly: true | ||
| - name: serving-cert | ||
| mountPath: /certs | ||
| readOnly: true | ||
| volumes: | ||
| - name: config | ||
| configMap: | ||
| name: compute-prometheus-adapter-config | ||
| - name: serving-cert | ||
| secret: | ||
| secretName: compute-prometheus-adapter-serving-cert |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| apiVersion: kustomize.config.k8s.io/v1alpha1 | ||
| kind: Component | ||
|
|
||
| resources: | ||
| - service_account.yaml | ||
| - rbac.yaml | ||
| - serving-cert.yaml | ||
| - config.yaml | ||
| - deployment.yaml | ||
| - service.yaml | ||
| - apiservice.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: compute-prometheus-adapter-resource-reader | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute | ||
| rules: | ||
| - apiGroups: [""] | ||
| resources: [nodes, pods, namespaces] | ||
| verbs: [get, list, watch] | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: compute-prometheus-adapter-resource-reader | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: compute-prometheus-adapter-resource-reader | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: compute-prometheus-adapter | ||
| namespace: compute-system | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: compute-prometheus-adapter-auth-delegator | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: system:auth-delegator | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: compute-prometheus-adapter | ||
| namespace: compute-system | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: compute-prometheus-adapter-authentication-reader | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute | ||
| rules: | ||
| - apiGroups: [""] | ||
| resources: [configmaps] | ||
| resourceNames: [extension-apiserver-authentication] | ||
| verbs: [get] | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: compute-prometheus-adapter-authentication-reader | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: compute-prometheus-adapter-authentication-reader | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: compute-prometheus-adapter | ||
| namespace: compute-system |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: compute-prometheus-adapter | ||
| namespace: compute-system | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute | ||
| spec: | ||
| selector: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| ports: | ||
| - name: https | ||
| port: 443 | ||
| protocol: TCP | ||
| targetPort: https |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: compute-prometheus-adapter | ||
| namespace: compute-system | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| apiVersion: cert-manager.io/v1 | ||
| kind: Certificate | ||
| metadata: | ||
| name: compute-prometheus-adapter-serving-cert | ||
| namespace: compute-system | ||
| labels: | ||
| app.kubernetes.io/name: compute-prometheus-adapter | ||
| app.kubernetes.io/part-of: compute | ||
| spec: | ||
| dnsNames: | ||
| - compute-prometheus-adapter.compute-system.svc | ||
| - compute-prometheus-adapter.compute-system.svc.cluster.local | ||
| issuerRef: | ||
| # Placeholder. Infra overlays must patch this issuer. | ||
| group: cert-manager.io | ||
| kind: ClusterIssuer | ||
| name: placeholder-issuer | ||
| secretName: compute-prometheus-adapter-serving-cert |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking we have these metrics be standardized around datum's naming for instances? Like
datum_compute_instance_cpu_usage_seconds_total.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point! 2d1c252