Skip to content

Commit

Permalink
fix(slo): use spaceId for pipeline names (#141133)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme authored Sep 20, 2022
1 parent a956266 commit ab0e2fb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 20 deletions.
8 changes: 5 additions & 3 deletions x-pack/plugins/observability/server/assets/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* 2.0.
*/

export const SLO_COMPONENT_TEMPLATE_MAPPINGS_NAME = 'observability-slo-mappings';
export const SLO_COMPONENT_TEMPLATE_SETTINGS_NAME = 'observability-slo-settings';
export const SLO_COMPONENT_TEMPLATE_MAPPINGS_NAME = 'slo-observability.sli-mappings';
export const SLO_COMPONENT_TEMPLATE_SETTINGS_NAME = 'slo-observability.sli-settings';
export const SLO_INDEX_TEMPLATE_NAME = 'slo-observability.sli';
export const SLO_INGEST_PIPELINE_NAME = 'observability-slo-monthly-index';
export const SLO_RESOURCES_VERSION = 1;

export const getSLOIngestPipelineName = (spaceId: string) =>
`${SLO_INDEX_TEMPLATE_NAME}.monthly-${spaceId}`;

export const getSLODestinationIndexName = (spaceId: string) =>
`${SLO_INDEX_TEMPLATE_NAME}-v${SLO_RESOURCES_VERSION}-${spaceId}`;

Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/observability/server/routes/register_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export function registerRoutes({
spacesService,
})) as any;

if (data === undefined) {
return response.noContent();
}

return response.ok({ body: data });
} catch (error) {
if (error instanceof ObservabilityError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import { IngestGetPipelineResponse } from '@elastic/elasticsearch/lib/api/typesW
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
import { loggerMock } from '@kbn/logging-mocks';
import {
getSLOIngestPipelineName,
SLO_COMPONENT_TEMPLATE_MAPPINGS_NAME,
SLO_COMPONENT_TEMPLATE_SETTINGS_NAME,
SLO_INDEX_TEMPLATE_NAME,
SLO_INGEST_PIPELINE_NAME,
SLO_RESOURCES_VERSION,
} from '../../assets/constants';
import { DefaultResourceInstaller } from './resource_installer';

const SPACE_ID = 'space-id';
describe('resourceInstaller', () => {
describe("when the common resources don't exist", () => {
it('installs the common resources', async () => {
Expand All @@ -25,7 +26,7 @@ describe('resourceInstaller', () => {
const installer = new DefaultResourceInstaller(
mockClusterClient,
loggerMock.create(),
'space-id'
SPACE_ID
);

await installer.ensureCommonResourcesInstalled();
Expand All @@ -43,7 +44,7 @@ describe('resourceInstaller', () => {
expect.objectContaining({ name: SLO_INDEX_TEMPLATE_NAME })
);
expect(mockClusterClient.ingest.putPipeline).toHaveBeenCalledWith(
expect.objectContaining({ id: SLO_INGEST_PIPELINE_NAME })
expect.objectContaining({ id: getSLOIngestPipelineName(SPACE_ID) })
);
});
});
Expand All @@ -53,12 +54,13 @@ describe('resourceInstaller', () => {
const mockClusterClient = elasticsearchServiceMock.createElasticsearchClient();
mockClusterClient.indices.existsIndexTemplate.mockResponseOnce(true);
mockClusterClient.ingest.getPipeline.mockResponseOnce({
[SLO_INGEST_PIPELINE_NAME]: { _meta: { version: SLO_RESOURCES_VERSION } },
// @ts-ignore _meta not typed properly
[getSLOIngestPipelineName(SPACE_ID)]: { _meta: { version: SLO_RESOURCES_VERSION } },
} as IngestGetPipelineResponse);
const installer = new DefaultResourceInstaller(
mockClusterClient,
loggerMock.create(),
'space-id'
SPACE_ID
);

await installer.ensureCommonResourcesInstalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import type {
import type { ElasticsearchClient, Logger } from '@kbn/core/server';

import {
getSLOIngestPipelineName,
SLO_COMPONENT_TEMPLATE_MAPPINGS_NAME,
SLO_COMPONENT_TEMPLATE_SETTINGS_NAME,
SLO_INDEX_TEMPLATE_NAME,
SLO_INGEST_PIPELINE_NAME,
SLO_RESOURCES_VERSION,
} from '../../assets/constants';
import { getSLOMappingsTemplate } from '../../assets/component_templates/slo_mappings_template';
Expand Down Expand Up @@ -64,7 +64,7 @@ export class DefaultResourceInstaller implements ResourceInstaller {

await this.createOrUpdateIngestPipelineTemplate(
getSLOPipelineTemplate(
SLO_INGEST_PIPELINE_NAME,
getSLOIngestPipelineName(this.spaceId),
this.getPipelinePrefix(SLO_RESOURCES_VERSION, this.spaceId)
)
);
Expand All @@ -87,13 +87,12 @@ export class DefaultResourceInstaller implements ResourceInstaller {

let ingestPipelineExists = false;
try {
const pipeline = await this.esClient.ingest.getPipeline({
id: SLO_INGEST_PIPELINE_NAME,
});
const pipelineName = getSLOIngestPipelineName(this.spaceId);
const pipeline = await this.esClient.ingest.getPipeline({ id: pipelineName });

ingestPipelineExists =
// @ts-ignore _meta is not defined on the type
pipeline && pipeline[SLO_INGEST_PIPELINE_NAME]._meta.version === SLO_RESOURCES_VERSION;
pipeline && pipeline[pipelineName]._meta.version === SLO_RESOURCES_VERSION;
} catch (err) {
return false;
}
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 @@ -12,8 +12,8 @@ import {
} from '@elastic/elasticsearch/lib/api/types';
import {
getSLODestinationIndexName,
getSLOIngestPipelineName,
getSLOTransformId,
SLO_INGEST_PIPELINE_NAME,
} from '../../../assets/constants';
import { getSLOTransformTemplate } from '../../../assets/transform_templates/slo_transform_template';
import {
Expand Down Expand Up @@ -106,7 +106,7 @@ export class ApmTransactionDurationTransformGenerator implements TransformGenera

private buildDestination(slo: APMTransactionDurationSLO, spaceId: string) {
return {
pipeline: SLO_INGEST_PIPELINE_NAME,
pipeline: getSLOIngestPipelineName(spaceId),
index: getSLODestinationIndexName(spaceId),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { getSLOTransformTemplate } from '../../../assets/transform_templates/slo
import { TransformGenerator } from '.';
import {
getSLODestinationIndexName,
getSLOIngestPipelineName,
getSLOTransformId,
SLO_INGEST_PIPELINE_NAME,
} from '../../../assets/constants';
import {
apmTransactionErrorRateSLOSchema,
Expand Down Expand Up @@ -108,7 +108,7 @@ export class ApmTransactionErrorRateTransformGenerator implements TransformGener

private buildDestination(slo: APMTransactionErrorRateSLO, spaceId: string) {
return {
pipeline: SLO_INGEST_PIPELINE_NAME,
pipeline: getSLOIngestPipelineName(spaceId),
index: getSLODestinationIndexName(spaceId),
};
}
Expand Down

0 comments on commit ab0e2fb

Please sign in to comment.