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

Update golang version used in TestOTLPMetricsGMP test #1509

Merged
merged 9 commits into from
Nov 16, 2023
24 changes: 21 additions & 3 deletions integration_test/ops_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2676,6 +2676,10 @@ func TestPrometheusMetricsWithJSONExporter(t *testing.T) {
t.Fatal(err)
}

if err := buildGoBinary(ctx, logger, vm, filesToUpload[0].remote, "/opt/go-http-server/"); err != nil {
t.Fatal(err)
}

// Run the setup script to run the http server and the JSON exporter
setupScript, err := testdataDir.ReadFile(path.Join(prometheusTestdata, "setup_json_exporter.sh"))
if err != nil {
Expand Down Expand Up @@ -3192,6 +3196,13 @@ func TestPrometheusSummaryMetrics(t *testing.T) {
testPrometheusMetrics(t, config, testChecks)
}

func buildGoBinary(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM, source, dest string) error {
installCmd := fmt.Sprintf(`
/usr/local/go/bin/go build -o %s/ %s`, dest, source)
_, err := gce.RunScriptRemotely(ctx, logger, vm, installCmd, nil, nil)
return err
}

// testPrometheusMetrics tests different Prometheus metric types using static
// testing files. The files will contain metrics in the right format and hosted
// by a simple HTTP server so that the agent can scrape the metrics
Expand Down Expand Up @@ -3227,10 +3238,17 @@ func testPrometheusMetrics(t *testing.T, opsAgentConfig string, testChecks []moc
t.Fatal(err)
}

// 2. Setup the golang and start the go http server
// 2. Setup the golang
if err := installGolang(ctx, logger, vm); err != nil {
t.Fatal(err)
}

// 3. Build the http server
if err := buildGoBinary(ctx, logger, vm, serviceFiles[0].remote, remoteWorkDir); err != nil {
LujieDuan marked this conversation as resolved.
Show resolved Hide resolved
t.Fatal(err)
}

// 4. Start the go http server
setupScript := `sudo systemctl daemon-reload
sudo systemctl enable http-server-for-prometheus-test
sudo systemctl restart http-server-for-prometheus-test`
Expand All @@ -3239,7 +3257,7 @@ func testPrometheusMetrics(t *testing.T, opsAgentConfig string, testChecks []moc
t.Fatalf("failed to start the http server in VM via systemctl with err: %v, stderr: %s", err, setupOut.Stderr)
}
// Wait until the http server is ready
time.Sleep(5 * time.Second)
time.Sleep(20 * time.Second)
liveCheckOut, liveCheckErr := gce.RunRemotely(ctx, logger.ToMainLog(), vm, "", `curl "http://localhost:8000/data"`)
if liveCheckErr != nil || strings.Contains(liveCheckOut.Stderr, "Connection refused") {
t.Fatalf("Http server failed to start with stdout %s and stderr %s", liveCheckOut.Stdout, liveCheckOut.Stderr)
Expand Down Expand Up @@ -3884,7 +3902,7 @@ func unmarshalResource(in string) (*resourcedetector.GCEResource, error) {
// the PATH before calling `go` as goPath
func installGolang(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM) error {
// TODO: use runtime.Version() to extract the go version
goVersion := "1.19"
goVersion := "1.20"
goArch := "amd64"
if gce.IsARM(vm.Platform) {
goArch = "arm64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

[Unit]
Description=Http Server for Prometheus Test
Requires=network.target
After=network.target
Requires=network.target
After=network.target

[Service]
Type=exec
Expand Down
Loading