mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Infra] Check ML permissions before requesting ML data (#218069)
fixes [#189213](https://github.com/elastic/kibana/issues/189213) ## Summary Checks whether the user has permission to ML before triggering requests to fetch ML data ### How to test - Create a user whose role doesn't have permission to ML, but has permission to O11y apps - Run `node scripts/synthtrace infra_hosts_with_apm_hosts --live --clean` - Navigate to Inventory Infrastructure / Hosts View --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
b1ffcf3060
commit
5423655975
3 changed files with 28 additions and 2 deletions
|
@ -83,8 +83,9 @@ class LosslessHistogram {
|
|||
record(value: number) {
|
||||
const countForValue = this.trackedValues.get(value);
|
||||
if (
|
||||
this.backingHistogram ||
|
||||
(countForValue === undefined && this.trackedValues.size >= MAX_VALUES_TO_TRACK_LOSSLESS)
|
||||
this.backingHistogram &&
|
||||
countForValue === undefined &&
|
||||
this.trackedValues.size >= MAX_VALUES_TO_TRACK_LOSSLESS
|
||||
) {
|
||||
this.getBackingHistogram().record(value);
|
||||
return;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import { useState, useCallback, useEffect, useReducer } from 'react';
|
||||
import type { BehaviorSubject } from 'rxjs';
|
||||
import { decodeOrThrow } from '@kbn/io-ts-utils';
|
||||
import { useKibanaContextForPlugin } from '../../../../hooks/use_kibana';
|
||||
import { isPending, isFailure, useFetcher } from '../../../../hooks/use_fetcher';
|
||||
import type {
|
||||
Sort,
|
||||
|
@ -185,6 +186,9 @@ export const useMetricsHostsAnomaliesResults = (
|
|||
active = true,
|
||||
}: { request$?: BehaviorSubject<(() => Promise<unknown>) | undefined>; active?: boolean }
|
||||
) => {
|
||||
const {
|
||||
services: { application },
|
||||
} = useKibanaContextForPlugin();
|
||||
const [reducerState, dispatch] = useReducer(
|
||||
stateReducer,
|
||||
STATE_DEFAULTS,
|
||||
|
@ -199,12 +203,19 @@ export const useMetricsHostsAnomaliesResults = (
|
|||
|
||||
const [metricsHostsAnomalies, setMetricsHostsAnomalies] = useState<MetricsHostsAnomalies>([]);
|
||||
|
||||
const mlCapabilities = application.capabilities.ml as { canGetJobs: boolean } | undefined;
|
||||
const canGetAnomalies = mlCapabilities?.canGetJobs;
|
||||
|
||||
const {
|
||||
data: response,
|
||||
status,
|
||||
refetch,
|
||||
} = useFetcher(
|
||||
async (callApi) => {
|
||||
if (!canGetAnomalies) {
|
||||
return;
|
||||
}
|
||||
|
||||
const apiResponse = await callApi(INFA_ML_GET_METRICS_HOSTS_ANOMALIES_PATH, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(
|
||||
|
@ -242,6 +253,7 @@ export const useMetricsHostsAnomaliesResults = (
|
|||
reducerState.timeRange.start,
|
||||
search,
|
||||
sourceId,
|
||||
canGetAnomalies,
|
||||
],
|
||||
{
|
||||
requestObservable$: request$,
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import { useState, useCallback, useEffect, useReducer } from 'react';
|
||||
import type { BehaviorSubject } from 'rxjs';
|
||||
import { decodeOrThrow } from '@kbn/io-ts-utils';
|
||||
import { useKibanaContextForPlugin } from '../../../../hooks/use_kibana';
|
||||
import { isFailure, isPending, useFetcher } from '../../../../hooks/use_fetcher';
|
||||
import type {
|
||||
Sort,
|
||||
|
@ -162,6 +163,10 @@ export const useMetricsK8sAnomaliesResults = (
|
|||
active = true,
|
||||
}: { request$?: BehaviorSubject<(() => Promise<unknown>) | undefined>; active?: boolean }
|
||||
) => {
|
||||
const {
|
||||
services: { application },
|
||||
} = useKibanaContextForPlugin();
|
||||
|
||||
const [metricsK8sAnomalies, setMetricsK8sAnomalies] = useState<MetricsK8sAnomalies>([]);
|
||||
const initStateReducer = (stateDefaults: ReducerStateDefaults): ReducerState => {
|
||||
return {
|
||||
|
@ -177,12 +182,19 @@ export const useMetricsK8sAnomaliesResults = (
|
|||
};
|
||||
const [reducerState, dispatch] = useReducer(stateReducer, STATE_DEFAULTS, initStateReducer);
|
||||
|
||||
const mlCapabilities = application.capabilities.ml as { canGetJobs: boolean } | undefined;
|
||||
const canGetAnomalies = mlCapabilities?.canGetJobs;
|
||||
|
||||
const {
|
||||
data: response,
|
||||
status,
|
||||
refetch,
|
||||
} = useFetcher(
|
||||
async (callApi) => {
|
||||
if (!canGetAnomalies) {
|
||||
return;
|
||||
}
|
||||
|
||||
const apiResponse = await callApi(INFA_ML_GET_METRICS_K8S_ANOMALIES_PATH, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(
|
||||
|
@ -218,6 +230,7 @@ export const useMetricsK8sAnomaliesResults = (
|
|||
reducerState.timeRange.start,
|
||||
search,
|
||||
sourceId,
|
||||
canGetAnomalies,
|
||||
],
|
||||
{
|
||||
requestObservable$: request$,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue