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

Add windows integration test #1912

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
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
21 changes: 21 additions & 0 deletions .github/workflows/integration-tests-win.yml
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/enterprise-server@3.6/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
12 changes: 12 additions & 0 deletions internal/cmd/integration-tests/docker-compose.windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:

mimir:
image: grafana/mimir:2.10.4
platform: linux/amd64
volumes:
- ./configs/mimir:/etc/mimir-config
entrypoint:
- /bin/mimir
- -config.file=/etc/mimir-config/mimir.yaml
ports:
- "9009:9009"
1 change: 0 additions & 1 deletion internal/cmd/integration-tests/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3"
services:

mimir:
Expand Down
28 changes: 21 additions & 7 deletions internal/cmd/integration-tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -32,24 +33,37 @@ func runIntegrationTests(cmd *cobra.Command, args []string) {
defer reportResults()
defer cleanUpEnvironment()

testFolder := "./tests/"
alloyBinaryPath := "../../../../../build/alloy"
alloyBinary := "build/alloy"
dockerComposeFile := "docker-compose.yaml"

if runtime.GOOS == "windows" {
testFolder = "./tests-windows/"
alloyBinaryPath = "..\\..\\..\\..\\..\\build\\alloy.exe"
alloyBinary = "build/alloy.exe"
dockerComposeFile = "docker-compose.windows.yaml"
}

if !skipBuild {
buildAlloy()
buildAlloy(alloyBinary)
}
setupEnvironment()

setupEnvironment(dockerComposeFile)

if specificTest != "" {
fmt.Println("Running", specificTest)
if !filepath.IsAbs(specificTest) && !strings.HasPrefix(specificTest, "./tests/") {
specificTest = "./tests/" + specificTest
if !filepath.IsAbs(specificTest) && !strings.HasPrefix(specificTest, testFolder) {
specificTest = testFolder + specificTest
}
logChan = make(chan TestLog, 1)
runSingleTest(specificTest, 12345)
runSingleTest(alloyBinaryPath, specificTest, 12345)
} else {
testDirs, err := filepath.Glob("./tests/*")
testDirs, err := filepath.Glob(testFolder + "*")
if err != nil {
panic(err)
}
logChan = make(chan TestLog, len(testDirs))
runAllTests()
runAllTests(alloyBinaryPath, testFolder)
}
}
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:9009/api/v1/push"
metadata_config {
send_interval = "1s"
}
queue_config {
max_samples_per_send = 100
}
}
external_labels = {
test_name = "win_metrics",
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build windows

package main

import (
"testing"

"github.com/grafana/alloy/internal/cmd/integration-tests/common"
)

func TestWindowsMetrics(t *testing.T) {
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
}
common.MimirMetricsTest(t, winMetrics, []string{}, "win_metrics")
}
23 changes: 11 additions & 12 deletions internal/cmd/integration-tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import (
"time"
)

const (
alloyBinaryPath = "../../../../../build/alloy"
)

type TestLog struct {
TestDir string
AlloyLog string
Expand All @@ -34,17 +30,17 @@ func executeCommand(command string, args []string, taskDescription string) {
}
}

func buildAlloy() {
executeCommand("make", []string{"-C", "../../..", "alloy"}, "Building Alloy")
func buildAlloy(alloyBinary string) {
executeCommand("make", []string{"-C", "../../..", "alloy", fmt.Sprintf("ALLOY_BINARY=%s", alloyBinary)}, "Building Alloy")
}

func setupEnvironment() {
executeCommand("docker", []string{"compose", "up", "-d"}, "Setting up environment with Docker Compose")
func setupEnvironment(dockerComposeFile string) {
executeCommand("docker", []string{"compose", "-f", dockerComposeFile, "up", "-d"}, "Setting up environment with Docker Compose")
fmt.Println("Sleep for 45 seconds to ensure that the env has time to initialize...")
time.Sleep(45 * time.Second)
}

func runSingleTest(testDir string, port int) {
func runSingleTest(alloyBinaryPath string, testDir string, port int) {
info, err := os.Stat(testDir)
if err != nil {
panic(err)
Expand Down Expand Up @@ -88,14 +84,17 @@ func runSingleTest(testDir string, port int) {
}
}

// sleep for a few seconds before deleting the files to make sure that they are not use anymore
time.Sleep(5 * time.Second)

err = os.RemoveAll(filepath.Join(testDir, "data-alloy"))
if err != nil {
panic(err)
}
}

func runAllTests() {
testDirs, err := filepath.Glob("./tests/*")
func runAllTests(alloyBinaryPath string, testFolder string) {
testDirs, err := filepath.Glob(testFolder + "*")
if err != nil {
panic(err)
}
Expand All @@ -106,7 +105,7 @@ func runAllTests() {
wg.Add(1)
go func(td string, offset int) {
defer wg.Done()
runSingleTest(td, port+offset)
runSingleTest(alloyBinaryPath, td, port+offset)
}(testDir, i)
}
wg.Wait()
Expand Down
Loading