mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
# Backport This will backport the following commits from `main` to `8.x`: - [[Streams] fixes the interval type used for the date histogram (#216258)](https://github.com/elastic/kibana/pull/216258) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Luca Wintergerst","email":"luca.wintergerst@elastic.co"},"sourceCommit":{"committedDate":"2025-04-01T11:24:01Z","message":"[Streams] fixes the interval type used for the date histogram (#216258)\n\n## Summary\ncloses https://github.com/elastic/streams-program/issues/225\n\nThe date histogram was hard coded to the fixed interval, which is not\nsuitable for all time ranges that `getCalculateAutoTimeExpression`\nreturns. This adds some logic to choose the correct agg setting.\nI am not sure if this is the cleanest way to solve this, but Lens is\ndoing something similar:\n\n\nhttps://github.com/elastic/kibana/blob/main/x-pack/platform/plugins/shared/lens/public/datasources/form_based/operations/definitions/date_histogram.tsx#L50\n\nBefore:\n\nAfter:\n\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [ ] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n### Identify risks\n\nDoes this PR introduce any risks? For example, consider risks like hard\nto test bugs, performance regression, potential of data loss.\n\nDescribe the risk, its severity, and mitigation for each identified\nrisk. Invite stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See some risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n- [ ] ...\n\n---------\n\nCo-authored-by: Joe Reuter <johannes.reuter@elastic.co>\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"30ad456181fa745d8e1ac6e1c93742ea9a4022ec","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:obs-ux-logs","backport:version","Feature:Streams","v9.1.0","v8.19.0"],"title":"[Streams] fixes the interval type used for the date histogram","number":216258,"url":"https://github.com/elastic/kibana/pull/216258","mergeCommit":{"message":"[Streams] fixes the interval type used for the date histogram (#216258)\n\n## Summary\ncloses https://github.com/elastic/streams-program/issues/225\n\nThe date histogram was hard coded to the fixed interval, which is not\nsuitable for all time ranges that `getCalculateAutoTimeExpression`\nreturns. This adds some logic to choose the correct agg setting.\nI am not sure if this is the cleanest way to solve this, but Lens is\ndoing something similar:\n\n\nhttps://github.com/elastic/kibana/blob/main/x-pack/platform/plugins/shared/lens/public/datasources/form_based/operations/definitions/date_histogram.tsx#L50\n\nBefore:\n\nAfter:\n\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [ ] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n### Identify risks\n\nDoes this PR introduce any risks? For example, consider risks like hard\nto test bugs, performance regression, potential of data loss.\n\nDescribe the risk, its severity, and mitigation for each identified\nrisk. Invite stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See some risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n- [ ] ...\n\n---------\n\nCo-authored-by: Joe Reuter <johannes.reuter@elastic.co>\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"30ad456181fa745d8e1ac6e1c93742ea9a4022ec"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216258","number":216258,"mergeCommit":{"message":"[Streams] fixes the interval type used for the date histogram (#216258)\n\n## Summary\ncloses https://github.com/elastic/streams-program/issues/225\n\nThe date histogram was hard coded to the fixed interval, which is not\nsuitable for all time ranges that `getCalculateAutoTimeExpression`\nreturns. This adds some logic to choose the correct agg setting.\nI am not sure if this is the cleanest way to solve this, but Lens is\ndoing something similar:\n\n\nhttps://github.com/elastic/kibana/blob/main/x-pack/platform/plugins/shared/lens/public/datasources/form_based/operations/definitions/date_histogram.tsx#L50\n\nBefore:\n\nAfter:\n\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [ ] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n### Identify risks\n\nDoes this PR introduce any risks? For example, consider risks like hard\nto test bugs, performance regression, potential of data loss.\n\nDescribe the risk, its severity, and mitigation for each identified\nrisk. Invite stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See some risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n- [ ] ...\n\n---------\n\nCo-authored-by: Joe Reuter <johannes.reuter@elastic.co>\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"30ad456181fa745d8e1ac6e1c93742ea9a4022ec"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Luca Wintergerst <luca.wintergerst@elastic.co>
This commit is contained in:
parent
009adee75e
commit
d9e5ea6f26
1 changed files with 38 additions and 8 deletions
|
@ -18,6 +18,30 @@ import { useIlmPhasesColorAndDescription } from './use_ilm_phases_color_and_desc
|
|||
const TIMESTAMP_FIELD = '@timestamp';
|
||||
const RANDOM_SAMPLER_PROBABILITY = 0.1;
|
||||
|
||||
// some units are not supported for the fixed_interval of the date histogram
|
||||
// this function uses the calculateAutoTimeExpression function to determine
|
||||
// if the interval should be a calendar_interval or a fixed_interval
|
||||
const getIntervalAndType = (
|
||||
timeRange: TimeRange,
|
||||
core: { uiSettings: { get: (key: string) => any } }
|
||||
): { interval: string; intervalType: string } | undefined => {
|
||||
const start = datemath.parse(timeRange.from);
|
||||
const end = datemath.parse(timeRange.to);
|
||||
const interval = getCalculateAutoTimeExpression((key) => core.uiSettings.get(key))(timeRange);
|
||||
|
||||
if (!start || !end || !interval) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const calendarIntervalUnits = new Set(['w', 'M', 'q', 'y']);
|
||||
|
||||
const intervalType = calendarIntervalUnits.has(interval.replace(/^\d+/, ''))
|
||||
? 'calendar_interval'
|
||||
: 'fixed_interval';
|
||||
|
||||
return { interval, intervalType };
|
||||
};
|
||||
|
||||
export const useIngestionRate = ({
|
||||
definition,
|
||||
stats,
|
||||
|
@ -42,10 +66,11 @@ export const useIngestionRate = ({
|
|||
|
||||
const start = datemath.parse(timeRange.from);
|
||||
const end = datemath.parse(timeRange.to);
|
||||
const interval = getCalculateAutoTimeExpression((key) => core.uiSettings.get(key))(timeRange);
|
||||
if (!start || !end || !interval) {
|
||||
const intervalData = getIntervalAndType(timeRange, core);
|
||||
if (!start || !end || !intervalData) {
|
||||
return;
|
||||
}
|
||||
const { interval, intervalType } = intervalData;
|
||||
|
||||
const {
|
||||
rawResponse: { aggregations },
|
||||
|
@ -73,13 +98,15 @@ export const useIngestionRate = ({
|
|||
sampler: {
|
||||
random_sampler: {
|
||||
probability: RANDOM_SAMPLER_PROBABILITY,
|
||||
seed: 42,
|
||||
},
|
||||
aggs: {
|
||||
docs_count: {
|
||||
date_histogram: {
|
||||
field: TIMESTAMP_FIELD,
|
||||
fixed_interval: interval,
|
||||
[intervalType]: interval,
|
||||
min_doc_count: 0,
|
||||
extended_bounds: { min: start, max: end },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -102,7 +129,7 @@ export const useIngestionRate = ({
|
|||
})),
|
||||
};
|
||||
},
|
||||
[data.search, definition, timeRange, stats, core.uiSettings]
|
||||
[definition, stats, timeRange, core, data.search]
|
||||
);
|
||||
|
||||
return {
|
||||
|
@ -143,10 +170,11 @@ export const useIngestionRatePerTier = ({
|
|||
|
||||
const start = datemath.parse(timeRange.from);
|
||||
const end = datemath.parse(timeRange.to);
|
||||
const interval = getCalculateAutoTimeExpression((key) => core.uiSettings.get(key))(timeRange);
|
||||
if (!start || !end || !interval) {
|
||||
const intervalData = getIntervalAndType(timeRange, core);
|
||||
if (!start || !end || !intervalData) {
|
||||
return;
|
||||
}
|
||||
const { interval, intervalType } = intervalData;
|
||||
|
||||
const {
|
||||
rawResponse: { aggregations },
|
||||
|
@ -182,13 +210,15 @@ export const useIngestionRatePerTier = ({
|
|||
sampler: {
|
||||
random_sampler: {
|
||||
probability: RANDOM_SAMPLER_PROBABILITY,
|
||||
seed: 42,
|
||||
},
|
||||
aggs: {
|
||||
docs_count: {
|
||||
date_histogram: {
|
||||
field: TIMESTAMP_FIELD,
|
||||
fixed_interval: interval,
|
||||
[intervalType]: interval,
|
||||
min_doc_count: 0,
|
||||
extended_bounds: { min: start, max: end },
|
||||
},
|
||||
aggs: {
|
||||
indices: {
|
||||
|
@ -250,7 +280,7 @@ export const useIngestionRatePerTier = ({
|
|||
|
||||
return { start, end, interval, buckets };
|
||||
},
|
||||
[data.search, streamsRepositoryClient, definition, timeRange, stats, core.uiSettings, ilmPhases]
|
||||
[definition, stats, timeRange, core, data.search, streamsRepositoryClient, ilmPhases]
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue