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

[Ingest Manager] Support for multiple kibana urls #75710

Closed
Closed
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 @@ -20,5 +20,4 @@ export interface SavedObjectsBulkCreateObject<T = unknown>
| [migrationVersion](./kibana-plugin-core-server.savedobjectsbulkcreateobject.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. |
| [references](./kibana-plugin-core-server.savedobjectsbulkcreateobject.references.md) | <code>SavedObjectReference[]</code> | |
| [type](./kibana-plugin-core-server.savedobjectsbulkcreateobject.type.md) | <code>string</code> | |
| [version](./kibana-plugin-core-server.savedobjectsbulkcreateobject.version.md) | <code>string</code> | |

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions
| [overwrite](./kibana-plugin-core-server.savedobjectscreateoptions.overwrite.md) | <code>boolean</code> | Overwrite existing documents (defaults to false) |
| [references](./kibana-plugin-core-server.savedobjectscreateoptions.references.md) | <code>SavedObjectReference[]</code> | |
| [refresh](./kibana-plugin-core-server.savedobjectscreateoptions.refresh.md) | <code>MutatingOperationRefreshSetting</code> | The Elasticsearch Refresh setting for this operation |
| [version](./kibana-plugin-core-server.savedobjectscreateoptions.version.md) | <code>string</code> | An opaque version number which changes on each successful write operation. Can be used in conjunction with <code>overwrite</code> for implementing optimistic concurrency control. |

This file was deleted.

7 changes: 1 addition & 6 deletions src/core/server/saved_objects/import/import_saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
SavedObjectsImportOptions,
} from './types';
import { validateReferences } from './validate_references';
import { SavedObject } from '../types';

/**
* Import saved objects from given stream. See the {@link SavedObjectsImportOptions | options} for more
Expand Down Expand Up @@ -68,7 +67,7 @@ export async function importSavedObjectsFromStream({
}

// Create objects in bulk
const bulkCreateResult = await savedObjectsClient.bulkCreate(omitVersion(filteredObjects), {
const bulkCreateResult = await savedObjectsClient.bulkCreate(filteredObjects, {
overwrite,
namespace,
});
Expand All @@ -83,7 +82,3 @@ export async function importSavedObjectsFromStream({
...(errorAccumulator.length ? { errors: errorAccumulator } : {}),
};
}

export function omitVersion(objects: SavedObject[]): SavedObject[] {
return objects.map(({ version, ...object }) => object);
}
12 changes: 4 additions & 8 deletions src/core/server/saved_objects/import/resolve_import_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
SavedObjectsResolveImportErrorsOptions,
} from './types';
import { validateReferences } from './validate_references';
import { omitVersion } from './import_saved_objects';

/**
* Resolve and return saved object import errors.
Expand Down Expand Up @@ -92,7 +91,7 @@ export async function resolveSavedObjectsImportErrors({
// Bulk create in two batches, overwrites and non-overwrites
const { objectsToOverwrite, objectsToNotOverwrite } = splitOverwrites(filteredObjects, retries);
if (objectsToOverwrite.length) {
const bulkCreateResult = await savedObjectsClient.bulkCreate(omitVersion(objectsToOverwrite), {
const bulkCreateResult = await savedObjectsClient.bulkCreate(objectsToOverwrite, {
overwrite: true,
namespace,
});
Expand All @@ -103,12 +102,9 @@ export async function resolveSavedObjectsImportErrors({
successCount += bulkCreateResult.saved_objects.filter((obj) => !obj.error).length;
}
if (objectsToNotOverwrite.length) {
const bulkCreateResult = await savedObjectsClient.bulkCreate(
omitVersion(objectsToNotOverwrite),
{
namespace,
}
);
const bulkCreateResult = await savedObjectsClient.bulkCreate(objectsToNotOverwrite, {
namespace,
});
errorAccumulator = [
...errorAccumulator,
...extractErrors(bulkCreateResult.saved_objects, objectsToNotOverwrite),
Expand Down
43 changes: 2 additions & 41 deletions src/core/server/saved_objects/service/lib/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,8 @@ describe('SavedObjectsRepository', () => {
{ method, _index = expect.any(String), getId = () => expect.any(String) }
) => {
const body = [];
for (const { type, id, if_primary_term: ifPrimaryTerm, if_seq_no: ifSeqNo } of objects) {
body.push({
[method]: {
_index,
_id: getId(type, id),
...(ifPrimaryTerm && ifSeqNo
? { if_primary_term: expect.any(Number), if_seq_no: expect.any(Number) }
: {}),
},
});
for (const { type, id } of objects) {
body.push({ [method]: { _index, _id: getId(type, id) } });
body.push(expect.any(Object));
}
expect(client.bulk).toHaveBeenCalledWith(
Expand Down Expand Up @@ -533,27 +525,6 @@ describe('SavedObjectsRepository', () => {
expectClientCallArgsAction([obj1, obj2], { method: 'index' });
});

it(`should use the ES index method with version if ID and version are defined and overwrite=true`, async () => {
await bulkCreateSuccess(
[
{
...obj1,
version: mockVersion,
},
obj2,
],
{ overwrite: true }
);

const obj1WithSeq = {
...obj1,
if_seq_no: mockVersionProps._seq_no,
if_primary_term: mockVersionProps._primary_term,
};

expectClientCallArgsAction([obj1WithSeq, obj2], { method: 'index' });
});

it(`should use the ES create method if ID is defined and overwrite=false`, async () => {
await bulkCreateSuccess([obj1, obj2]);
expectClientCallArgsAction([obj1, obj2], { method: 'create' });
Expand Down Expand Up @@ -1545,16 +1516,6 @@ describe('SavedObjectsRepository', () => {
expect(client.index).toHaveBeenCalled();
});

it(`should use the ES index with version if ID and version are defined and overwrite=true`, async () => {
await createSuccess(type, attributes, { id, overwrite: true, version: mockVersion });
expect(client.index).toHaveBeenCalled();

expect(client.index.mock.calls[0][0]).toMatchObject({
if_seq_no: mockVersionProps._seq_no,
if_primary_term: mockVersionProps._primary_term,
});
});

it(`should use the ES create action if ID is defined and overwrite=false`, async () => {
await createSuccess(type, attributes, { id });
expect(client.create).toHaveBeenCalled();
Expand Down
12 changes: 1 addition & 11 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ export class SavedObjectsRepository {
overwrite = false,
references = [],
refresh = DEFAULT_REFRESH_SETTING,
version,
} = options;

if (!this._allowedTypes.includes(type)) {
Expand Down Expand Up @@ -262,7 +261,6 @@ export class SavedObjectsRepository {
index: this.getIndexForType(type),
refresh,
body: raw._source,
...(overwrite && version ? decodeRequestVersion(version) : {}),
};

const { body } =
Expand Down Expand Up @@ -349,12 +347,7 @@ export class SavedObjectsRepository {

let savedObjectNamespace;
let savedObjectNamespaces;
let versionProperties;
const {
esRequestIndex,
object: { version, ...object },
method,
} = expectedBulkGetResult.value;
const { esRequestIndex, object, method } = expectedBulkGetResult.value;
if (esRequestIndex !== undefined) {
const indexFound = bulkGetResponse?.statusCode !== 404;
const actualResult = indexFound ? bulkGetResponse?.body.docs[esRequestIndex] : undefined;
Expand All @@ -371,14 +364,12 @@ export class SavedObjectsRepository {
};
}
savedObjectNamespaces = getSavedObjectNamespaces(namespace, docFound && actualResult);
versionProperties = getExpectedVersionProperties(version, actualResult);
} else {
if (this._registry.isSingleNamespace(object.type)) {
savedObjectNamespace = namespace;
} else if (this._registry.isMultiNamespace(object.type)) {
savedObjectNamespaces = getSavedObjectNamespaces(namespace);
}
versionProperties = getExpectedVersionProperties(version);
}

const expectedResult = {
Expand All @@ -403,7 +394,6 @@ export class SavedObjectsRepository {
[method]: {
_id: expectedResult.rawMigratedDoc._id,
_index: this.getIndexForType(object.type),
...(overwrite && versionProperties),
},
},
expectedResult.rawMigratedDoc._source
Expand Down
6 changes: 0 additions & 6 deletions src/core/server/saved_objects/service/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions {
id?: string;
/** Overwrite existing documents (defaults to false) */
overwrite?: boolean;
/**
* An opaque version number which changes on each successful write operation.
* Can be used in conjunction with `overwrite` for implementing optimistic concurrency control.
**/
version?: string;
/** {@inheritDoc SavedObjectsMigrationVersion} */
migrationVersion?: SavedObjectsMigrationVersion;
references?: SavedObjectReference[];
Expand All @@ -57,7 +52,6 @@ export interface SavedObjectsBulkCreateObject<T = unknown> {
id?: string;
type: string;
attributes: T;
version?: string;
references?: SavedObjectReference[];
/** {@inheritDoc SavedObjectsMigrationVersion} */
migrationVersion?: SavedObjectsMigrationVersion;
Expand Down
3 changes: 0 additions & 3 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2050,8 +2050,6 @@ export interface SavedObjectsBulkCreateObject<T = unknown> {
references?: SavedObjectReference[];
// (undocumented)
type: string;
// (undocumented)
version?: string;
}

// @public (undocumented)
Expand Down Expand Up @@ -2186,7 +2184,6 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions {
// (undocumented)
references?: SavedObjectReference[];
refresh?: MutatingOperationRefreshSetting;
version?: string;
}

// @public (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function createInstallRoute(
let createResults;
try {
createResults = await context.core.savedObjects.client.bulkCreate(
sampleDataset.savedObjects.map(({ version, ...savedObject }) => savedObject),
sampleDataset.savedObjects,
{ overwrite: true }
);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_manager/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface IngestManagerConfigType {
pollingRequestTimeout: number;
maxConcurrentConnections: number;
kibana: {
host?: string;
host?: string[] | string;
ca_sha256?: string;
};
elasticsearch: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SavedObjectAttributes } from 'src/core/public';
interface BaseSettings {
agent_auto_upgrade?: boolean;
package_auto_upgrade?: boolean;
kibana_url?: string;
kibana_url?: string[];
kibana_ca_sha256?: string;
has_seen_add_data_notice?: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { EnrollmentAPIKey } from '../../../types';

interface Props {
kibanaUrl: string;
kibanaUrl: string[];
apiKey: EnrollmentAPIKey;
kibanaCASha256?: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ import {
EuiFlyoutFooter,
EuiForm,
EuiFormRow,
EuiFieldText,
EuiRadioGroup,
EuiComboBox,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiText } from '@elastic/eui';
import { useInput, useComboInput, useCore, useGetSettings, sendPutSettings } from '../hooks';
import { useComboInput, useCore, useGetSettings, sendPutSettings } from '../hooks';
import { useGetOutputs, sendPutOutput } from '../hooks/use_request/outputs';

const URL_REGEX = /^(https?):\/\/[^\s$.?#].[^\s]*$/gm;
Expand All @@ -36,14 +35,21 @@ interface Props {
function useSettingsForm(outputId: string | undefined, onSuccess: () => void) {
const [isLoading, setIsloading] = React.useState(false);
const { notifications } = useCore();
const kibanaUrlInput = useInput('', (value) => {
if (!value.match(URL_REGEX)) {
const kibanaUrlInput = useComboInput([], (value) => {
if (value.some((v) => !v.match(URL_REGEX))) {
return [
i18n.translate('xpack.ingestManager.settings.kibanaUrlError', {
defaultMessage: 'Invalid URL',
}),
];
}
if (value.length === 0) {
return [
i18n.translate('xpack.ingestManager.settings.kibanaUrlEmptyError', {
defaultMessage: 'At least one URL is required',
}),
];
}
});
const elasticsearchUrlInput = useComboInput([], (value) => {
if (value.some((v) => !v.match(URL_REGEX))) {
Expand Down Expand Up @@ -118,7 +124,7 @@ export const SettingFlyout: React.FunctionComponent<Props> = ({ onClose }) => {
useEffect(() => {
if (settings) {
inputs.kibanaUrl.setValue(
settings.kibana_url || `${window.location.origin}${core.http.basePath.get()}`
settings.kibana_url || [`${window.location.origin}${core.http.basePath.get()}`]
);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down Expand Up @@ -222,7 +228,7 @@ export const SettingFlyout: React.FunctionComponent<Props> = ({ onClose }) => {
})}
{...inputs.kibanaUrl.formRowProps}
>
<EuiFieldText required={true} {...inputs.kibanaUrl.props} name="kibanaUrl" />
<EuiComboBox noSuggestions {...inputs.kibanaUrl.props} />
</EuiFormRow>
</EuiFormRow>
<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ export const ManagedInstructions: React.FunctionComponent<Props> = ({ agentPolic
const settings = useGetSettings();
const apiKey = useGetOneEnrollmentAPIKey(selectedAPIKeyId);

const kibanaUrl =
settings.data?.item?.kibana_url ?? `${window.location.origin}${core.http.basePath.get()}`;
const kibanaUrl = settings.data?.item?.kibana_url ?? [
`${window.location.origin}${core.http.basePath.get()}`,
];
const kibanaCASha256 = settings.data?.item?.kibana_ca_sha256;

const steps: EuiContainedStepProps[] = [
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/ingest_manager/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export const config = {
pollingRequestTimeout: schema.number({ defaultValue: 60000 }),
maxConcurrentConnections: schema.number({ defaultValue: 0 }),
kibana: schema.object({
host: schema.maybe(schema.string()),
host: schema.maybe(
schema.oneOf([
schema.uri({ scheme: ['http', 'https'] }),
schema.arrayOf(schema.uri({ scheme: ['http', 'https'] }), { minSize: 1 }),
])
),
ca_sha256: schema.maybe(schema.string()),
}),
elasticsearch: schema.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export const registerRoutes = ({
const http = appContextService.getHttpSetup();
const serverInfo = http.getServerInfo();
const basePath = http.basePath;
const kibanaUrl =
(await settingsService.getSettings(soClient)).kibana_url ||
const kibanaUrl = (await settingsService.getSettings(soClient)).kibana_url || [
url.format({
protocol: serverInfo.protocol,
hostname: serverInfo.hostname,
port: serverInfo.port,
pathname: basePath.serverBasePath,
});
}),
];

const script = getScript(request.params.osType, kibanaUrl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import * as Registry from '../../registry';
import { AssetType, KibanaAssetType, AssetReference } from '../../../../types';
import { savedObjectTypes } from '../../packages';

type SavedObjectToBe = Required<Omit<SavedObjectsBulkCreateObject, 'version'>> & {
type: AssetType;
};
type SavedObjectToBe = Required<SavedObjectsBulkCreateObject> & { type: AssetType };
export type ArchiveAsset = Pick<
SavedObject,
'id' | 'attributes' | 'migrationVersion' | 'references'
Expand Down
Loading