Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdurham committed Dec 27, 2023
1 parent f75dfd9 commit 8780316
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions component/prometheus/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ func (arg *Arguments) SetToDefault() {
}
}

// Validate implements river.Validator.
func (arg *Arguments) Validate() error {
if arg.CacheSize <= 0 {
return fmt.Errorf("max_cache_size must be greater than 0 and is %d", arg.CacheSize)
}
return nil
}

// Exports holds values which are exported by the prometheus.relabel component.
type Exports struct {
Receiver storage.Appendable `river:"receiver,attr"`
Expand Down
14 changes: 13 additions & 1 deletion component/prometheus/relabel/relabel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,22 @@ func TestUpdateReset(t *testing.T) {
relabeller.relabel(0, lbls)
require.True(t, relabeller.cache.Len() == 1)
_ = relabeller.Update(Arguments{
CacheSize: 100000,
MetricRelabelConfigs: []*flow_relabel.Config{},
})
require.True(t, relabeller.cache.Len() == 0)
}

func TestValidator(t *testing.T) {
args := Arguments{CacheSize: 0}
err := args.Validate()
require.Error(t, err)

args.CacheSize = 1
err = args.Validate()
require.NoError(t, err)
}

func TestNil(t *testing.T) {
ls := labelstore.New(nil, prom.DefaultRegisterer)
fanout := prometheus.NewInterceptor(nil, ls, prometheus.WithAppendHook(func(ref storage.SeriesRef, _ labels.Labels, _ int64, _ float64, _ storage.Appender) (storage.SeriesRef, error) {
Expand All @@ -72,6 +83,7 @@ func TestNil(t *testing.T) {
Action: "drop",
},
},
CacheSize: 100000,
})
require.NotNil(t, relabeller)
require.NoError(t, err)
Expand Down Expand Up @@ -129,7 +141,6 @@ func BenchmarkCache(b *testing.B) {

lbls := labels.FromStrings("__address__", "localhost")
app := entry.Appender(context.Background())

for i := 0; i < b.N; i++ {
app.Append(0, lbls, time.Now().UnixMilli(), 0)
}
Expand Down Expand Up @@ -161,6 +172,7 @@ func generateRelabel(t *testing.T) *Component {
Action: "replace",
},
},
CacheSize: 100_000,
})
require.NotNil(t, relabeller)
require.NoError(t, err)
Expand Down

0 comments on commit 8780316

Please sign in to comment.