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

ci: fix CI jobs for Alloy #67

Merged
merged 1 commit into from
Mar 25, 2024
Merged
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
4 changes: 3 additions & 1 deletion .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ steps:
trigger:
paths:
- packaging/**
- internal/tools/packaging_test/**
- Makefile
- tools/make/*.mk
ref:
- refs/heads/main
type: docker
Expand Down Expand Up @@ -399,6 +401,6 @@ kind: secret
name: updater_private_key
---
kind: signature
hmac: ba4497becf94a0f6f8dead2d99f8636683fbfba81eb869723c0a71ce4f7dcc09
hmac: 1a44f5bcd0f52805d4b7d1f11433f993832627118bbae3956fe5aa49b68d5a31

...
2 changes: 2 additions & 0 deletions .drone/pipelines/test_packages.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ local pipelines = import '../util/pipelines.jsonnet';
ref: ['refs/heads/main'],
paths: [
'packaging/**',
'internal/tools/packaging_test/**',
'Makefile',
'tools/make/*.mk',
],
},
steps: [{
Expand Down
50 changes: 25 additions & 25 deletions internal/tools/packaging_test/agent_linux_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func TestAlloyLinuxPackages(t *testing.T) {

tt := []struct {
name string
f func(*AgentEnvironment, *testing.T)
f func(*AlloyEnvironment, *testing.T)
}{
{"install package", (*AgentEnvironment).TestInstall},
{"ensure existing config doesn't get overridden", (*AgentEnvironment).TestConfigPersistence},
{"test data folder permissions", (*AgentEnvironment).TestDataFolderPermissions},
{"install package", (*AlloyEnvironment).TestInstall},
{"ensure existing config doesn't get overridden", (*AlloyEnvironment).TestConfigPersistence},
{"test data folder permissions", (*AlloyEnvironment).TestDataFolderPermissions},

// TODO: a test to verify that the systemd service works would be nice, but not
// required.
Expand All @@ -43,11 +43,11 @@ func TestAlloyLinuxPackages(t *testing.T) {

for _, tc := range tt {
t.Run(tc.name+"/rpm", func(t *testing.T) {
env := &AgentEnvironment{RPMEnvironment(t, packageName, dockerPool)}
env := &AlloyEnvironment{RPMEnvironment(t, packageName, dockerPool)}
tc.f(env, t)
})
t.Run(tc.name+"/deb", func(t *testing.T) {
env := &AgentEnvironment{DEBEnvironment(t, packageName, dockerPool)}
env := &AlloyEnvironment{DEBEnvironment(t, packageName, dockerPool)}
tc.f(env, t)
})
}
Expand All @@ -61,7 +61,7 @@ func buildAlloyPackages(t *testing.T) {
root, err := filepath.Abs(filepath.Join(wd, "../../.."))
require.NoError(t, err)

cmd := exec.Command("make", fmt.Sprintf("dist-agent-packages-%s", runtime.GOARCH))
cmd := exec.Command("make", fmt.Sprintf("dist-alloy-packages-%s", runtime.GOARCH))
cmd.Env = append(
os.Environ(),
"VERSION=v0.0.0",
Expand All @@ -73,47 +73,47 @@ func buildAlloyPackages(t *testing.T) {
require.NoError(t, cmd.Run())
}

type AgentEnvironment struct{ Environment }
type AlloyEnvironment struct{ Environment }

func (env *AgentEnvironment) TestInstall(t *testing.T) {
func (env *AlloyEnvironment) TestInstall(t *testing.T) {
res := env.Install()
require.Equal(t, 0, res.ExitCode, "installing failed")

res = env.ExecScript(`[ -f /usr/bin/grafana-agent ]`)
require.Equal(t, 0, res.ExitCode, "expected grafana-agent to be installed")
res = env.ExecScript(`[ -f /etc/grafana-agent.river ]`)
require.Equal(t, 0, res.ExitCode, "expected grafana agent configuration file to exist")
res = env.ExecScript(`[ -f /usr/bin/alloy]`)
require.Equal(t, 0, res.ExitCode, "expected Alloy to be installed")
res = env.ExecScript(`[ -f /etc/alloy.river ]`)
require.Equal(t, 0, res.ExitCode, "expected Alloy configuration file to exist")

res = env.Uninstall()
require.Equal(t, 0, res.ExitCode, "uninstalling failed")

res = env.ExecScript(`[ -f /usr/bin/grafana-agent ]`)
require.Equal(t, 1, res.ExitCode, "expected grafana-agent to be uninstalled")
res = env.ExecScript(`[ -f /usr/bin/alloy ]`)
require.Equal(t, 1, res.ExitCode, "expected Alloy to be uninstalled")
// NOTE(rfratto): we don't check for what happens to the config file here,
// since the behavior is inconsistent: rpm uninstalls it, but deb doesn't.
}

func (env *AgentEnvironment) TestConfigPersistence(t *testing.T) {
res := env.ExecScript(`echo -n "keepalive" > /etc/grafana-agent.river`)
func (env *AlloyEnvironment) TestConfigPersistence(t *testing.T) {
res := env.ExecScript(`echo -n "keepalive" > /etc/alloy.river`)
require.Equal(t, 0, res.ExitCode, "failed to write config file")

res = env.Install()
require.Equal(t, 0, res.ExitCode, "installation failed")

res = env.ExecScript(`cat /etc/grafana-agent.river`)
res = env.ExecScript(`cat /etc/alloy.river`)
require.Equal(t, "keepalive", res.Stdout, "Expected existing file to not be overridden")
}

func (env *AgentEnvironment) TestDataFolderPermissions(t *testing.T) {
// Installing should create /var/lib/grafana-agent, assign it to the
// grafana-agent user and group, and set its permissions to 0770.
func (env *AlloyEnvironment) TestDataFolderPermissions(t *testing.T) {
// Installing should create /var/lib/alloy, assign it to the
// alloy user and group, and set its permissions to 0770.
res := env.Install()
require.Equal(t, 0, res.ExitCode, "installation failed")

res = env.ExecScript(`[ -d /var/lib/grafana-agent ]`)
require.Equal(t, 0, res.ExitCode, "Expected /var/lib/grafana-agent to have been created during install")
res = env.ExecScript(`[ -d /var/lib/alloy ]`)
require.Equal(t, 0, res.ExitCode, "Expected /var/lib/alloy to have been created during install")

res = env.ExecScript(`stat -c '%a:%U:%G' /var/lib/grafana-agent`)
require.Equal(t, "770:grafana-agent:grafana-agent\n", res.Stdout, "wrong permissions for data folder")
res = env.ExecScript(`stat -c '%a:%U:%G' /var/lib/alloy`)
require.Equal(t, "770:alloy:alloy\n", res.Stdout, "wrong permissions for data folder")
require.Equal(t, 0, res.ExitCode, "stat'ing data folder failed")
}
5 changes: 4 additions & 1 deletion tools/ci/docker-containers-windows
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ else
VERSION=$(./tools/image-tag)
fi

VERSION_TAG=$VERSION-windows
# The VERSION_TAG is the version to use for the Docker tag. It is sanitized to
# force it to be a valid tag name; ./tools/image-tag can emit characters that
# are valid for semver but invalid for Docker tags, such as +.
VERSION_TAG=${VERSION//+/-}-windows

# We also need to know which "branch tag" to update. Branch tags are used as a
# secondary tag for Docker containers. The branch tag is "latest" when being
Expand Down
Loading