Skip to content

Commit

Permalink
[8.x] chore(slo): refactor transform generators and managers dependen…
Browse files Browse the repository at this point in the history
…cy injection (#201031) (#201390)

# Backport

This will backport the following commits from `main` to `8.x`:
- [chore(slo): refactor transform generators and managers dependency
injection (#201031)](#201031)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Kevin
Delemme","email":"kevin.delemme@elastic.co"},"sourceCommit":{"committedDate":"2024-11-22T13:52:18Z","message":"chore(slo):
refactor transform generators and managers dependency injection
(#201031)","sha":"204666310fec611773a1bfb8c0c80a72f1dc5468","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-management","v8.17.0"],"title":"chore(slo):
refactor transform generators and managers dependency
injection","number":201031,"url":"https://github.com/elastic/kibana/pull/201031","mergeCommit":{"message":"chore(slo):
refactor transform generators and managers dependency injection
(#201031)","sha":"204666310fec611773a1bfb8c0c80a72f1dc5468"}},"sourceBranch":"main","suggestedTargetBranches":["8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201031","number":201031,"mergeCommit":{"message":"chore(slo):
refactor transform generators and managers dependency injection
(#201031)","sha":"204666310fec611773a1bfb8c0c80a72f1dc5468"}},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Kevin Delemme <kevin.delemme@elastic.co>
  • Loading branch information
kibanamachine and kdelemme authored Nov 22, 2024
1 parent c5aec31 commit f8217ef
Show file tree
Hide file tree
Showing 23 changed files with 620 additions and 655 deletions.
100 changes: 51 additions & 49 deletions x-pack/plugins/observability_solution/slo/server/routes/slo/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
updateSLOParamsSchema,
} from '@kbn/slo-schema';
import { getOverviewParamsSchema } from '@kbn/slo-schema/src/rest_specs/routes/get_overview';
import type { IndicatorTypes } from '../../domain/models';
import { executeWithErrorHandler } from '../../errors';
import {
CreateSLO,
Expand Down Expand Up @@ -60,29 +59,10 @@ import { SloDefinitionClient } from '../../services/slo_definition_client';
import { getSloSettings, storeSloSettings } from '../../services/slo_settings';
import { DefaultSummarySearchClient } from '../../services/summary_search_client';
import { DefaultSummaryTransformGenerator } from '../../services/summary_transform_generator/summary_transform_generator';
import {
ApmTransactionDurationTransformGenerator,
ApmTransactionErrorRateTransformGenerator,
HistogramTransformGenerator,
KQLCustomTransformGenerator,
MetricCustomTransformGenerator,
SyntheticsAvailabilityTransformGenerator,
TimesliceMetricTransformGenerator,
TransformGenerator,
} from '../../services/transform_generators';
import { createTransformGenerators } from '../../services/transform_generators';
import { createSloServerRoute } from '../create_slo_server_route';
import { SLORoutesDependencies } from '../types';

const transformGenerators: Record<IndicatorTypes, TransformGenerator> = {
'sli.apm.transactionDuration': new ApmTransactionDurationTransformGenerator(),
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(),
'sli.synthetics.availability': new SyntheticsAvailabilityTransformGenerator(),
'sli.kql.custom': new KQLCustomTransformGenerator(),
'sli.metric.custom': new MetricCustomTransformGenerator(),
'sli.histogram.custom': new HistogramTransformGenerator(),
'sli.metric.timeslice': new TimesliceMetricTransformGenerator(),
};

const assertPlatinumLicense = async (plugins: SLORoutesDependencies['plugins']) => {
const licensing = await plugins.licensing.start();
const hasCorrectLicense = (await licensing.getLicense()).hasAtLeast('platinum');
Expand Down Expand Up @@ -120,14 +100,18 @@ const createSLORoute = createSloServerRoute({
getSpaceId(plugins, request),
dataViews.dataViewsServiceFactory(soClient, esClient),
]);
const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger,

const transformGenerators = createTransformGenerators(
spaceId,
dataViewsService,
sloContext.isServerless
);

const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger
);
const summaryTransformManager = new DefaultSummaryTransformManager(
new DefaultSummaryTransformGenerator(),
scopedClusterClient,
Expand Down Expand Up @@ -168,14 +152,17 @@ const inspectSLORoute = createSloServerRoute({
const soClient = core.savedObjects.client;
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const dataViewsService = await dataViews.dataViewsServiceFactory(soClient, esClient);
const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger,

const transformGenerators = createTransformGenerators(
spaceId,
dataViewsService,
sloContext.isServerless
);
const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger
);
const summaryTransformManager = new DefaultSummaryTransformManager(
new DefaultSummaryTransformGenerator(),
scopedClusterClient,
Expand Down Expand Up @@ -218,14 +205,17 @@ const updateSLORoute = createSloServerRoute({
const soClient = core.savedObjects.client;
const dataViewsService = await dataViews.dataViewsServiceFactory(soClient, esClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger,

const transformGenerators = createTransformGenerators(
spaceId,
dataViewsService,
sloContext.isServerless
);
const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger
);
const summaryTransformManager = new DefaultSummaryTransformManager(
new DefaultSummaryTransformGenerator(),
scopedClusterClient,
Expand Down Expand Up @@ -271,14 +261,16 @@ const deleteSLORoute = createSloServerRoute({

const dataViewsService = await dataViews.dataViewsServiceFactory(soClient, esClient);

const transformGenerators = createTransformGenerators(
spaceId,
dataViewsService,
sloContext.isServerless
);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger,
spaceId,
dataViewsService,
sloContext.isServerless
logger
);

const summaryTransformManager = new DefaultSummaryTransformManager(
Expand Down Expand Up @@ -346,14 +338,18 @@ const enableSLORoute = createSloServerRoute({
const esClient = core.elasticsearch.client.asCurrentUser;
const dataViewsService = await dataViews.dataViewsServiceFactory(soClient, esClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger,

const transformGenerators = createTransformGenerators(
spaceId,
dataViewsService,
sloContext.isServerless
);

const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger
);
const summaryTransformManager = new DefaultSummaryTransformManager(
new DefaultSummaryTransformGenerator(),
scopedClusterClient,
Expand Down Expand Up @@ -388,14 +384,17 @@ const disableSLORoute = createSloServerRoute({
const esClient = core.elasticsearch.client.asCurrentUser;
const dataViewsService = await dataViews.dataViewsServiceFactory(soClient, esClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger,

const transformGenerators = createTransformGenerators(
spaceId,
dataViewsService,
sloContext.isServerless
);
const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger
);
const summaryTransformManager = new DefaultSummaryTransformManager(
new DefaultSummaryTransformGenerator(),
scopedClusterClient,
Expand Down Expand Up @@ -430,14 +429,17 @@ const resetSLORoute = createSloServerRoute({

const dataViewsService = await dataViews.dataViewsServiceFactory(soClient, esClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger,

const transformGenerators = createTransformGenerators(
spaceId,
dataViewsService,
sloContext.isServerless
);
const transformManager = new DefaultTransformManager(
transformGenerators,
scopedClusterClient,
logger
);
const summaryTransformManager = new DefaultSummaryTransformManager(
new DefaultSummaryTransformGenerator(),
scopedClusterClient,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { dataViewsService } from '@kbn/data-views-plugin/server/mocks';
import { ALL_VALUE } from '@kbn/slo-schema';
import { twoMinute } from '../fixtures/duration';
import {
Expand All @@ -13,15 +14,14 @@ import {
createSLOWithTimeslicesBudgetingMethod,
} from '../fixtures/slo';
import { ApmTransactionDurationTransformGenerator } from './apm_transaction_duration';
import { dataViewsService } from '@kbn/data-views-plugin/server/mocks';

const generator = new ApmTransactionDurationTransformGenerator();
const spaceId = 'custom-space';
const SPACE_ID = 'custom-space';
const generator = new ApmTransactionDurationTransformGenerator(SPACE_ID, dataViewsService);

describe('APM Transaction Duration Transform Generator', () => {
it('returns the expected transform params with every specified indicator params', async () => {
const slo = createSLO({ id: 'irrelevant', indicator: createAPMTransactionDurationIndicator() });
const transform = await generator.getTransformParams(slo, spaceId, dataViewsService);
const transform = await generator.getTransformParams(slo);

expect(transform).toMatchSnapshot();
});
Expand All @@ -31,7 +31,7 @@ describe('APM Transaction Duration Transform Generator', () => {
id: 'irrelevant',
indicator: createAPMTransactionDurationIndicator(),
});
const transform = await generator.getTransformParams(slo, spaceId, dataViewsService);
const transform = await generator.getTransformParams(slo);

expect(transform).toMatchSnapshot();
});
Expand All @@ -46,7 +46,7 @@ describe('APM Transaction Duration Transform Generator', () => {
timesliceWindow: twoMinute(),
},
});
const transform = await generator.getTransformParams(slo, spaceId, dataViewsService);
const transform = await generator.getTransformParams(slo);

expect(transform).toMatchSnapshot();
});
Expand All @@ -60,7 +60,7 @@ describe('APM Transaction Duration Transform Generator', () => {
transactionType: ALL_VALUE,
}),
});
const transform = await generator.getTransformParams(slo, spaceId, dataViewsService);
const transform = await generator.getTransformParams(slo);

expect(transform.source.query).toMatchSnapshot();
});
Expand All @@ -72,7 +72,7 @@ describe('APM Transaction Duration Transform Generator', () => {
index,
}),
});
const transform = await generator.getTransformParams(slo, spaceId, dataViewsService);
const transform = await generator.getTransformParams(slo);

expect(transform.source.index).toEqual(index);
});
Expand All @@ -84,7 +84,7 @@ describe('APM Transaction Duration Transform Generator', () => {
filter,
}),
});
const transform = await generator.getTransformParams(slo, spaceId, dataViewsService);
const transform = await generator.getTransformParams(slo);

expect(transform.source.query).toMatchSnapshot();
});
Expand All @@ -99,7 +99,7 @@ describe('APM Transaction Duration Transform Generator', () => {
}),
});

const transform = await generator.getTransformParams(slo, spaceId, dataViewsService);
const transform = await generator.getTransformParams(slo);

expect(transform.source.query).toMatchSnapshot();
expect(transform.pivot?.group_by).toMatchSnapshot();
Expand All @@ -115,7 +115,7 @@ describe('APM Transaction Duration Transform Generator', () => {
}),
});

const transform = await generator.getTransformParams(slo, spaceId, dataViewsService);
const transform = await generator.getTransformParams(slo);

expect(transform.source.query).toMatchSnapshot();
expect(transform.pivot?.group_by).toMatchSnapshot();
Expand All @@ -131,7 +131,7 @@ describe('APM Transaction Duration Transform Generator', () => {
}),
});

const transform = await generator.getTransformParams(slo, spaceId, dataViewsService);
const transform = await generator.getTransformParams(slo);

expect(transform.source.query).toMatchSnapshot();
expect(transform.pivot?.group_by).toMatchSnapshot();
Expand All @@ -147,7 +147,7 @@ describe('APM Transaction Duration Transform Generator', () => {
}),
});

const transform = await generator.getTransformParams(slo, spaceId, dataViewsService);
const transform = await generator.getTransformParams(slo);

expect(transform.source.query).toMatchSnapshot();
expect(transform.pivot?.group_by).toMatchSnapshot();
Expand All @@ -163,7 +163,7 @@ describe('APM Transaction Duration Transform Generator', () => {
},
});

const transform = await generator.getTransformParams(slo, spaceId, dataViewsService);
const transform = await generator.getTransformParams(slo);

// @ts-ignore
const rangeFilter = transform.source.query.bool.filter.find((f) => 'range' in f);
Expand Down
Loading

0 comments on commit f8217ef

Please sign in to comment.