Skip to content

Commit

Permalink
ci: keyperf collector does not exist in Harvest version 22.11 (#3248)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrinds authored Nov 4, 2024
1 parent 08b11e4 commit 3008134
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion integration/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def void stopAndRemoveDockers() {
sh '''
for container_id in $(docker ps -a -q);do docker stop $container_id;done
for container_id in $(docker ps -a -q);do docker rm $container_id;done
docker system prune --all --force --volumes
docker system prune --force --volumes
volumes=$(docker volume ls -qf dangling=true)
if [ "$volumes" ]; then
docker volume rm $volumes
Expand Down
15 changes: 10 additions & 5 deletions integration/test/installer/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,26 @@ func (g *Grafana) Install() bool {
g.image = "grafana/grafana:8.1.8"
slog.Info("Grafana image : " + g.image)
imageName := "grafana"
_ = docker.StopContainers(imageName)
cmd := exec.Command("docker", "run", "-d", "-e", "GF_LOG_LEVEL=debug", "-p", utils.GrafanaPort+":"+utils.GrafanaPort, g.image) //nolint:gosec
err := docker.StopContainers(imageName)
if err != nil {
slog.Warn("Error while stopping Grafana container", slog.Any("err", err))
}
cmd := exec.Command("docker", "run", "-d", "--name", "grafana", "-e", "GF_LOG_LEVEL=debug", "-p", utils.GrafanaPort+":"+utils.GrafanaPort, g.image) //nolint:gosec
cmd.Stdout = os.Stdout
err := cmd.Start()
cmd.Stderr = os.Stderr
err = cmd.Start()
utils.PanicIfNotNil(err)
waitCount := 0
maxWaitCount := 15
maxWaitCount := 3
for waitCount < maxWaitCount {
waitCount++
time.Sleep(1 * time.Minute)
if utils.IsURLReachable("http://localhost:" + utils.GrafanaPort) {
return true
}
slog.Info("Grafana is not yet reachable.", slog.Int("waitCount", waitCount), slog.Int("maxWaitCount", maxWaitCount))
}
slog.Info("Reached maximum timeout. Grafana is failed to start", slog.Int("maxWaitCount", maxWaitCount))
slog.Info("Reached maximum wait count. Grafana failed to start")
return false
}

Expand Down
8 changes: 7 additions & 1 deletion integration/test/installer/harvest.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ func (h *Harvest) Stop() {
fmt.Println(status)
}

func (h *Harvest) AllRunning() bool {
func (h *Harvest) AllRunning(ignoring ...string) bool {
pollerArray := h.GetPollerInfo()
outer:
for _, poller := range pollerArray {
if poller.Status != "running" {
for _, ignore := range ignoring {
if strings.Contains(poller.Poller, ignore) {
continue outer
}
}
return false
}
}
Expand Down
4 changes: 2 additions & 2 deletions integration/test/installer/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (r *RPM) Install() bool {
return false
} // use file directly from the repo
harvestObj.Start()
status := harvestObj.AllRunning()
status := harvestObj.AllRunning("keyperf")
asupExecPath := HarvestHome + "/autosupport/asup"
isValidAsup := harvestObj.IsValidAsup(asupExecPath)
return status && isValidAsup
Expand All @@ -51,7 +51,7 @@ func (r *RPM) Upgrade() bool {
rpmFileName := "harvest.rpm"
utils.RemoveSafely(rpmFileName)
harvestObj := new(Harvest)
if !harvestObj.AllRunning() {
if !harvestObj.AllRunning("keyperf") {
utils.PanicIfNotNil(errors.New("pollers are not in a running state before upgrade"))
}
versionCmd := []string{"-qa", "harvest"}
Expand Down
22 changes: 11 additions & 11 deletions integration/test/rpm_installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"github.com/Netapp/harvest-automation/test/installer"
"github.com/Netapp/harvest-automation/test/utils"
"log"
"log/slog"
"os"
"testing"
)
Expand All @@ -16,7 +16,7 @@ func TestRHELInstall(t *testing.T) {
}
installObject, err := installer.GetInstaller(installer.GRAFANA, "grafana/grafana")
if err != nil {
log.Println("Unable to initialize installer object for " + installer.GRAFANA)
slog.Error("Unable to initialize installer object", slog.String("object", installer.GRAFANA))
panic(err)
}
if !installObject.Install() {
Expand All @@ -27,24 +27,24 @@ func TestRHELInstall(t *testing.T) {

installObject, err2 := installer.GetInstaller(installer.RHEL, path)
if err2 != nil {
log.Println("Unable to initialize installer object")
slog.Error("Unable to initialize installer object", slog.String("object", installer.RHEL))
panic(err2)
}
if installObject.Install() {
log.Println("Installation is successful..")
slog.Info("Installation is successful..")
} else {
log.Println("Setup completed")
panic("installation is failed.")
slog.Error("Installation failed")
panic("installation failed.")
}
harvestObj := new(installer.Harvest)
if harvestObj.AllRunning() {
log.Println("All pollers are running")
if harvestObj.AllRunning("keyperf") {
slog.Info("All pollers but keyperf are running")
} else {
t.Errorf("One or more pollers are not running.")
}
installObject, err = installer.GetInstaller(installer.PROMETHEUS, "prom/prometheus")
if err != nil {
log.Println("Unable to initialize installer object for " + installer.PROMETHEUS)
slog.Error("Unable to initialize installer object", slog.String("object", installer.PROMETHEUS))
panic(err)
}
if !installObject.Install() {
Expand All @@ -58,11 +58,11 @@ func TestRHELStop(t *testing.T) {
var path = os.Getenv("BUILD_PATH")
installObject, err2 := installer.GetInstaller(installer.RHEL, path)
if err2 != nil {
log.Println("Unable to initialize installer object")
slog.Info("Unable to initialize installer object")
panic(err2)
}
if installObject.Stop() {
log.Println("Stop is successful..")
slog.Info("Stop is successful..")
} else {
panic("Stop is failed.")
}
Expand Down
10 changes: 4 additions & 6 deletions integration/test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package utils

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"github.com/carlmjohnson/requests"
"github.com/netapp/harvest/v2/cmd/tools/grafana"
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/slogx"
Expand Down Expand Up @@ -179,12 +181,8 @@ func WaitForGrafana() bool {
}

func IsURLReachable(url string) bool {
response, err := http.Get(url) //nolint:gosec
if err != nil {
return false
}
defer response.Body.Close()
return response.StatusCode == http.StatusOK
err := requests.URL(url).Fetch(context.Background())
return err == nil
}

func AddPrometheusToGrafana() {
Expand Down
2 changes: 1 addition & 1 deletion jenkins/artifacts/jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def void stopAndRemoveDockers() {
rm -rf /opt/home/nightly/
mkdir -p /opt/home/nightly/
for container_id in $(docker ps -a -q);do docker stop $container_id;done
docker system prune --all --force --volumes
docker system prune --force --volumes
volumes=$(docker volume ls -qf dangling=true)
if [ "$volumes" ]; then
docker volume rm $volumes
Expand Down

0 comments on commit 3008134

Please sign in to comment.