forked from prometheus/node_exporter
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PMM-10274 Add tests for node_exporter
- Loading branch information
1 parent
3c771b8
commit a9da035
Showing
13 changed files
with
1,107 additions
and
1,566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
######################### | ||
### tests | ||
|
||
# measures avg scrape time and compares old vs new exporters | ||
test-performance: | ||
go test -v -run '^TestPerformance$$' -args -doRun=true | ||
|
||
extraMetrics = false | ||
multipleLabels = false | ||
dumpMetrics = false | ||
|
||
test-metrics: | ||
go test -v -run '^TestMissingMetrics$$' -args -doRun=true | ||
|
||
test-labels: | ||
go test -v -run '^TestMissingLabels$$' -args -doRun=true | ||
|
||
test-resolutions-duplicates: | ||
go test -v -run '^TestResolutionsMetricDuplicates$$' -args -doRun=true | ||
|
||
test-resolutions: | ||
go test -v -run '^TestResolutions$$' -args -doRun=true | ||
|
||
dump-metrics: | ||
go test -v -run '^TestDumpMetrics$$' -args -doRun=true -extraMetrics=$(extraMetrics) -multipleLabels=$(multipleLabels) -dumpMetrics=$(dumpMetrics) | ||
|
||
test-consistency: test-metrics test-resolutions test-resolutions-duplicates | ||
|
||
######################### | ||
### env preparation | ||
|
||
# download exporter from provided feature build's client binary url | ||
prepare-exporter: | ||
go test -v -run '^TestPrepareUpdatedExporter$\' -args -doRun=true -url=$(url) | ||
|
||
prepare-exporter-from-repo: | ||
make -C ../../../ build && cp ../../../node_exporter assets/node_exporter | ||
|
||
prepare-base-exporter: | ||
tar -xf assets/node_exporter_percona.tar.xz -C assets/ | ||
|
||
prepare-env-from-repo: prepare-exporter-from-repo prepare-base-exporter |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package percona_tests | ||
|
||
import ( | ||
"archive/tar" | ||
"compress/gzip" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// TestPrepareExporters extracts exporter from client binary's tar.gz | ||
func TestPrepareUpdatedExporter(t *testing.T) { | ||
if doRun == nil || !*doRun { | ||
t.Skip("For manual runs only through make") | ||
return | ||
} | ||
|
||
if url == nil || *url == "" { | ||
t.Error("URL not defined") | ||
return | ||
} | ||
|
||
prepareExporter(*url, updatedExporterFileName) | ||
} | ||
|
||
func extractExporter(gzipStream io.Reader, fileName string) { | ||
uncompressedStream, err := gzip.NewReader(gzipStream) | ||
if err != nil { | ||
log.Fatal("ExtractTarGz: NewReader failed") | ||
} | ||
|
||
tarReader := tar.NewReader(uncompressedStream) | ||
|
||
exporterFound := false | ||
for !exporterFound { | ||
header, err := tarReader.Next() | ||
|
||
if err == io.EOF { | ||
break | ||
} | ||
|
||
if err != nil { | ||
log.Fatalf("ExtractTarGz: Next() failed: %s", err.Error()) | ||
} | ||
|
||
switch header.Typeflag { | ||
case tar.TypeDir: | ||
continue | ||
case tar.TypeReg: | ||
if strings.HasSuffix(header.Name, "postgres_exporter") { | ||
outFile, err := os.Create(fileName) | ||
if err != nil { | ||
log.Fatalf("ExtractTarGz: Create() failed: %s", err.Error()) | ||
} | ||
defer outFile.Close() | ||
if _, err := io.Copy(outFile, tarReader); err != nil { | ||
log.Fatalf("ExtractTarGz: Copy() failed: %s", err.Error()) | ||
} | ||
|
||
exporterFound = true | ||
} | ||
default: | ||
log.Fatalf( | ||
"ExtractTarGz: uknown type: %d in %s", | ||
header.Typeflag, | ||
header.Name) | ||
} | ||
} | ||
} | ||
|
||
func prepareExporter(url, fileName string) { | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
extractExporter(resp.Body, fileName) | ||
|
||
err = exec.Command("chmod", "+x", fileName).Run() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
Oops, something went wrong.