table.go
table.go - Overview
-
Overview This file defines constants for database and table names used in ClickHouse for storing Prometheus metrics, along with a function to determine the appropriate table name based on the time range of a query.
-
Detailed Documentation
Constants
-
databaseName
:- Purpose: Defines the name of the ClickHouse database where metrics are stored.
- Value:
"signoz_metrics"
-
distributedTimeSeriesV4
:- Purpose: Defines the name of the ClickHouse distributed table for time series data with lower time range.
- Value:
"distributed_time_series_v4"
-
distributedTimeSeriesV46hrs
:- Purpose: Defines the name of the ClickHouse distributed table for time series data with medium time range.
- Value:
"distributed_time_series_v4_6hrs"
-
distributedTimeSeriesV41day
:- Purpose: Defines the name of the ClickHouse distributed table for time series data with higher time range.
- Value:
"distributed_time_series_v4_1day"
-
distributedSamplesV4
:- Purpose: Defines the name of the ClickHouse distributed table for samples data.
- Value:
"distributed_samples_v4"
Variables
-
sixHoursInMilliseconds
:- Purpose: Defines the duration of six hours in milliseconds.
- Value:
time.Hour.Milliseconds() * 6
-
oneDayInMilliseconds
:- Purpose: Defines the duration of one day in milliseconds.
- Value:
time.Hour.Milliseconds() * 24
Function: getStartAndEndAndTableName
- Purpose: Determines the appropriate ClickHouse table name based on the provided start and end timestamps of a query. It also adjusts the start time to the nearest hour, 6 hours, or day, depending on the time range.
- Parameters:
start
(int64): The start timestamp in milliseconds.end
(int64): The end timestamp in milliseconds.
- Returns:
int64
: The adjusted start timestamp in milliseconds.int64
: The end timestamp in milliseconds (same as input).string
: The name of the ClickHouse table to use for the query. The table selected is based on the time range.distributedTimeSeriesV4
if the time range is less than or equal to 6 hours.distributedTimeSeriesV46hrs
if the time range is less than or equal to 1 day and greater than 6 hours.distributedTimeSeriesV41day
if the time range is greater than 1 day.
- Code Examples
// Example usage of getStartAndEndAndTableName
const start = 1678886400000; // March 15, 2023 00:00:00 GMT
const end = 1678972800000; // March 16, 2023 00:00:00 GMT
const [adjustedStart, adjustedEnd, tableName] = getStartAndEndAndTableName(start, end);
console.log("Adjusted Start:", adjustedStart);
console.log("Adjusted End:", adjustedEnd);
console.log("Table Name:", tableName);
Include in Getting Started: NO