-
Notifications
You must be signed in to change notification settings - Fork 454
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
[query] Implemented the Graphite timeSlice
function
#2581
Changes from 22 commits
4e901d7
f42685a
f0df4ce
bef6377
8ce6dc3
30ef946
cf9288f
50b0ae9
1ebe629
ebaafce
2a0643c
53222b9
b2d895c
88260f7
73e279f
007e83e
dafe31b
0c9f44e
17c42bd
f246f82
8f60dca
ca19d91
9f0e2c7
5ebab5a
c164a5f
902accc
381dcec
a6f915c
89a9600
2d7c62a
2659565
9e558a8
5d2c66b
fbe5d13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ import ( | |
|
||
"github.com/m3db/m3/src/query/graphite/common" | ||
"github.com/m3db/m3/src/query/graphite/errors" | ||
"github.com/m3db/m3/src/query/graphite/graphite" | ||
"github.com/m3db/m3/src/query/graphite/ts" | ||
"github.com/m3db/m3/src/query/util" | ||
) | ||
|
@@ -242,6 +243,42 @@ func timeShift( | |
}, nil | ||
} | ||
|
||
|
||
func timeSlice(ctx *common.Context, inputPath singlePathSpec, start string, end string) (ts.SeriesList, error) { | ||
tzOffsetForAbsoluteTime := time.Duration(0) | ||
startTime, err := graphite.ParseTime(start, time.Now(), tzOffsetForAbsoluteTime) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of passing different i.e. declare |
||
endTime, err := graphite.ParseTime(end, time.Now(), tzOffsetForAbsoluteTime) | ||
|
||
if (err != nil) { | ||
return ts.NewSeriesList(), err | ||
} | ||
teddywahle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
input := ts.SeriesList(inputPath) | ||
output := make([]*ts.Series, input.Len()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per review on another PR, prefer to do the following instead of direct index setting: output := make([]*ts.Series, 0, input.Len())
// ...
output = append(output, renamedSlicedSeries) |
||
|
||
for i, series := range input.Values { | ||
nanoSecondsPerStep := series.MillisPerStep() * 1000000 | ||
stepDuration := time.Duration(nanoSecondsPerStep) | ||
teddywahle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
truncatedValues := ts.NewValues(ctx, series.MillisPerStep(), series.Len()) | ||
|
||
currentTime := series.StartTime() | ||
for i := 0; i < series.Len(); i++ { | ||
if ( currentTime.After(startTime) && currentTime.Before(endTime)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The graphite documentation says that start and end are inclusive for timeSlice:
Hence this should be (also removing the un-needed round brackets): equalOrAfterStart := currentTime.Equal(startTime) || currentTime.After(startTime)
beforeOrEqualEnd := currentTime.Before(endTime) || currentTime.Equal(endTime)
if equalOrAfterStart && beforeOrEqualEnd {
// ...
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch, thanks |
||
truncatedValues.SetValueAt(i, series.ValueAtTime(currentTime)) | ||
} | ||
currentTime = currentTime.Add(stepDuration) | ||
} | ||
|
||
slicedSeries := ts.NewSeries(ctx, series.Name(), series.StartTime(), truncatedValues) | ||
renamedSlicedSeries := slicedSeries.RenamedTo(fmt.Sprintf("timeSlice(%s, %s, %s)", slicedSeries.Name(), start, end)) | ||
output[i] = renamedSlicedSeries | ||
} | ||
input.Values = output | ||
return input, nil | ||
} | ||
|
||
|
||
|
||
// absolute returns the absolute value of each element in the series. | ||
func absolute(ctx *common.Context, input singlePathSpec) (ts.SeriesList, error) { | ||
return transform(ctx, input, | ||
|
@@ -1972,6 +2009,9 @@ func init() { | |
MustRegisterFunction(timeShift).WithDefaultParams(map[uint8]interface{}{ | ||
3: true, // resetEnd | ||
}) | ||
MustRegisterFunction(timeSlice).WithDefaultParams(map[uint8]interface{}{ | ||
3: "now", // endTime | ||
}) | ||
MustRegisterFunction(transformNull).WithDefaultParams(map[uint8]interface{}{ | ||
2: 0.0, // defaultValue | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can you add a description for this function, maybe something similar to the docs for the function?