Skip to content

Commit 1f2882c

Browse files
committed
Run tests in CI
Signed-off-by: Karsten Jeschkies <[email protected]>
1 parent 5d9a043 commit 1f2882c

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

Diff for: .github/workflows/ci.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ on:
1010
workflow_call:
1111

1212
jobs:
13+
test_go:
14+
name: Go tests
15+
runs-on: ubuntu-latest
16+
container:
17+
image: quay.io/prometheus/golang-builder:1.23-base
18+
steps:
19+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
- uses: prometheus/promci@c3c93a50d581b928af720f0134b2b2dad32a6c41 # v0.4.6
21+
- uses: ./.github/promci/actions/setup_environment
22+
- run: make test
23+
1324
build:
1425
name: Build for common architectures
1526
runs-on: ubuntu-latest
@@ -61,7 +72,7 @@ jobs:
6172
publish_master:
6273
name: Publish master branch artifacts
6374
runs-on: ubuntu-latest
64-
needs: [build_all, verify-example-configs]
75+
needs: [test_go, build_all, verify-example-configs]
6576
if: |
6677
(github.repository == 'prometheus-community/yet-another-cloudwatch-exporter')
6778
&&
@@ -81,7 +92,7 @@ jobs:
8192
publish_release:
8293
name: Publish release artifacts
8394
runs-on: ubuntu-latest
84-
needs: [build_all, verify-example-configs]
95+
needs: [test_go, build_all, verify-example-configs]
8596
if: |
8697
(github.repository == 'prometheus-community/yet-another-cloudwatch-exporter')
8798
&&

Diff for: cmd/yace/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"slices"
2323
"strings"
2424

25+
"github.com/prometheus/common/model"
2526
"github.com/prometheus/common/promslog"
2627
promslogflag "github.com/prometheus/common/promslog/flag"
2728
"github.com/prometheus/common/version"
@@ -248,6 +249,9 @@ func NewYACEApp() *cli.App {
248249
}
249250

250251
func startScraper(c *cli.Context) error {
252+
// Use legacy validation as that's the behaviour of former releases.
253+
model.NameValidationScheme = model.LegacyValidation
254+
251255
logger = newLogger(logFormat, logLevel).With("version", version.Version)
252256

253257
// log warning if the two concurrency limiting methods are configured via CLI

Diff for: cmd/yace/scraper.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/model"
2828
)
2929

30-
type scraper struct {
30+
type Scraper struct {
3131
registry atomic.Pointer[prometheus.Registry]
3232
featureFlags []string
3333
}
@@ -38,16 +38,16 @@ type cachingFactory interface {
3838
Clear()
3939
}
4040

41-
func NewScraper(featureFlags []string) *scraper { //nolint:revive
42-
s := &scraper{
41+
func NewScraper(featureFlags []string) *Scraper {
42+
s := &Scraper{
4343
registry: atomic.Pointer[prometheus.Registry]{},
4444
featureFlags: featureFlags,
4545
}
4646
s.registry.Store(prometheus.NewRegistry())
4747
return s
4848
}
4949

50-
func (s *scraper) makeHandler() func(http.ResponseWriter, *http.Request) {
50+
func (s *Scraper) makeHandler() func(http.ResponseWriter, *http.Request) {
5151
return func(w http.ResponseWriter, r *http.Request) {
5252
handler := promhttp.HandlerFor(s.registry.Load(), promhttp.HandlerOpts{
5353
DisableCompression: false,
@@ -56,7 +56,7 @@ func (s *scraper) makeHandler() func(http.ResponseWriter, *http.Request) {
5656
}
5757
}
5858

59-
func (s *scraper) decoupled(ctx context.Context, logger *slog.Logger, jobsCfg model.JobsConfig, cache cachingFactory) {
59+
func (s *Scraper) decoupled(ctx context.Context, logger *slog.Logger, jobsCfg model.JobsConfig, cache cachingFactory) {
6060
logger.Debug("Starting scraping async")
6161
s.scrape(ctx, logger, jobsCfg, cache)
6262

@@ -75,7 +75,7 @@ func (s *scraper) decoupled(ctx context.Context, logger *slog.Logger, jobsCfg mo
7575
}
7676
}
7777

78-
func (s *scraper) scrape(ctx context.Context, logger *slog.Logger, jobsCfg model.JobsConfig, cache cachingFactory) {
78+
func (s *Scraper) scrape(ctx context.Context, logger *slog.Logger, jobsCfg model.JobsConfig, cache cachingFactory) {
7979
if !sem.TryAcquire(1) {
8080
// This shouldn't happen under normal use, users should adjust their configuration when this occurs.
8181
// Let them know by logging a warning.

Diff for: pkg/promutil/prometheus_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/prometheus/client_golang/prometheus"
2020
dto "github.com/prometheus/client_model/go"
21+
"github.com/prometheus/common/model"
2122
"github.com/stretchr/testify/assert"
2223
"github.com/stretchr/testify/require"
2324
)
@@ -71,6 +72,12 @@ func TestSanitize(t *testing.T) {
7172
}
7273

7374
func TestPromStringTag(t *testing.T) {
75+
originalValidationScheme := model.NameValidationScheme
76+
model.NameValidationScheme = model.LegacyValidation
77+
defer func() {
78+
model.NameValidationScheme = originalValidationScheme
79+
}()
80+
7481
testCases := []struct {
7582
name string
7683
label string
@@ -134,6 +141,12 @@ func TestPromStringTag(t *testing.T) {
134141
}
135142

136143
func TestNewPrometheusCollector_CanReportMetricsAndErrors(t *testing.T) {
144+
originalValidationScheme := model.NameValidationScheme
145+
model.NameValidationScheme = model.LegacyValidation
146+
defer func() {
147+
model.NameValidationScheme = originalValidationScheme
148+
}()
149+
137150
metrics := []*PrometheusMetric{
138151
{
139152
Name: "this*is*not*valid",

0 commit comments

Comments
 (0)