query_range.go
query_range.go - Overview
-
Overview This file provides utility functions for adjusting time ranges, calculating step intervals, normalizing label names, and handling time series data retrieved from a cache. It includes functions for aligning time ranges, determining minimum step intervals, calculating the Least Common Multiple (LCM), normalizing Prometheus label names, and extracting/filtering series data from cached data structures.
-
Detailed Documentation
AdjustedMetricTimeRange
- Purpose: Adjusts the start and end times of a metric query based on the step interval and query type (rate, running_diff).
- Parameters:
start
(int64): The original start time in milliseconds.end
(int64): The original end time in milliseconds.step
(int64): The step interval in seconds.mq
(v3.BuilderQuery): The query object containing information about aggregation operators and functions.
- Returns:
int64
: The adjusted start time in milliseconds.int64
: The adjusted end time in milliseconds.
PastDayRoundOff
- Purpose: Calculates the Unix milliseconds timestamp for the beginning of the current day.
- Returns:
int64
: The timestamp in Unix milliseconds.
MinAllowedStepInterval
- Purpose: Calculates the minimum allowed step interval in seconds based on the time range and the maximum allowed data points.
- Parameters:
start
(int64): The start time in milliseconds.end
(int64): The end time in milliseconds.
- Returns:
int64
: The minimum allowed step interval in seconds.
GCD
- Purpose: Calculates the greatest common divisor (GCD) of two integers.
- Parameters:
a
(int64): The first integer.b
(int64): The second integer.
- Returns:
int64
: The greatest common divisor ofa
andb
.
LCM
- Purpose: Calculates the least common multiple (LCM) of two integers.
- Parameters:
a
(int64): The first integer.b
(int64): The second integer.
- Returns:
int64
: The least common multiple ofa
andb
.
LCMList
- Purpose: Computes the LCM of a list of int64 numbers.
- Parameters:
nums
([]int64): A slice of integers.
- Returns:
int64
: The least common multiple of the numbers in the list. Returns 1 if the list is empty.
NormalizeLabelName
- Purpose: Normalizes a label name by replacing invalid characters with underscores and ensuring it starts with a letter or underscore.
- Parameters:
name
(string): The label name to normalize.
- Returns:
string
: The normalized label name.
GetSeriesFromCachedData
- Purpose: Extracts time series data from cached data within a specified time range.
- Parameters:
data
([]querycache.CachedSeriesData): A slice of cached series data.start
(int64): The start time in milliseconds.end
(int64): The end time in milliseconds.
- Returns:
[]*v3.Series
: A slice of time series, with points filtered by the specified time range.
GetSeriesFromCachedDataV2
- Purpose: Extracts time series data from cached data within a specified time range, similar to
GetSeriesFromCachedData
but with a different start time condition. - Parameters:
data
([]querycache.CachedSeriesData): A slice of cached series data.start
(int64): The start time in milliseconds.end
(int64): The end time in milliseconds.step
(int64): The step interval in seconds.
- Returns:
[]*v3.Series
: A slice of time series, with points filtered by the specified time range, usingstart-(start%(step*1000))
as lower bound.
FilterSeriesPoints
- Purpose: Filters series points for storing in cache based on
missStart
,missEnd
, andstepInterval
. - Parameters:
seriesList
([]*v3.Series): A slice of time series to filter.missStart
(int64): The start time of the missing data in milliseconds.missEnd
(int64): The end time of the missing data in milliseconds.stepInterval
(int64): The step interval in seconds.
- Returns:
[]*v3.Series
: A slice of filtered time series.int64
: Adjusted start time in milliseconds.int64
: Adjusted end time in milliseconds.
-
Code Examples N/A
-
Clarity and Accuracy The documentation provides accurate descriptions based on the code.
-
Markdown & MDX Perfection The markdown is correctly formatted.
-
Edge Cases To Avoid Breaking MDX No issues found.
-
Getting Started Relevance Include in Getting Started: NO