Skip to content

Commit

Permalink
ci: Harvest should lint metrics with promtool (#3246)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrinds authored Nov 4, 2024
1 parent 01dcf9d commit 08ce197
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,6 @@ endif
VERSION=${VERSION} INSTALL_DOCKER=1 ./integration/test/test.sh
VERSION=${VERSION} REGRESSION=1 ./integration/test/test.sh
VERSION=${VERSION} ANALYZE_DOCKER_LOGS=1 ./integration/test/test.sh
VERSION=${VERSION} CHECK_METRICS=1 ./integration/test/test.sh


4 changes: 0 additions & 4 deletions cmd/collectors/zapi/plugins/systemnode/systemnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ func (s *SystemNode) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *
inst.SetLabel("bmc_firmware_version", serviceProcessorMap[nodeName])
}

// update node metrics with partner info
for _, metric := range data.GetMetrics() {
metric.SetLabel("ha_partner", partnerNameMap[metric.GetLabel("node")])
}
return nil, s.client.Metadata, nil
}

Expand Down
2 changes: 2 additions & 0 deletions integration/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ pipeline {
zip -r docker_logs.zip /var/log/harvest
cd $WORKSPACE/docker
ANALYZE_DOCKER_LOGS=1 bash $WORKSPACE/harvest/integration/test/test.sh
CHECK_METRICS=1 bash $WORKSPACE/harvest/integration/test/test.sh
docker ps -q | xargs docker stop | xargs docker rm --force
"""
archiveArtifacts artifacts: "docker_logs.zip", fingerprint: true
Expand Down Expand Up @@ -267,6 +268,7 @@ pipeline {
zip -r docker_fips_logs.zip /var/log/harvest
cd $WORKSPACE/docker
ANALYZE_DOCKER_LOGS=1 bash $WORKSPACE/harvest/integration/test/test.sh
CHECK_METRICS=1 bash $WORKSPACE/harvest/integration/test/test.sh
docker ps -q | xargs docker stop | xargs docker rm --force
"""
archiveArtifacts artifacts: "docker_fips_logs.zip", fingerprint: true
Expand Down
52 changes: 52 additions & 0 deletions integration/test/promtool_metrics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"errors"
"fmt"
"github.com/Netapp/harvest-automation/test/utils"
"os/exec"
"strings"
"testing"
)

func TestPrometheusMetrics(t *testing.T) {
utils.SkipIfMissing(t, utils.CheckMetrics)

ports := []int{12990, 12992, 12993, 12994}
for _, port := range ports {
checkMetrics(t, port)
}
}

func checkMetrics(t *testing.T, port int) {
cli := fmt.Sprintf(`curl -s http://localhost:%d/metrics | tee /tmp/metrics:%d.txt | promtool check metrics`, port, port)
command := exec.Command("bash", "-c", cli)
output, err := command.CombinedOutput()

if err != nil {
var ee *exec.ExitError
if !errors.As(err, &ee) {
// An exit code can't be used since we need to ignore metrics that are not valid but can't change
t.Errorf("ERR checking metrics cli=%s err=%v output=%s", cli, err, string(output))
return
}
}

if len(output) == 0 {
return
}

// Read the output, line by line, and check for errors, non-errors are ignored

lines := strings.Split(string(output), "\n")
for _, line := range lines {
line = strings.TrimSpace(line)
if line == "" {
continue
}

if strings.Contains(line, "error while linting: ") {
t.Errorf("promtool: %s", line)
}
}
}
1 change: 1 addition & 0 deletions integration/test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
GrafanaTokeKey = "grafana_api_token"

AnalyzeDockerLogs = "ANALYZE_DOCKER_LOGS"
CheckMetrics = "CHECK_METRICS"
CopyDockerLogs = "COPY_DOCKER_LOGS"
InstallDocker = "INSTALL_DOCKER"
InstallNative = "INSTALL_NATIVE"
Expand Down

0 comments on commit 08ce197

Please sign in to comment.