Skip to content
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

Relabel host #751

Merged
merged 38 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pipelines/azure-pipeline-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ trigger:
include:
- main
- ccp_shell_removal_branch
- ccp_shell_removal_branch_prod

pr:
autoCancel: true
Expand Down Expand Up @@ -316,7 +317,7 @@ jobs:

# Necessary due to necessary due to https://stackoverflow.com/questions/60080264/docker-cannot-build-multi-platform-images-with-docker-buildx
sudo apt-get update && sudo apt-get -y install qemu binfmt-support qemu-user-static
docker system prune --volumes -y
docker system prune --all -f
docker login containerinsightsprod.azurecr.io -u $(ACR_USERNAME) -p $(ACR_PASSWORD)
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

Expand Down
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: (.+)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this filter doesn't really work as expected and it generates a hash for all metrics, the column is dropped at the end anyway so this behaviour is not visible. The replace logic has to check both [hostalias, host] as hashed alias will always have a value but host will be empty for metrics without this label.

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 @@ -42,6 +42,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 @@ -35,6 +35,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 @@ -43,6 +43,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:
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
69 changes: 34 additions & 35 deletions otelcollector/prometheuscollector/file_utilities.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package main

import (
"fmt"
"os"
"os/exec"
"io/ioutil"
"strings"
"log"
"io"
"bufio"
"bufio"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
)


func printMdsdVersion() {
cmd := exec.Command("mdsd", "--version")
cmd.Stderr = os.Stderr
Expand All @@ -32,41 +31,41 @@ func readVersionFile(filePath string) (string, error) {
}

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 {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
if err != nil {
// Handle the error, e.g., log it or return false
return false
}
if info.Size() == 0 {
return false
}
return true
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
if err != nil {
// Handle the error, e.g., log it or return false
return false
}
if info.Size() == 0 {
return false
}
return true
}

func readAndTrim(filename string) (string, error) {
content, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
}
trimmedContent := strings.TrimSpace(string(content))
return trimmedContent, nil
content, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
}
trimmedContent := strings.TrimSpace(string(content))
return trimmedContent, nil
}

func exists(path string) bool {
_, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
_, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}

func copyFile(sourcePath, destinationPath string) error {
Expand Down