[TSVB] Use panel interval for annotations (#125222)

This commit is contained in:
Joe Reuter 2022-02-14 14:33:55 +01:00 committed by GitHub
parent 617a602c5d
commit 5babc9f663
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 7 deletions

View file

@ -31,6 +31,7 @@ export async function getAnnotationRequestParams(
capabilities,
uiSettings,
cachedIndexPatternFetcher,
buildSeriesMetaParams,
}: AnnotationServices
): Promise<EsSearchRequest> {
const annotationIndex = await cachedIndexPatternFetcher(annotation.index_pattern);
@ -43,6 +44,7 @@ export async function getAnnotationRequestParams(
annotationIndex,
capabilities,
uiSettings,
getMetaParams: () => buildSeriesMetaParams(annotationIndex, Boolean(panel.use_kibana_indexes)),
});
return {

View file

@ -23,16 +23,26 @@ export const dateHistogram: AnnotationsRequestProcessorsFunction = ({
annotationIndex,
capabilities,
uiSettings,
getMetaParams,
}) => {
return (next) => async (doc) => {
const maxBarsUiSettings = await uiSettings.get(UI_SETTINGS.HISTOGRAM_MAX_BARS);
const barTargetUiSettings = await uiSettings.get(UI_SETTINGS.HISTOGRAM_BAR_TARGET);
const timeField = annotation.time_field || annotationIndex.indexPattern?.timeFieldName || '';
const { interval, maxBars } = await getMetaParams();
if (panel.use_kibana_indexes) {
validateField(timeField, annotationIndex);
}
const { bucketSize, intervalString } = getBucketSize(
req,
interval,
capabilities,
maxBars ? Math.min(maxBarsUiSettings, maxBars) : barTargetUiSettings
);
const { bucketSize: autoBucketSize, intervalString: autoIntervalString } = getBucketSize(
req,
'auto',
capabilities,
@ -49,7 +59,7 @@ export const dateHistogram: AnnotationsRequestProcessorsFunction = ({
min: from.valueOf(),
max: to.valueOf() - bucketSize * 1000,
},
...dateHistogramInterval(intervalString),
...dateHistogramInterval(autoBucketSize < bucketSize ? autoIntervalString : intervalString),
});
return next(doc);
};

View file

@ -22,6 +22,11 @@ export interface AnnotationsRequestProcessorsParams {
annotationIndex: FetchedIndexPattern;
capabilities: SearchCapabilities;
uiSettings: IUiSettingsClient;
getMetaParams: () => Promise<{
maxBars: number;
timeField?: string | undefined;
interval: string;
}>;
}
export type AnnotationSearchRequest = Record<string, unknown>;

View file

@ -468,12 +468,9 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await visualBuilder.setAnnotationFilter('geo.dest : "AW" or geo.src : "AM"');
await visualBuilder.setAnnotationFields('extension.raw');
await visualBuilder.setAnnotationRowTemplate('extension: {{extension.raw}}');
const annotationsData = await visualBuilder.getAnnotationsData();
expect(annotationsData).to.eql(expectedAnnotationsData);
});
it('should display correct annotations data for machine.os.raw and memory fields', async () => {
const expectedAnnotationsData = [
{
@ -512,12 +509,9 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await visualBuilder.setAnnotationRowTemplate(
'OS: {{machine.os.raw}}, memory: {{memory}}'
);
const annotationsData = await visualBuilder.getAnnotationsData();
expect(annotationsData).to.eql(expectedAnnotationsData);
});
it('should display correct annotations data when using runtime field', async () => {
const expectedAnnotationsData = [
{