Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logs onboarding] Removing custom_logs from routes and making them more generic #162706

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,9 @@
},
"observability-onboarding-state": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be useful to rename this observability-onboarding-state to observability-onboarding-flow to match the new pattern for routes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to rename the savedObject but got the following error
Removing mapped properties is disallowed >8.8

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok...well it's more of a cosmetic thing i guess. i figured now would be the time since it's technically still not released yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not released to serverless yet but I believe modifying the name of a saved object will trigger a more expensive migration that affects customers. This is mainly a problem for heavy users of cases and/or alerts. CC @gsoldevila

That being said, I think it'd be good to get some "practice" of what it'd be like to be running a live service so I agree with the decision to rather forgo the cosmetic change :)

"properties": {
"type": {
"type": "keyword"
},
"state": {
"type": "object",
"dynamic": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"ml-module": "2225cbb4bd508ea5f69db4b848be9d8a74b60198",
"ml-trained-model": "482195cefd6b04920e539d34d7356d22cb68e4f3",
"monitoring-telemetry": "5d91bf75787d9d4dd2fae954d0b3f76d33d2e559",
"observability-onboarding-state": "55b112d6a33fedb7c1e4fec4da768d2bcc5fadc2",
"observability-onboarding-state": "c18631f47a0da568f12f859c9ab9d4ca73bdff7c",
"osquery-manager-usage-metric": "983bcbc3b7dda0aad29b20907db233abba709bcc",
"osquery-pack": "6ab4358ca4304a12dcfc1777c8135b75cffb4397",
"osquery-pack-asset": "b14101d3172c4b60eb5404696881ce5275c84152",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ updateStepProgress() {
local STATUS="$2" # "incomplete" | "complete" | "disabled" | "loading" | "warning" | "danger" | "current"
local MESSAGE=${3:-}
curl --request POST \
--url "${API_ENDPOINT}/custom_logs/${ONBOARDING_ID}/step/${STEPNAME}" \
--url "${API_ENDPOINT}/flow/${ONBOARDING_ID}/step/${STEPNAME}" \
--header "Authorization: ApiKey ${API_KEY_ENCODED}" \
--header "Content-Type: application/json" \
--header "kbn-xsrf: true" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import React from 'react';
import { APIReturnType } from '../../../../services/rest/create_call_api';

type ApiKeyPayload =
APIReturnType<'POST /internal/observability_onboarding/custom_logs/save'>;
APIReturnType<'POST /internal/observability_onboarding/logs/flow'>;

export type HasPrivileges = boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function InstallElasticAgent() {
(callApi) => {
if (!hasAlreadySavedFlow(getState())) {
return callApi(
'GET /internal/observability_onboarding/custom_logs/privileges'
'GET /internal/observability_onboarding/logs/setup/privileges'
);
}
},
Expand All @@ -69,7 +69,7 @@ export function InstallElasticAgent() {

const { data: setup } = useFetcher((callApi) => {
return callApi(
'GET /internal/observability_onboarding/custom_logs/install_shipper_setup'
'GET /internal/observability_onboarding/logs/setup/environment'
);
}, []);

Expand All @@ -87,23 +87,20 @@ export function InstallElasticAgent() {
logFilePaths,
} = getState();
if (!hasAlreadySavedFlow(getState()) && monitoringRole?.hasPrivileges) {
return callApi(
'POST /internal/observability_onboarding/custom_logs/save',
{
params: {
body: {
name: datasetName,
state: {
datasetName,
serviceName,
namespace,
customConfigurations,
logFilePaths,
},
return callApi('POST /internal/observability_onboarding/logs/flow', {
params: {
body: {
name: datasetName,
state: {
datasetName,
serviceName,
namespace,
customConfigurations,
logFilePaths,
},
},
}
);
},
});
}
},
[monitoringRole?.hasPrivileges]
Expand All @@ -120,7 +117,7 @@ export function InstallElasticAgent() {
} = getState();
if (onboardingId) {
return callApi(
'PUT /internal/observability_onboarding/custom_logs/{onboardingId}/save',
'PUT /internal/observability_onboarding/flow/{onboardingId}',
{
params: {
path: { onboardingId },
Expand Down Expand Up @@ -173,7 +170,7 @@ export function InstallElasticAgent() {
(callApi) => {
if (onboardingId) {
return callApi(
'GET /internal/observability_onboarding/custom_logs/{onboardingId}/progress',
'GET /internal/observability_onboarding/flow/{onboardingId}/progress',
{ params: { path: { onboardingId } } }
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { CoreStart } from '@kbn/core/server';
import { EsLegacyConfigService } from '../../services/es_legacy_config_service';
import { EsLegacyConfigService } from '../services/es_legacy_config_service';

export function getFallbackKibanaUrl({ http }: CoreStart) {
const basePath = http.basePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

import { SavedObjectsClientContract } from '@kbn/core/server';
import {
ObservabilityOnboardingFlow,
OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE,
ObservabilityOnboardingState,
SavedObservabilityOnboardingState,
SavedObservabilityOnboardingFlow,
} from '../../saved_objects/observability_onboarding_status';

export async function getObservabilityOnboardingState({
export async function getObservabilityOnboardingFlow({
savedObjectsClient,
savedObjectId,
}: {
savedObjectsClient: SavedObjectsClientContract;
savedObjectId: string;
}): Promise<SavedObservabilityOnboardingState | undefined> {
}): Promise<SavedObservabilityOnboardingFlow | undefined> {
try {
const result = await savedObjectsClient.get<ObservabilityOnboardingState>(
const result = await savedObjectsClient.get<ObservabilityOnboardingFlow>(
OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE,
savedObjectId
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './get_observability_onboarding_flow';
export * from './save_observability_onboarding_flow';
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,36 @@
import { SavedObjectsClientContract, SavedObject } from '@kbn/core/server';
import {
OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE,
ObservabilityOnboardingState,
SavedObservabilityOnboardingState,
ObservabilityOnboardingFlow,
SavedObservabilityOnboardingFlow,
} from '../../saved_objects/observability_onboarding_status';

interface Options {
savedObjectsClient: SavedObjectsClientContract;
observabilityOnboardingState: ObservabilityOnboardingState;
observabilityOnboardingState: ObservabilityOnboardingFlow;
savedObjectId?: string;
}
export async function saveObservabilityOnboardingState({
export async function saveObservabilityOnboardingFlow({
savedObjectsClient,
observabilityOnboardingState,
savedObjectId,
}: Options): Promise<SavedObservabilityOnboardingState> {
}: Options): Promise<SavedObservabilityOnboardingFlow> {
let savedObject: Omit<
SavedObject<ObservabilityOnboardingState>,
SavedObject<ObservabilityOnboardingFlow>,
'attributes' | 'references'
>;
if (savedObjectId) {
savedObject = await savedObjectsClient.update<ObservabilityOnboardingState>(
savedObject = await savedObjectsClient.update<ObservabilityOnboardingFlow>(
OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE,
savedObjectId,
{
type: observabilityOnboardingState.type,
state: observabilityOnboardingState.state,
progress: { ...observabilityOnboardingState.progress },
}
);
} else {
savedObject = await savedObjectsClient.create<ObservabilityOnboardingState>(
savedObject = await savedObjectsClient.create<ObservabilityOnboardingFlow>(
OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE,
observabilityOnboardingState
);
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/observability_onboarding/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
ObservabilityOnboardingPluginStartDependencies,
} from './types';
import { ObservabilityOnboardingConfig } from '.';
import { observabilityOnboardingState } from './saved_objects/observability_onboarding_status';
import { observabilityOnboardingFlow } from './saved_objects/observability_onboarding_status';
import { EsLegacyConfigService } from './services/es_legacy_config_service';

export class ObservabilityOnboardingPlugin
Expand Down Expand Up @@ -52,7 +52,7 @@ export class ObservabilityOnboardingPlugin
this.logger.debug('observability_onboarding: Setup');
this.esLegacyConfigService.setup(core.elasticsearch.legacy.config$);

core.savedObjects.registerType(observabilityOnboardingState);
core.savedObjects.registerType(observabilityOnboardingFlow);

const resourcePlugins = mapValues(plugins, (value, key) => {
return {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import * as t from 'io-ts';
import { getAuthenticationAPIKey } from '../../lib/get_authentication_api_key';
import { createObservabilityOnboardingServerRoute } from '../create_observability_onboarding_server_route';
import { getObservabilityOnboardingState } from '../custom_logs/get_observability_onboarding_state';
import { generateYml } from './generate_yml';
import { getFallbackESUrl } from '../custom_logs/get_fallback_urls';
import { getFallbackESUrl } from '../../lib/get_fallback_urls';
import { getObservabilityOnboardingFlow } from '../../lib/state';

const generateConfig = createObservabilityOnboardingServerRoute({
endpoint: 'GET /internal/observability_onboarding/elastic_agent/config',
Expand Down Expand Up @@ -38,22 +38,22 @@ const generateConfig = createObservabilityOnboardingServerRoute({
? [plugins.cloud?.setup?.elasticsearchUrl]
: await getFallbackESUrl(esLegacyConfigService);

const savedState = await getObservabilityOnboardingState({
const savedState = await getObservabilityOnboardingFlow({
savedObjectsClient,
savedObjectId: onboardingId,
});

const yaml = generateYml({
datasetName: savedState?.state.datasetName,
customConfigurations: savedState?.state.customConfigurations,
logFilePaths: savedState?.state.logFilePaths,
namespace: savedState?.state.namespace,
datasetName: savedState?.state?.datasetName,
customConfigurations: savedState?.state?.customConfigurations,
logFilePaths: savedState?.state?.logFilePaths,
namespace: savedState?.state?.namespace,
apiKey: authApiKey
? `${authApiKey?.apiKeyId}:${authApiKey?.apiKey}`
: '$API_KEY',
esHost: elasticsearchUrl,
logfileId: `custom-logs-${Date.now()}`,
serviceName: savedState?.state.serviceName,
serviceName: savedState?.state?.serviceName,
});

return yaml;
Expand Down
Loading
Loading