Skip to content

Commit

Permalink
Merge branch 'main' into kbn-179458-es-secondary-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jun 13, 2024
2 parents 0c014fb + fe59dd4 commit f5d2f01
Show file tree
Hide file tree
Showing 156 changed files with 2,893 additions and 1,637 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ packages/kbn-reporting/server @elastic/appex-sharedux
packages/kbn-resizable-layout @elastic/kibana-data-discovery
examples/resizable_layout_examples @elastic/kibana-data-discovery
x-pack/test/plugin_functional/plugins/resolver_test @elastic/security-solution
packages/response-ops/feature_flag_service @elastic/response-ops
examples/response_stream @elastic/ml-ui
packages/kbn-rison @elastic/kibana-operations
x-pack/plugins/rollup @elastic/kibana-management
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"**/@types/node": "20.10.5",
"**/@typescript-eslint/utils": "5.62.0",
"**/chokidar": "^3.5.3",
"**/d3-scale/**/d3-color": "npm:@elastic/[email protected]",
"**/d3-scale/**/d3-color": "npm:@elastic/kibana-[email protected]",
"**/globule/minimatch": "^3.1.2",
"**/hoist-non-react-statics": "^3.3.2",
"**/isomorphic-fetch/node-fetch": "^2.6.7",
Expand Down Expand Up @@ -692,6 +692,7 @@
"@kbn/resizable-layout": "link:packages/kbn-resizable-layout",
"@kbn/resizable-layout-examples-plugin": "link:examples/resizable_layout_examples",
"@kbn/resolver-test-plugin": "link:x-pack/test/plugin_functional/plugins/resolver_test",
"@kbn/response-ops-feature-flag-service": "link:packages/response-ops/feature_flag_service",
"@kbn/response-stream-plugin": "link:examples/response_stream",
"@kbn/rison": "link:packages/kbn-rison",
"@kbn/rollup-plugin": "link:x-pack/plugins/rollup",
Expand Down
27 changes: 27 additions & 0 deletions packages/response-ops/feature_flag_service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# @kbn/response-ops-feature-flags

This packages exposes a feature flag service that is used in the ResponseOps plugins and packages to handle feature flags.

## Usage

### Create feature flag service

```
const featureFlagService = createFeatureFlagService(['test.myFeature', 'test.myFeature.subFeature']); // TS will infer the types automatically
```

or

```
type FeatureFlagValues = 'test.myFeature' | 'test.myOtherFeature'
const featureFlagService = createFeatureFlagService<FeatureFlagValues>(['test.myFeature']);
```

### Checking the existence of a feature flag
```
const featureFlagService = createFeatureFlagService(['test.myFeature', 'test.myFeature.subFeature']);
if (featureFlagService.isFeatureFlagSet('test.myFeature')) {
// my feature code
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { createFeatureFlagService } from './feature_flag_service';

type FeatureFlagValues = 'test.myFeature' | 'test.myOtherFeature';

describe('FeatureFlagService', () => {
it('returns true if the feature exists', () => {
const featureFlagService = createFeatureFlagService(['test.myFeature']);
expect(featureFlagService.isFeatureFlagSet('test.myFeature')).toBe(true);
});

it('returns false if the feature does not exist', () => {
const featureFlagService = createFeatureFlagService(['test.myFeature']);
// @ts-expect-error: foo is not part of the valid feature flags
expect(featureFlagService.isFeatureFlagSet('foo')).toBe(false);
});

it('returns true if the feature exists (as typed)', () => {
const featureFlagService = createFeatureFlagService<FeatureFlagValues>(['test.myFeature']);
expect(featureFlagService.isFeatureFlagSet('test.myFeature')).toBe(true);
});
});
25 changes: 25 additions & 0 deletions packages/response-ops/feature_flag_service/feature_flag_service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

class FeatureFlag<T extends string = string> {
private readonly featureFlags = new Set<T>();

constructor(featureFlags: T[]) {
featureFlags.forEach((featureFlag) => this.featureFlags.add(featureFlag));
}

public isFeatureFlagSet(featureFlag: T): boolean {
return this.featureFlags.has(featureFlag);
}
}

export const createFeatureFlagService = <T extends string>(featureFlags: T[]) => {
return new FeatureFlag<typeof featureFlags[number]>(featureFlags);
};

export type FeatureFlagService<T extends string = string> = InstanceType<typeof FeatureFlag<T>>;
10 changes: 10 additions & 0 deletions packages/response-ops/feature_flag_service/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { createFeatureFlagService } from './feature_flag_service';
export type { FeatureFlagService } from './feature_flag_service';
13 changes: 13 additions & 0 deletions packages/response-ops/feature_flag_service/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../..',
roots: ['<rootDir>/packages/response-ops/feature_flag_service'],
};
5 changes: 5 additions & 0 deletions packages/response-ops/feature_flag_service/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/response-ops-feature-flag-service",
"owner": "@elastic/response-ops"
}
6 changes: 6 additions & 0 deletions packages/response-ops/feature_flag_service/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/response-ops-feature-flag-service",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
17 changes: 17 additions & 0 deletions packages/response-ops/feature_flag_service/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": []
}
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,8 @@
"@kbn/resizable-layout-examples-plugin/*": ["examples/resizable_layout_examples/*"],
"@kbn/resolver-test-plugin": ["x-pack/test/plugin_functional/plugins/resolver_test"],
"@kbn/resolver-test-plugin/*": ["x-pack/test/plugin_functional/plugins/resolver_test/*"],
"@kbn/response-ops-feature-flag-service": ["packages/response-ops/feature_flag_service"],
"@kbn/response-ops-feature-flag-service/*": ["packages/response-ops/feature_flag_service/*"],
"@kbn/response-stream-plugin": ["examples/response_stream"],
"@kbn/response-stream-plugin/*": ["examples/response_stream/*"],
"@kbn/rison": ["packages/kbn-rison"],
Expand Down
10 changes: 1 addition & 9 deletions x-pack/packages/ml/aiops_components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@ export { DualBrush, DualBrushAnnotation } from './src/dual_brush';
export { ProgressControls } from './src/progress_controls';
export {
DocumentCountChart,
DocumentCountChartWithAutoAnalysisStart,
DocumentCountChartRedux,
type BrushSettings,
type BrushSelectionUpdateHandler,
} from './src/document_count_chart';
export type { DocumentCountChartProps } from './src/document_count_chart';
export {
useLogRateAnalysisStateContext,
LogRateAnalysisStateProvider,
type GroupTableItem,
type GroupTableItemGroup,
type TableItemAction,
} from './src/log_rate_analysis_state_provider';
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,17 @@ import {
getSnappedWindowParameters,
getWindowParametersForTrigger,
type DocumentCountStatsChangePoint,
type LogRateAnalysisType,
type LogRateHistogramItem,
type WindowParameters,
} from '@kbn/aiops-log-rate-analysis';
import { type BrushSelectionUpdatePayload } from '@kbn/aiops-log-rate-analysis/state';
import { MULTILAYER_TIME_AXIS_STYLE } from '@kbn/charts-plugin/common';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { ChartsPluginStart } from '@kbn/charts-plugin/public';
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';

import { DualBrush, DualBrushAnnotation } from '../..';

import { useLogRateAnalysisStateContext } from '../log_rate_analysis_state_provider';

import { BrushBadge } from './brush_badge';

declare global {
Expand Down Expand Up @@ -77,22 +75,17 @@ export interface BrushSettings {
}

/**
* Callback function which gets called when the brush selection has changed
*
* @param windowParameters Baseline and deviation time ranges.
* @param force Force update
* @param logRateAnalysisType `spike` or `dip` based on median log rate bucket size
* Callback to set the autoRunAnalysis flag
*/
export type BrushSelectionUpdateHandler = (
windowParameters: WindowParameters,
force: boolean,
logRateAnalysisType: LogRateAnalysisType
) => void;
type SetAutoRunAnalysisFn = (isAutoRun: boolean) => void;

/**
* Callback to set the autoRunAnalysis flag
* Brush selection update handler
*/
type SetAutoRunAnalysisFn = (isAutoRun: boolean) => void;
type BrushSelectionUpdateHandler = (
/** Payload for the brush selection update */
d: BrushSelectionUpdatePayload
) => void;

/**
* Props for document count chart
Expand Down Expand Up @@ -126,7 +119,7 @@ export interface DocumentCountChartProps {
/** Whether or not brush has been reset */
isBrushCleared: boolean;
/** Callback to set the autoRunAnalysis flag */
setAutoRunAnalysis?: SetAutoRunAnalysisFn;
setAutoRunAnalysisFn?: SetAutoRunAnalysisFn;
/** Timestamp for start of initial analysis */
autoAnalysisStart?: number | WindowParameters;
/** Optional style to override bar chart */
Expand Down Expand Up @@ -190,7 +183,7 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = (props) => {
interval,
chartPointsSplitLabel,
isBrushCleared,
setAutoRunAnalysis,
setAutoRunAnalysisFn,
autoAnalysisStart,
barColorOverride,
barStyleAccessor,
Expand Down Expand Up @@ -315,15 +308,15 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = (props) => {
windowParameters === undefined &&
adjustedChartPoints !== undefined
) {
if (setAutoRunAnalysis) {
if (setAutoRunAnalysisFn) {
const autoRun =
typeof startRange !== 'number' ||
(typeof startRange === 'number' &&
changePoint !== undefined &&
startRange >= changePoint.startTs &&
startRange <= changePoint.endTs);

setAutoRunAnalysis(autoRun);
setAutoRunAnalysisFn(autoRun);
}

const wp = getWindowParametersForTrigger(
Expand All @@ -338,11 +331,11 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = (props) => {
setWindowParameters(wpSnap);

if (brushSelectionUpdateHandler !== undefined) {
brushSelectionUpdateHandler(
wpSnap,
true,
getLogRateAnalysisType(adjustedChartPoints, wpSnap)
);
brushSelectionUpdateHandler({
windowParameters: wpSnap,
force: true,
analysisType: getLogRateAnalysisType(adjustedChartPoints, wpSnap),
});
}
}
}
Expand All @@ -354,7 +347,7 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = (props) => {
timeRangeLatest,
snapTimestamps,
originalWindowParameters,
setAutoRunAnalysis,
setAutoRunAnalysisFn,
setWindowParameters,
brushSelectionUpdateHandler,
adjustedChartPoints,
Expand Down Expand Up @@ -395,7 +388,11 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = (props) => {
}
setWindowParameters(wp);
setWindowParametersAsPixels(wpPx);
brushSelectionUpdateHandler(wp, false, getLogRateAnalysisType(adjustedChartPoints, wp));
brushSelectionUpdateHandler({
windowParameters: wp,
force: false,
analysisType: getLogRateAnalysisType(adjustedChartPoints, wp),
});
}

const [mlBrushWidth, setMlBrushWidth] = useState<number>();
Expand Down Expand Up @@ -556,24 +553,3 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = (props) => {
</>
);
};

/**
* Functional component that renders a `DocumentCountChart` with additional properties
* managed by the log rate analysis state. It leverages the `useLogRateAnalysisStateContext`
* to acquire state variables like `initialAnalysisStart` and functions such as
* `setAutoRunAnalysis`. These values are then passed as props to the `DocumentCountChart`.
*
* @param props - The properties passed to the DocumentCountChart component.
* @returns The DocumentCountChart component enhanced with automatic analysis start capabilities.
*/
export const DocumentCountChartWithAutoAnalysisStart: FC<DocumentCountChartProps> = (props) => {
const { initialAnalysisStart, setAutoRunAnalysis } = useLogRateAnalysisStateContext();

return (
<DocumentCountChart
{...props}
autoAnalysisStart={initialAnalysisStart}
setAutoRunAnalysis={setAutoRunAnalysis}
/>
);
};
Loading

0 comments on commit f5d2f01

Please sign in to comment.