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

ci: Harvest should lint metrics with promtool #3246

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -27,6 +27,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