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

e2e: prom metric check func #2051

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions test/engine/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func ScenarioInitializer(ctx *godog.ScenarioContext) {

// metric
ctx.Then(`^there is more than \{(\d+)\} metrics in \{(\d+)\} seconds$`, verify.MetricCount)
ctx.Then(`^there is exactly \{(\d+)\} metrics in \{(\d+)\} interval seconds$`, verify.MetricCount)

// other
ctx.Then(`wait \{(\d+)\} seconds`, func(ctx context.Context, t int) context.Context {
Expand Down
11 changes: 11 additions & 0 deletions test/engine/verify/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ func LogCountLess(ctx context.Context, expect int) (context.Context, error) {
}

func MetricCheck(ctx context.Context, expect int, duration int64, checker func([]*protocol.LogGroup) error) (context.Context, error) {
var startTime int32
var enableExactlyCheck bool
value := ctx.Value(config.StartTimeContextKey)
if value != nil {
startTime = value.(int32)
enableExactlyCheck = true
}
timeoutCtx, cancel := context.WithTimeout(context.TODO(), config.TestConfig.RetryTimeout)
defer cancel()
var groups []*protocol.LogGroup
Expand All @@ -126,6 +133,10 @@ func MetricCheck(ctx context.Context, expect int, duration int64, checker func([
count = 0
currTime := time.Now().Unix()
lastScrapeTime := int32(currTime - duration)
if enableExactlyCheck {
expect = int(int32(currTime)-startTime) / int(duration)
lastScrapeTime = startTime
}
groups, err = subscriber.TestSubscriber.GetData(control.GetQuery(ctx), lastScrapeTime)
if err != nil {
return err
Expand Down
Loading