Skip to content

Commit

Permalink
fix (ccp) : Relabel host for Control Plane Metrics (#833)
Browse files Browse the repository at this point in the history
[comment]: # (Note that your PR title should follow the conventional
commit format: https://conventionalcommits.org/en/v1.0.0/#summary)
# PR Description

Add a relabel for host to control plane metrics

[comment]: # (The below checklist is for PRs adding new features. If a
box is not checked, add a reason why it's not needed.)
# New Feature Checklist

- [ ] List telemetry added about the feature.
- [ ] Link to the one-pager about the feature.
- [ ] List any tasks necessary for release (3P docs, AKS RP chart
changes, etc.) after merging the PR.
- [ ] Attach results of scale and perf testing.

[comment]: # (The below checklist is for code changes. Not all boxes
necessarily need to be checked. Build, doc, and template changes do not
need to fill out the checklist.)
# Tests Checklist

- [ ] Have end-to-end Ginkgo tests been run on your cluster and passed?
To bootstrap your cluster to run the tests, follow [these
instructions](/otelcollector/test/README.md#bootstrap-a-dev-cluster-to-run-ginkgo-tests).
  - Labels used when running the tests on your cluster:
    - [ ] `operator`
    - [ ] `windows`
    - [ ] `arm64`
    - [ ] `arc-extension`
- [ ] Have new tests been added? For features, have tests been added for
this feature? For fixes, is there a test that could have caught this
issue and could validate that the fix works?
  - [ ] Is a new scrape job needed?
- [ ] The scrape job was added to the folder
[test-cluster-yamls](/otelcollector/test/test-cluster-yamls/) in the
correct configmap or as a CR.
  - [ ] Was a new test label added?
- [ ] A string constant for the label was added to
[constants.go](/otelcollector/test/utils/constants.go).
- [ ] The label and description was added to the [test
README](/otelcollector/test/README.md).
- [ ] The label was added to this [PR
checklist](/.github/pull_request_template).
- [ ] The label was added as needed to
[testkube-test-crs.yaml](/otelcollector/test/testkube/testkube-test-crs.yaml).
  - [ ] Are additional API server permissions needed for the new tests?
- [ ] These permissions have been added to
[api-server-permissions.yaml](/otelcollector/test/testkube/api-server-permissions.yaml).
  - [ ] Was a new test suite (a new folder under `/tests`) added?
- [ ] The new test suite is included in
[testkube-test-crs.yaml](/otelcollector/test/testkube/testkube-test-crs.yaml).

Co-authored-by: Nina Segares <[email protected]>
Co-authored-by: Nina Segares <[email protected]>
  • Loading branch information
3 people authored Apr 15, 2024
1 parent 25201f8 commit ba61867
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ scrape_configs:
target_label: instance
action: replace
metric_relabel_configs:
# Generate host alias
- source_labels: [ host ]
action: hashmod
regex: (.+)
modulus: 10000000000000000000 # take last 19 digits of the MD5 hash. (Prom won't let us take more than this)
target_label: hostalias
- source_labels: [ host ]
regex: ^(localhost|\[::1\]):443$
target_label: hostalias
replacement: kube-apiserver
# Replace the host with hostalias
- source_labels: [ hostalias, host ]
regex: ^(.+);(.+)$
action: replace
target_label: host
- source_labels: [ __name__ ]
action: drop
regex: (go_.*|process_(cpu|max|resident|virtual|open)_.*)
regex: (go_.*|process_(cpu|max|resident|virtual|open)_.*)
- action: labeldrop
regex: hostalias
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ scrape_configs:
target_label: instance
action: replace
metric_relabel_configs:
# Generate host alias
- source_labels: [ host ]
action: hashmod
regex: ^(.+)$
modulus: 10000000000000000000 # take last 19 digits of the MD5 hash. (Prom won't let us take more than this)
target_label: hostalias
- source_labels: [ host ]
regex: ^hcp-kubernetes.*.svc.cluster.local:443$
target_label: hostalias
replacement: kube-apiserver
# Replace the host with hostalias
- source_labels: [ hostalias, host ]
regex: ^(.+);(.+)$
action: replace
target_label: host
- source_labels: [ __name__ ]
action: drop
regex: (go_.*|process_(cpu|max|resident|virtual|open)_.*)
- action: labeldrop
regex: hostalias
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ scrape_configs:
action: drop
regex: (etcd2-.*)
metric_relabel_configs:
# Generate host alias
- source_labels: [ host ]
action: hashmod
regex: ^(.+)$
modulus: 10000000000000000000 # take last 19 digits of the MD5 hash. (Prom won't let us take more than this)
target_label: hostalias
- source_labels: [ host ]
regex: ^hcp-kubernetes.*.svc.cluster.local:443$
target_label: hostalias
replacement: kube-apiserver
# Replace the host with hostalias
- source_labels: [ hostalias, host ]
regex: ^(.+);(.+)$
action: replace
target_label: host
- source_labels: [ __name__ ]
action: drop
regex: (go_.*|process_(cpu|max|resident|virtual|open)_.*)
regex: (go_.*|process_(cpu|max|resident|virtual|open)_.*)
- action: labeldrop
regex: hostalias
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ scrape_configs:
target_label: instance
action: replace
metric_relabel_configs:
# Generate host alias
- source_labels: [ host ]
action: hashmod
regex: ^(.+)$
modulus: 10000000000000000000 # take last 19 digits of the MD5 hash. (Prom won't let us take more than this)
target_label: hostalias
- source_labels: [ host ]
regex: ^hcp-kubernetes.*.svc.cluster.local:443$
target_label: hostalias
replacement: kube-apiserver
# Replace the host with hostalias
- source_labels: [ hostalias, host ]
regex: ^(.+);(.+)$
action: replace
target_label: host
- source_labels: [ __name__ ]
action: drop
regex: (go_.*|process_(cpu|max|resident|virtual|open)_.*)
- action: labeldrop
regex: hostalias
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ scrape_configs:
target_label: instance
action: replace
metric_relabel_configs:
# Generate host alias
- source_labels: [ host ]
action: hashmod
regex: ^(.+)$
modulus: 10000000000000000000 # take last 19 digits of the MD5 hash. (Prom won't let us take more than this)
target_label: hostalias
- source_labels: [ host ]
regex: ^hcp-kubernetes.*.svc.cluster.local:443$
target_label: hostalias
replacement: kube-apiserver
# Replace the host with hostalias
- source_labels: [ hostalias, host ]
regex: ^(.+);(.+)$
action: replace
target_label: host
- source_labels: [ __name__ ]
action: drop
regex: (go_.*|process_(cpu|max|resident|virtual|open)_.*)
- action: labeldrop
regex: hostalias
7 changes: 3 additions & 4 deletions otelcollector/shared/file_utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"log"
"os"
"os/exec"
Expand All @@ -24,15 +23,15 @@ func printMdsdVersion() {
}

func readVersionFile(filePath string) (string, error) {
content, err := ioutil.ReadFile(filePath)
content, err := os.ReadFile(filePath)
if err != nil {
return "", err
}
return string(content), nil
}

func fmtVar(name, value string) {
fmt.Printf("%s=\"%s\"\n", name, value)
fmt.Printf("%s=\"%s\"\n", name, strings.TrimRight(value, "\n\r"))
}

func existsAndNotEmpty(filename string) bool {
Expand All @@ -50,7 +49,7 @@ func existsAndNotEmpty(filename string) bool {
}

func readAndTrim(filename string) (string, error) {
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return "", err
}
Expand Down

0 comments on commit ba61867

Please sign in to comment.