-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
182 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Integration Tests Windows | ||
on: | ||
# Run tests on main just so the module and build cache can be saved and used | ||
# in PRs. This speeds up the time it takes to test PRs dramatically. | ||
# (More information on https://docs.github.com/en/[email protected]/actions/using-workflows/caching-dependencies-to-speed-up-workflows) | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
jobs: | ||
run_tests: | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.22" | ||
- name: Run tests | ||
run: make integration-test |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
version: "3" | ||
services: | ||
|
||
mimir: | ||
|
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
23 changes: 23 additions & 0 deletions
23
internal/cmd/integration-tests/tests-windows/windows/config.alloy
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,23 @@ | ||
prometheus.exporter.windows "default" { } | ||
|
||
prometheus.scrape "default" { | ||
targets = prometheus.exporter.windows.default.targets | ||
forward_to = [prometheus.remote_write.default.receiver] | ||
scrape_interval = "1s" | ||
scrape_timeout = "500ms" | ||
} | ||
|
||
prometheus.remote_write "default" { | ||
endpoint { | ||
url = "http://localhost:9090/receive" | ||
metadata_config { | ||
send_interval = "1s" | ||
} | ||
queue_config { | ||
max_samples_per_send = 100 | ||
} | ||
} | ||
external_labels = { | ||
test_name = "win_metrics", | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
internal/cmd/integration-tests/tests-windows/windows/windows_metrics_test.go
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,110 @@ | ||
//go:build windows | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/golang/snappy" | ||
"github.com/prometheus/prometheus/prompb" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// List of expected Windows metrics | ||
var winMetrics = []string{ | ||
"windows_cpu_time_total", // cpu | ||
"windows_cs_logical_processors", // cs | ||
"windows_logical_disk_info", // logical_disk | ||
"windows_net_bytes_received_total", // net | ||
"windows_os_info", // os | ||
"windows_service_info", // service | ||
"windows_system_system_up_time", // system | ||
} | ||
|
||
// TestWindowsMetrics sets up a server to receive remote write requests | ||
// and checks if required metrics appear within a one minute timeout | ||
func TestWindowsMetrics(t *testing.T) { | ||
foundMetrics := make(map[string]bool) | ||
for _, metric := range winMetrics { | ||
foundMetrics[metric] = false | ||
} | ||
|
||
done := make(chan bool) | ||
srv := &http.Server{Addr: ":9090"} | ||
http.HandleFunc("/receive", func(w http.ResponseWriter, r *http.Request) { | ||
ts, _ := handlePost(t, w, r) | ||
|
||
for _, timeseries := range ts { | ||
var metricName string | ||
for _, label := range timeseries.Labels { | ||
if label.Name == "__name__" { | ||
metricName = label.Value | ||
break | ||
} | ||
} | ||
for _, requiredMetric := range winMetrics { | ||
if requiredMetric == metricName && !foundMetrics[requiredMetric] { | ||
foundMetrics[requiredMetric] = true | ||
} | ||
} | ||
} | ||
|
||
allFound := true | ||
for _, found := range foundMetrics { | ||
if !found { | ||
allFound = false | ||
break | ||
} | ||
} | ||
|
||
if allFound { | ||
done <- true | ||
} | ||
}) | ||
|
||
go func() { | ||
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { | ||
panic(fmt.Errorf("could not start server: %v", err)) | ||
} | ||
}() | ||
defer srv.Shutdown(context.Background()) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) | ||
defer cancel() | ||
|
||
select { | ||
case <-ctx.Done(): | ||
missingMetrics := []string{} | ||
for metric, found := range foundMetrics { | ||
if !found { | ||
missingMetrics = append(missingMetrics, metric) | ||
} | ||
} | ||
if len(missingMetrics) > 0 { | ||
t.Errorf("Timeout reached. Missing metrics: %v", missingMetrics) | ||
} else { | ||
t.Log("All required metrics received.") | ||
} | ||
case <-done: | ||
t.Log("All required metrics received within the timeout.") | ||
} | ||
} | ||
|
||
func handlePost(t *testing.T, _ http.ResponseWriter, r *http.Request) ([]prompb.TimeSeries, []prompb.MetricMetadata) { | ||
defer r.Body.Close() | ||
data, err := io.ReadAll(r.Body) | ||
require.NoError(t, err) | ||
|
||
data, err = snappy.Decode(nil, data) | ||
require.NoError(t, err) | ||
|
||
var req prompb.WriteRequest | ||
err = req.Unmarshal(data) | ||
require.NoError(t, err) | ||
return req.GetTimeseries(), req.Metadata | ||
} |
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