Skip to content

[FEATURE] prometheus & timeserieschart: Add annotation support#642

Draft
Gladorme wants to merge 11 commits into
perses:mainfrom
Gladorme:annotations-2
Draft

[FEATURE] prometheus & timeserieschart: Add annotation support#642
Gladorme wants to merge 11 commits into
perses:mainfrom
Gladorme:annotations-2

Conversation

@Gladorme
Copy link
Copy Markdown
Member

@Gladorme Gladorme commented Apr 27, 2026

Description

Add annotation generation for Prometheus datasource and add display on TimeSeriesChart.

Idea: add option to ignore "end" to only keep a point

PR related to:

Screenshots

image

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.

Gladorme added 11 commits April 20, 2026 17:14
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
@Gladorme Gladorme changed the title [FEATURE] Add annotation support [FEATURE] prometheus & timeserieschart: Add annotation support Apr 27, 2026
Comment thread barchart/package.json
"@perses-dev/components": "^0.53.1",
"@perses-dev/core": "^0.53.0",
"@perses-dev/plugin-system": "^0.53.1",
"@perses-dev/plugin-system": "file:../../shared/plugin-system",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"file:../../shared/plugin-system ?

@@ -0,0 +1,97 @@
import { AnnotationData } from '@perses-dev/spec';
import { AnnotationContext, datasourceSelectValueToSelector, replaceVariables } from '@perses-dev/plugin-system';
import { DatasourceSpec, parseDurationString } from '@perses-dev/core';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid using core.
All types have been placed either in spec or in shared packages.

import { ReactElement } from 'react';
import { useId } from '@perses-dev/components';
import { produce } from 'immer';
import { Autocomplete, Chip, FormControl, Stack, TextField } from '@mui/material';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Chip' is declared but its value is never read.ts(6133)

Comment on lines +58 to +64
const formatDate = (timeMs: number): { date: string; time: string } => {
const d = new Date(timeMs);
return {
date: formatWithUserTimeZone(d, 'MMM dd, yyyy'),
time: formatWithUserTimeZone(d, 'HH:mm:ss'),
};
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exact same method was added to the /shared/plugin-system
We should have this as a util once.

https://github.com/perses/shared/pull/120/changes#r3309644486

* markLine (vertical dashed lines) and markPoint (triangle markers under the X-axis).
*/
export function buildAnnotationSeries(annotations: TimeSeriesAnnotation[] | undefined): LineSeriesOption[] {
if (!annotations || annotations.length === 0) return [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!annotations?.length) return [];

const markPointData: any[] = [];

annotations.forEach((annotation, index) => {
const color = annotation.color ?? '#FF6B6B';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you have already defined this color-code in plugin-system\src\components\Annotations\AnnotationEditorForm\AnnotationEditorForm.tsx

To avoid duplication the definition could be kept in plugin-system only and exposed so the plugin itself can use it as the default one.

export const DEFAULT_ANNOTATION_COLOR = '#FF6B6B';

Comment on lines +210 to +238
// Add start marker
markPointData.push({
coord: [annotation.start, 0],
symbol: 'triangle',
symbolSize: [12, 12],
symbolRotate: 0,
symbolOffset: [0, 4], // Position below X-axis
itemStyle: { color },
annotationIndex: index,
emphasis: {
disabled: true,
},
isStart: true,
});

// Add end marker
markPointData.push({
coord: [annotation.end, 0],
symbol: 'triangle',
symbolSize: [12, 12],
symbolRotate: 0,
symbolOffset: [0, 4], // Position below X-axis
itemStyle: { color },
annotationIndex: index,
emphasis: {
disabled: true,
},
isEnd: true,
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks cumbersome and could be simplified.

for (const type of ['Start', 'End']) {
  const isStart = type === 'Start';
  markPointData.push({
    coord: [isStart ? annotation.start : annotation.end, 0],
    symbol: 'triangle',
    symbolSize: [12, 12],
    symbolRotate: 0,
    symbolOffset: [0, 4],
    itemStyle: { color },
    annotationIndex: index,
    emphasis: { disabled: true },
    isStart,
    isEnd: !isStart,
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants