-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
620be2b
commit 6e9c6c1
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Provenance-includes-location: https://github.com/prometheus/prometheus/blob/main/promql/engine.go | ||
// Provenance-includes-location: https://github.com/prometheus/prometheus/blob/main/promql/functions.go | ||
// Provenance-includes-license: Apache-2.0 | ||
// Provenance-includes-copyright: The Prometheus Authors | ||
|
||
package functions | ||
|
||
import ( | ||
"github.com/prometheus/prometheus/promql" | ||
|
||
"github.com/grafana/mimir/pkg/streamingpromql/limiting" | ||
"github.com/grafana/mimir/pkg/streamingpromql/types" | ||
) | ||
|
||
var Timestamp = FunctionOverInstantVectorDefinition{ | ||
SeriesMetadataFunction: DropSeriesName, | ||
SeriesDataFunc: timestamp, | ||
} | ||
|
||
func timestamp(data types.InstantVectorSeriesData, _ []types.ScalarData, _ types.QueryTimeRange, memoryConsumptionTracker *limiting.MemoryConsumptionTracker) (types.InstantVectorSeriesData, error) { | ||
output := types.InstantVectorSeriesData{} | ||
|
||
defer types.HPointSlicePool.Put(data.Histograms, memoryConsumptionTracker) | ||
|
||
if len(data.Histograms) > 0 { | ||
defer types.FPointSlicePool.Put(data.Floats, memoryConsumptionTracker) | ||
|
||
var err error | ||
output.Floats, err = types.FPointSlicePool.Get(len(data.Floats)+len(data.Histograms), memoryConsumptionTracker) | ||
|
||
if err != nil { | ||
return types.InstantVectorSeriesData{}, err | ||
} | ||
} else { | ||
// Only have floats, so it's safe to reuse the input float slice. | ||
output.Floats = data.Floats[:0] | ||
} | ||
|
||
it := types.InstantVectorSeriesDataIterator{} | ||
it.Reset(data) | ||
|
||
t, _, _, ok := it.Next() | ||
|
||
for ok { | ||
output.Floats = append(output.Floats, promql.FPoint{T: t, F: float64(t) / 1000}) | ||
t, _, _, ok = it.Next() | ||
} | ||
|
||
return output, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters