mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
# Backport This will backport the following commits from `main` to `8.12`: - [[Obs UX] Include with_filters and with_query to hosts count event (#173279)](https://github.com/elastic/kibana/pull/173279) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Carlos Crespo","email":"crespocarlos@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-12-18T11:05:18Z","message":"[Obs UX] Include with_filters and with_query to hosts count event (#173279)\n\ncloses https://github.com/elastic/kibana/issues/173077\r\n\r\n## Summary\r\n\r\nAdds `with_query` and `with_filters` attributes to the \"Host View Total\r\nHost Count Retrieved\" event.\r\n\r\n**note**: date picker isn't considered for the flags above.\r\n\r\n### How to test\r\n\r\n1. Start ES, Kibana, and metricbeat\r\n2. Navigate to Infrastructure > Hosts\r\n3. Inspect the `kibana-browser` request payload and check if the new\r\nattributes are there\r\n4. Add/remove filters and query and repeat step 3.\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"c6224788036dc4f8b1f0a9a585b846042f4d89c2","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Metrics UI","release_note:skip","backport:prev-minor","Team:obs-ux-infra_services","v8.13.0"],"number":173279,"url":"https://github.com/elastic/kibana/pull/173279","mergeCommit":{"message":"[Obs UX] Include with_filters and with_query to hosts count event (#173279)\n\ncloses https://github.com/elastic/kibana/issues/173077\r\n\r\n## Summary\r\n\r\nAdds `with_query` and `with_filters` attributes to the \"Host View Total\r\nHost Count Retrieved\" event.\r\n\r\n**note**: date picker isn't considered for the flags above.\r\n\r\n### How to test\r\n\r\n1. Start ES, Kibana, and metricbeat\r\n2. Navigate to Infrastructure > Hosts\r\n3. Inspect the `kibana-browser` request payload and check if the new\r\nattributes are there\r\n4. Add/remove filters and query and repeat step 3.\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"c6224788036dc4f8b1f0a9a585b846042f4d89c2"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/173279","number":173279,"mergeCommit":{"message":"[Obs UX] Include with_filters and with_query to hosts count event (#173279)\n\ncloses https://github.com/elastic/kibana/issues/173077\r\n\r\n## Summary\r\n\r\nAdds `with_query` and `with_filters` attributes to the \"Host View Total\r\nHost Count Retrieved\" event.\r\n\r\n**note**: date picker isn't considered for the flags above.\r\n\r\n### How to test\r\n\r\n1. Start ES, Kibana, and metricbeat\r\n2. Navigate to Infrastructure > Hosts\r\n3. Inspect the `kibana-browser` request payload and check if the new\r\nattributes are there\r\n4. Add/remove filters and query and repeat step 3.\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"c6224788036dc4f8b1f0a9a585b846042f4d89c2"}}]}] BACKPORT--> Co-authored-by: Carlos Crespo <crespocarlos@users.noreply.github.com>
This commit is contained in:
parent
8904970633
commit
3db8c923f4
4 changed files with 76 additions and 32 deletions
|
@ -7,10 +7,11 @@
|
|||
|
||||
import * as rt from 'io-ts';
|
||||
import { ES_SEARCH_STRATEGY, IKibanaSearchResponse } from '@kbn/data-plugin/common';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { catchError, map, Observable, of, startWith } from 'rxjs';
|
||||
import { useCallback, useEffect, useMemo } from 'react';
|
||||
import { catchError, map, Observable, of, startWith, tap } from 'rxjs';
|
||||
import createContainer from 'constate';
|
||||
import type { QueryDslQueryContainer, SearchResponse } from '@elastic/elasticsearch/lib/api/types';
|
||||
import type { ITelemetryClient } from '../../../../services/telemetry';
|
||||
import { useKibanaContextForPlugin } from '../../../../hooks/use_kibana';
|
||||
import { decodeOrThrow } from '../../../../../common/runtime_types';
|
||||
import { useDataSearch, useLatestPartialDataSearchResponse } from '../../../../utils/data_search';
|
||||
|
@ -79,7 +80,23 @@ export const useHostCount = () => {
|
|||
searchCriteria.dateRange.from,
|
||||
searchCriteria.dateRange.to,
|
||||
]),
|
||||
parseResponses: normalizeDataSearchResponse,
|
||||
parseResponses: useMemo(
|
||||
() =>
|
||||
normalizeDataSearchResponse({
|
||||
telemetry,
|
||||
telemetryData: {
|
||||
withQuery: !!searchCriteria.query.query,
|
||||
withFilters:
|
||||
searchCriteria.filters.length > 0 || searchCriteria.panelFilters.length > 0,
|
||||
},
|
||||
}),
|
||||
[
|
||||
searchCriteria.filters.length,
|
||||
searchCriteria.panelFilters.length,
|
||||
searchCriteria.query.query,
|
||||
telemetry,
|
||||
]
|
||||
),
|
||||
});
|
||||
|
||||
const { isRequestRunning, isResponsePartial, latestResponseData, latestResponseErrors } =
|
||||
|
@ -89,14 +106,6 @@ export const useHostCount = () => {
|
|||
fetchHostCount();
|
||||
}, [fetchHostCount]);
|
||||
|
||||
useEffect(() => {
|
||||
if (latestResponseData) {
|
||||
telemetry.reportHostsViewTotalHostCountRetrieved({
|
||||
total: latestResponseData.count.value,
|
||||
});
|
||||
}
|
||||
}, [latestResponseData, telemetry]);
|
||||
|
||||
return {
|
||||
errors: latestResponseErrors,
|
||||
isRequestRunning,
|
||||
|
@ -116,27 +125,42 @@ const INITIAL_STATE = {
|
|||
loaded: 0,
|
||||
total: undefined,
|
||||
};
|
||||
const normalizeDataSearchResponse = (
|
||||
response$: Observable<IKibanaSearchResponse<SearchResponse<Record<string, unknown>>>>
|
||||
) =>
|
||||
response$.pipe(
|
||||
map((response) => ({
|
||||
data: decodeOrThrow(HostCountResponseRT)(response.rawResponse.aggregations),
|
||||
errors: [],
|
||||
isPartial: response.isPartial ?? false,
|
||||
isRunning: response.isRunning ?? false,
|
||||
loaded: response.loaded,
|
||||
total: response.total,
|
||||
})),
|
||||
startWith(INITIAL_STATE),
|
||||
catchError((error) =>
|
||||
of({
|
||||
...INITIAL_STATE,
|
||||
errors: [error.message ?? error],
|
||||
isRunning: false,
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const normalizeDataSearchResponse =
|
||||
({
|
||||
telemetry,
|
||||
telemetryData,
|
||||
}: {
|
||||
telemetry: ITelemetryClient;
|
||||
telemetryData: { withQuery: boolean; withFilters: boolean };
|
||||
}) =>
|
||||
(response$: Observable<IKibanaSearchResponse<SearchResponse<Record<string, unknown>>>>) => {
|
||||
return response$.pipe(
|
||||
map((response) => ({
|
||||
data: decodeOrThrow(HostCountResponseRT)(response.rawResponse.aggregations),
|
||||
errors: [],
|
||||
isPartial: response.isPartial ?? false,
|
||||
isRunning: response.isRunning ?? false,
|
||||
loaded: response.loaded,
|
||||
total: response.total,
|
||||
})),
|
||||
tap(({ data }) => {
|
||||
telemetry.reportHostsViewTotalHostCountRetrieved({
|
||||
total: data.count.value,
|
||||
with_query: telemetryData.withQuery,
|
||||
with_filters: telemetryData.withFilters,
|
||||
});
|
||||
}),
|
||||
startWith(INITIAL_STATE),
|
||||
catchError((error) =>
|
||||
of({
|
||||
...INITIAL_STATE,
|
||||
errors: [error.message ?? error],
|
||||
isRunning: false,
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const HostCountResponseRT = rt.type({
|
||||
count: rt.type({
|
||||
|
|
|
@ -109,6 +109,20 @@ const hostViewTotalHostCountRetrieved: InfraTelemetryEvent = {
|
|||
optional: false,
|
||||
},
|
||||
},
|
||||
with_query: {
|
||||
type: 'boolean',
|
||||
_meta: {
|
||||
description: 'Has KQL query',
|
||||
optional: false,
|
||||
},
|
||||
},
|
||||
with_filters: {
|
||||
type: 'boolean',
|
||||
_meta: {
|
||||
description: 'Has filters',
|
||||
optional: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -172,6 +172,8 @@ describe('TelemetryService', () => {
|
|||
|
||||
telemetry.reportHostsViewTotalHostCountRetrieved({
|
||||
total: 300,
|
||||
with_filters: true,
|
||||
with_query: false,
|
||||
});
|
||||
|
||||
expect(setupParams.analytics.reportEvent).toHaveBeenCalledTimes(1);
|
||||
|
@ -179,6 +181,8 @@ describe('TelemetryService', () => {
|
|||
InfraTelemetryEventTypes.HOST_VIEW_TOTAL_HOST_COUNT_RETRIEVED,
|
||||
{
|
||||
total: 300,
|
||||
with_filters: true,
|
||||
with_query: false,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -41,6 +41,8 @@ export interface HostFlyoutFilterActionParams {
|
|||
|
||||
export interface HostsViewQueryHostsCountRetrievedParams {
|
||||
total: number;
|
||||
with_query: boolean;
|
||||
with_filters: boolean;
|
||||
}
|
||||
|
||||
export interface AssetDetailsFlyoutViewedParams {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue