From 831e8acf15ca4c108fd220edb28008b34efe8dc2 Mon Sep 17 00:00:00 2001 From: Galen Kistler <109082771+gtk-grafana@users.noreply.github.com> Date: Wed, 26 Jul 2023 14:03:17 -0500 Subject: [PATCH] Prometheus: Add support for day_of_year (#72403) add querybuilder/code editor support for day_of_year --- public/app/plugins/datasource/prometheus/promql.ts | 7 +++++++ .../datasource/prometheus/querybuilder/operations.ts | 4 ++++ .../plugins/datasource/prometheus/querybuilder/types.ts | 1 + 3 files changed, 12 insertions(+) diff --git a/public/app/plugins/datasource/prometheus/promql.ts b/public/app/plugins/datasource/prometheus/promql.ts index 6baa26d4899..c37f52796ba 100644 --- a/public/app/plugins/datasource/prometheus/promql.ts +++ b/public/app/plugins/datasource/prometheus/promql.ts @@ -238,6 +238,13 @@ export const FUNCTIONS = [ documentation: 'Returns the day of the week for each of the given times in UTC. Returned values are from 0 to 6, where 0 means Sunday etc.', }, + { + insertText: 'day_of_year', + label: 'day_of_year', + detail: 'day_of_year(v=vector(time()) instant-vector)', + documentation: + 'Returns the day of the year for each of the given times in UTC. Returned values are from 1 to 365 for non-leap years, and 1 to 366 in leap years.', + }, { insertText: 'days_in_month', label: 'days_in_month', diff --git a/public/app/plugins/datasource/prometheus/querybuilder/operations.ts b/public/app/plugins/datasource/prometheus/querybuilder/operations.ts index 788689ee7da..2c091045bb2 100644 --- a/public/app/plugins/datasource/prometheus/querybuilder/operations.ts +++ b/public/app/plugins/datasource/prometheus/querybuilder/operations.ts @@ -164,6 +164,10 @@ export function getOperationDefinitions(): QueryBuilderOperationDef[] { id: PromOperationId.DayOfWeek, category: PromVisualQueryOperationCategory.Time, }), + createFunction({ + id: PromOperationId.DayOfYear, + category: PromVisualQueryOperationCategory.Time, + }), createFunction({ id: PromOperationId.DaysInMonth, category: PromVisualQueryOperationCategory.Time, diff --git a/public/app/plugins/datasource/prometheus/querybuilder/types.ts b/public/app/plugins/datasource/prometheus/querybuilder/types.ts index 49cef909698..24750f21a96 100644 --- a/public/app/plugins/datasource/prometheus/querybuilder/types.ts +++ b/public/app/plugins/datasource/prometheus/querybuilder/types.ts @@ -53,6 +53,7 @@ export enum PromOperationId { CountValues = 'count_values', DayOfMonth = 'day_of_month', DayOfWeek = 'day_of_week', + DayOfYear = 'day_of_year', DaysInMonth = 'days_in_month', Deg = 'deg', Delta = 'delta',