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

MQE time related functions #10486

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open

MQE time related functions #10486

wants to merge 26 commits into from

Conversation

lamida
Copy link
Contributor

@lamida lamida commented Jan 20, 2025

What this PR does

Which issue(s) this PR fixes or relates to

Fixes #

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

lamida added 10 commits January 22, 2025 21:19
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
@lamida lamida force-pushed the lamida/mqe-time-functions branch from 2cf7ef4 to 5ebc1ff Compare January 22, 2025 13:19
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
@lamida lamida marked this pull request as ready for review January 22, 2025 18:03
@lamida lamida requested a review from a team as a code owner January 22, 2025 18:03
pkg/streamingpromql/functions.go Outdated Show resolved Hide resolved
pkg/streamingpromql/functions.go Outdated Show resolved Hide resolved
pkg/streamingpromql/operators/functions/times.go Outdated Show resolved Hide resolved
pkg/streamingpromql/testdata/upstream/functions.test Outdated Show resolved Hide resolved
lamida and others added 7 commits January 23, 2025 16:15
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
@lamida lamida requested a review from charleskorn January 27, 2025 17:31
pkg/streamingpromql/testdata/ours/functions.test Outdated Show resolved Hide resolved
pkg/streamingpromql/testdata/ours/functions.test Outdated Show resolved Hide resolved
pkg/streamingpromql/testdata/ours/functions.test Outdated Show resolved Hide resolved
@@ -61,6 +61,37 @@ func SingleInputVectorFunctionOperatorFactory(name string, f functions.FunctionO
}
}

func TimeFunctionOperatorFactory(name string, f functions.FunctionOverInstantVectorDefinition) InstantVectorFunctionOperatorFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is only used by TimeTransformationFunctionOperatorFactory, I would move this inside that function - I don't think the separation is useful, and they're always used together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be inlined in 16843e7

Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
@lamida lamida requested a review from charleskorn January 28, 2025 10:41
Copy link
Contributor

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo nits

samples = samples[:s.TimeRange.StepCount]

for step := 0; step < s.TimeRange.StepCount; step++ {
t := s.TimeRange.StartT + int64(step)*s.TimeRange.IntervalMilliseconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] This could be simplified to:

Suggested change
t := s.TimeRange.StartT + int64(step)*s.TimeRange.IntervalMilliseconds
t := s.TimeRange.IndexTime(step)


samples = samples[:s.TimeRange.StepCount]

for step := 0; step < s.TimeRange.StepCount; step++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] This could be simplified to:

Suggested change
for step := 0; step < s.TimeRange.StepCount; step++ {
for step := range s.TimeRange.StepCount {

Comment on lines +86 to +104
if len(args) > 1 {
// Should be caught by the PromQL parser, but we check here for safety.
return nil, fmt.Errorf("expected 0 or 1 argument for %s, got %v", name, len(args))
}

var inner types.InstantVectorOperator
if len(args) > 0 {
var ok bool
// time based function expect instant vector argument
inner, ok = args[0].(types.InstantVectorOperator)
if !ok {
// Should be caught by the PromQL parser, but we check here for safety.
return nil, fmt.Errorf("expected an instant vector argument for %s, got %T", name, args[0])
}

} else {
// if the argument is not provided, it will default to vector(time())
inner = scalars.NewScalarToInstantVector(operators.NewTime(timeRange, memoryConsumptionTracker, expressionPosition), expressionPosition)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] This could be simplified to a structure like:

if len(args) == 0 {
	...
} else if len(args) == 1 {
	...
} else {
	return nil, fmt.Errorf("expected 0 or 1 argument for %s, got %v", name, len(args))
}

Copy link
Contributor

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just noticed there are a bunch of test cases in pkg/streamingpromql/testdata/upstream/at_modifier.test that can now be enabled (eg. those starting around line 200) - could you please enable these?

(tools/check-for-disabled-but-supported-mqe-test-cases should find them all for you)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants