Skip to content

Commit

Permalink
Relabel host (#751)
Browse files Browse the repository at this point in the history
* Relabel host value

---------

Co-authored-by: Nina Segares <[email protected]>
  • Loading branch information
sgeannina and Nina Segares authored Feb 20, 2024
1 parent 133e148 commit c1462a7
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 38 deletions.
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: (.+)
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

0 comments on commit c1462a7

Please sign in to comment.