Skip to content

Commit 71fa676

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

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
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

cmd/yace/scraper.go

Lines changed: 6 additions & 6 deletions
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.

pkg/promutil/prometheus_test.go

Lines changed: 13 additions & 0 deletions
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)