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

[Inventory] Inventory plugin #191798

Merged
merged 35 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
eb7569e
[Inventory] Inventory plugin
dgieselaar Jul 18, 2024
570f78d
Extract datasets
dgieselaar Aug 1, 2024
f5727e8
Disable inventory plugin by default
dgieselaar Aug 30, 2024
88cefe5
Fix types
dgieselaar Aug 30, 2024
e53b3b3
Disable by default
dgieselaar Aug 30, 2024
fe471af
Fix lint errors & CODEOWNERS
dgieselaar Aug 30, 2024
bc0b98c
Update codeowners via kibana.jsonc
dgieselaar Aug 30, 2024
f49bdac
Use right team
dgieselaar Aug 30, 2024
4336608
Add limits
dgieselaar Aug 30, 2024
e4bb64d
Separate repository client in fetch/stream
dgieselaar Aug 30, 2024
a709bec
Merge branch 'main' of github.com:elastic/kibana into inventory-plugin
dgieselaar Aug 30, 2024
cad3bb3
Update README
dgieselaar Aug 31, 2024
745b9da
Merge branch 'main' of github.com:elastic/kibana into inventory-plugin
dgieselaar Aug 31, 2024
ab9f8f9
Use KibanaRenderContextProvider
dgieselaar Aug 31, 2024
296ed2a
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Aug 31, 2024
8dddf03
Fix types & tests
dgieselaar Aug 31, 2024
21003d7
Fix APM E2E test
dgieselaar Sep 1, 2024
b46a785
Fix bug in SSE formatting
dgieselaar Sep 2, 2024
b2fe459
Merge branch 'main' of github.com:elastic/kibana into inventory-plugin
dgieselaar Sep 2, 2024
171a8df
Merge branch 'main' of github.com:elastic/kibana into inventory-plugin
dgieselaar Sep 9, 2024
2f22a5d
Remove AI work
dgieselaar Sep 9, 2024
d73d1e5
Update CODEOWNERS
dgieselaar Sep 9, 2024
a4e7b65
Update CODEOWNERS
dgieselaar Sep 9, 2024
cd20fc0
[CI] Auto-commit changed files from 'node scripts/lint_packages --fix'
kibanamachine Sep 9, 2024
a61864e
Add back changes to menu
dgieselaar Sep 9, 2024
2c39d89
Merge branch 'inventory-plugin' of github.com:dgieselaar/kibana into …
dgieselaar Sep 9, 2024
70b0742
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 9, 2024
ae4e035
Resolve merge conflict correctly
dgieselaar Sep 9, 2024
0b94e16
Fix tests
dgieselaar Sep 10, 2024
0238a8c
Fix type issues in routes
dgieselaar Sep 10, 2024
87b8924
Allow primitives as return types
dgieselaar Sep 10, 2024
4670089
Merge branch 'main' of github.com:elastic/kibana into inventory-plugin
dgieselaar Sep 10, 2024
6370430
Allow any as a value
dgieselaar Sep 11, 2024
a039dae
Update README.md
dgieselaar Sep 11, 2024
62e3ed0
[CI] Auto-commit changed files from 'node scripts/lint_packages --fix'
kibanamachine Sep 11, 2024
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
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ packages/deeplinks/devtools @elastic/kibana-management
packages/deeplinks/fleet @elastic/fleet
packages/deeplinks/management @elastic/kibana-management
packages/deeplinks/ml @elastic/ml-ui
packages/deeplinks/observability @elastic/obs-ux-logs-team
packages/deeplinks/observability @elastic/obs-ux-management
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
packages/deeplinks/observability @elastic/obs-ux-management
packages/deeplinks/observability @elastic/obs-ux-management-team

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks!

packages/deeplinks/search @elastic/search-kibana
packages/deeplinks/security @elastic/security-solution
packages/deeplinks/shared @elastic/appex-sharedux
Expand Down Expand Up @@ -522,6 +522,7 @@ x-pack/plugins/integration_assistant @elastic/security-scalability
src/plugins/interactive_setup @elastic/kibana-security
test/interactive_setup_api_integration/plugins/test_endpoints @elastic/kibana-security
packages/kbn-interpreter @elastic/kibana-visualizations
x-pack/plugins/observability_solution/inventory @elastic/obs-ai-assistant
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
x-pack/plugins/observability_solution/inventory @elastic/obs-ai-assistant
x-pack/plugins/observability_solution/inventory @elastic/obs-ux-infra_services

Copy link
Member Author

Choose a reason for hiding this comment

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

cheers, will update this in the kibana.jsonc file

x-pack/plugins/observability_solution/investigate_app @elastic/obs-ux-management-team
x-pack/plugins/observability_solution/investigate @elastic/obs-ux-management-team
packages/kbn-investigation-shared @elastic/obs-ux-management-team
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,10 @@ the infrastructure monitoring use-case within Kibana.
|Team owner: Security Integrations Scalability


|{kib-repo}blob/{branch}/x-pack/plugins/observability_solution/inventory/README.md[inventory]
|undefined


|{kib-repo}blob/{branch}/x-pack/plugins/observability_solution/investigate/README.md[investigate]
|undefined

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@
"@kbn/interactive-setup-plugin": "link:src/plugins/interactive_setup",
"@kbn/interactive-setup-test-endpoints-plugin": "link:test/interactive_setup_api_integration/plugins/test_endpoints",
"@kbn/interpreter": "link:packages/kbn-interpreter",
"@kbn/inventory-plugin": "link:x-pack/plugins/observability_solution/inventory",
"@kbn/investigate-app-plugin": "link:x-pack/plugins/observability_solution/investigate_app",
"@kbn/investigate-plugin": "link:x-pack/plugins/observability_solution/investigate",
"@kbn/investigation-shared": "link:packages/kbn-investigation-shared",
Expand Down
2 changes: 2 additions & 0 deletions packages/deeplinks/observability/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export const INVESTIGATE_APP_ID = 'investigate';
export const OBLT_UX_APP_ID = 'ux';

export const OBLT_PROFILING_APP_ID = 'profiling';

export const INVENTORY_APP_ID = 'inventory';
10 changes: 8 additions & 2 deletions packages/deeplinks/observability/deep_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
AI_ASSISTANT_APP_ID,
OBLT_UX_APP_ID,
OBLT_PROFILING_APP_ID,
INVENTORY_APP_ID,
} from './constants';

type LogsApp = typeof LOGS_APP_ID;
Expand All @@ -31,6 +32,7 @@ type SloApp = typeof SLO_APP_ID;
type AiAssistantApp = typeof AI_ASSISTANT_APP_ID;
type ObltUxApp = typeof OBLT_UX_APP_ID;
type ObltProfilingApp = typeof OBLT_PROFILING_APP_ID;
type InventoryApp = typeof INVENTORY_APP_ID;

export type AppId =
| LogsApp
Expand All @@ -43,10 +45,13 @@ export type AppId =
| SloApp
| AiAssistantApp
| ObltUxApp
| ObltProfilingApp;
| ObltProfilingApp
| InventoryApp;

export type LogsLinkId = 'log-categories' | 'settings' | 'anomalies' | 'stream';

export type InventoryLinkId = 'datastreams';

export type ObservabilityOverviewLinkId =
| 'alerts'
| 'cases'
Expand Down Expand Up @@ -89,4 +94,5 @@ export type DeepLinkId =
| `${MetricsApp}:${MetricsLinkId}`
| `${ApmApp}:${ApmLinkId}`
| `${SyntheticsApp}:${SyntheticsLinkId}`
| `${ObltProfilingApp}:${ProfilingLinkId}`;
| `${ObltProfilingApp}:${ProfilingLinkId}`
| `${InventoryApp}:${InventoryLinkId}`;
2 changes: 1 addition & 1 deletion packages/deeplinks/observability/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/deeplinks-observability",
"owner": "@elastic/obs-ux-logs-team"
"owner": "@elastic/obs-ux-management-team"
}
2 changes: 1 addition & 1 deletion packages/kbn-es-types/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export type SearchHit<
? {
fields: Partial<Record<ValueTypeOfField<TFields>, unknown[]>>;
}
: {}) &
: { fields?: Record<string, unknown[]> }) &
(TDocValueFields extends DocValueFields
? {
fields: Partial<Record<ValueTypeOfField<TDocValueFields>, unknown[]>>;
Expand Down
19 changes: 14 additions & 5 deletions packages/kbn-server-route-repository-utils/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
} from '@kbn/core/server';
import { z } from '@kbn/zod';
import * as t from 'io-ts';
import { Observable } from 'rxjs';
import { RequiredKeys } from 'utility-types';

type PathMaybeOptional<T extends { path: Record<string, any> }> = RequiredKeys<
Expand Down Expand Up @@ -195,21 +196,29 @@ type MaybeOptionalArgs<T extends Record<string, any>> = RequiredKeys<T> extends
export type RouteRepositoryClient<
TServerRouteRepository extends ServerRouteRepository,
TAdditionalClientOptions extends Record<string, any> = DefaultClientOptions
> = <TEndpoint extends Extract<keyof TServerRouteRepository, string>>(
> = <
TEndpoint extends Extract<keyof TServerRouteRepository, string>,
TAsEventSourceStreamOptions extends { asEventSourceStream?: boolean }
>(
endpoint: TEndpoint,
...args: MaybeOptionalArgs<
ClientRequestParamsOf<TServerRouteRepository, TEndpoint> & TAdditionalClientOptions
>
) => Promise<ReturnOf<TServerRouteRepository, TEndpoint>>;

export type DefaultClientOptions = HttpFetchOptions;
> &
([TAsEventSourceStreamOptions] | [])
) => TAsEventSourceStreamOptions extends { asEventSourceStream: boolean }
? ReturnOf<TServerRouteRepository, TEndpoint> extends Observable<infer TObservable>
? Observable<TObservable>
: Observable<unknown>
: Promise<ReturnOf<TServerRouteRepository, TEndpoint>>;
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved

interface CoreRouteHandlerResources {
request: KibanaRequest;
response: KibanaResponseFactory;
context: RequestHandlerContext;
}

export type DefaultClientOptions = HttpFetchOptions;

export interface DefaultRouteHandlerResources extends CoreRouteHandlerResources {
logger: Logger;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-server-route-repository-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"target/**/*"
],
"kbn_references": [
"@kbn/core-http-browser",
"@kbn/core-http-server",
"@kbn/core",
"@kbn/zod",
"@kbn/core-http-browser",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 { map, Observable } from 'rxjs';
import { PassThrough } from 'stream';

export function observableIntoEventSourceStream(source$: Observable<unknown>): PassThrough {
const withSerializedErrors$ = source$.pipe(
map((event) => {
return `data: ${JSON.stringify(event)}\n\n`;
})
);

const stream = new PassThrough();

withSerializedErrors$.subscribe({
next: (line) => {
stream.write(line);
},
complete: () => {
stream.end();
},
error: (error) => {
stream.write(`data: ${JSON.stringify(error)}\n\n`);
stream.end();
},
});

return stream;
}
4 changes: 4 additions & 0 deletions packages/kbn-server-route-repository/src/register_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import {
} from '@kbn/server-route-repository-utils';
import { isZod } from '@kbn/zod';
import { merge } from 'lodash';
import { isObservable } from 'rxjs';
import { passThroughValidationObject, noParamsValidationObject } from './validation_objects';
import { validateAndDecodeParams } from './validate_and_decode_params';
import { makeZodValidationObject } from './make_zod_validation_object';
import { observableIntoEventSourceStream } from './observable_into_event_source_stream';

const CLIENT_CLOSED_REQUEST = {
statusCode: 499,
Expand Down Expand Up @@ -88,6 +90,8 @@ export function registerRoutes<TDependencies extends Record<string, any>>({

if (isKibanaResponse(result)) {
return result;
} else if (isObservable(result)) {
return response.ok({ body: observableIntoEventSourceStream(result) });
} else {
const body = result || {};
return response.ok({ body });
Expand Down
25 changes: 21 additions & 4 deletions packages/kbn-server-route-repository/src/test_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as t from 'io-ts';
import { z } from '@kbn/zod';
import { kibanaResponseFactory } from '@kbn/core/server';
import { EndpointOf, ReturnOf, RouteRepositoryClient } from '@kbn/server-route-repository-utils';
import { Observable, of } from 'rxjs';
import { createServerRouteFactory } from './create_server_route_factory';
import { decodeRequestParams } from './decode_request_params';

Expand Down Expand Up @@ -199,6 +200,12 @@ const repository = {
});
},
}),
...createServerRoute({
endpoint: 'POST /internal/endpoint_returning_observable',
handler: async () => {
return of({ streamed_response: true });
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved
},
}),
};

type TestRepository = typeof repository;
Expand Down Expand Up @@ -239,7 +246,10 @@ assertType<ReturnOf<TestRepository, 'GET /internal/endpoint_returning_kibana_res

// RouteRepositoryClient

type TestClient = RouteRepositoryClient<TestRepository, { timeout: number }>;
type TestClient = RouteRepositoryClient<
TestRepository,
{ asEventSourceStream?: boolean; timeout: number }
>;

const client: TestClient = {} as any;

Expand All @@ -260,17 +270,17 @@ client('GET /internal/endpoint_without_params', {
});

// It requires params for routes with a params codec
// @ts-expect-error property 'serviceName' is missing in type '{}'
client('GET /internal/endpoint_with_params', {
params: {
// @ts-expect-error property 'serviceName' is missing in type '{}'
path: {},
},
timeout: 1,
});

// @ts-expect-error property 'serviceName' is missing in type '{}'
client('GET /internal/endpoint_with_params_zod', {
params: {
// @ts-expect-error property 'serviceName' is missing in type '{}'
path: {},
},
timeout: 1,
Expand All @@ -294,10 +304,10 @@ client('GET /internal/endpoint_with_optional_params', {
},
});

// @ts-expect-error Object literal may only specify known properties, and 'path' does not exist in type
client('GET /internal/endpoint_with_optional_params_zod', {
timeout: 1,
params: {
// @ts-expect-error Object literal may only specify known properties, and 'path' does not exist in type
path: '',
},
});
Expand Down Expand Up @@ -382,3 +392,10 @@ assertType<{ path: { serviceName: boolean } }>(
t.type({ path: t.type({ serviceName: t.string }) })
)
);

assertType<Observable<{ streamed_response: boolean }>>(
client('POST /internal/endpoint_returning_observable', {
timeout: 10,
asEventSourceStream: true as const,
})
);
1 change: 1 addition & 0 deletions src/dev/storybook/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const storybookAliases = {
grouping: 'packages/kbn-grouping/.storybook',
home: 'src/plugins/home/.storybook',
infra: 'x-pack/plugins/observability_solution/infra/.storybook',
inventory: 'x-pack/plugins/observability_solution/inventory/.storybook',
investigate: 'x-pack/plugins/observability_solution/investigate_app/.storybook',
kibana_react: 'src/plugins/kibana_react/.storybook',
lists: 'x-pack/plugins/lists/.storybook',
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,8 @@
"@kbn/interactive-setup-test-endpoints-plugin/*": ["test/interactive_setup_api_integration/plugins/test_endpoints/*"],
"@kbn/interpreter": ["packages/kbn-interpreter"],
"@kbn/interpreter/*": ["packages/kbn-interpreter/*"],
"@kbn/inventory-plugin": ["x-pack/plugins/observability_solution/inventory"],
"@kbn/inventory-plugin/*": ["x-pack/plugins/observability_solution/inventory/*"],
"@kbn/investigate-app-plugin": ["x-pack/plugins/observability_solution/investigate_app"],
"@kbn/investigate-app-plugin/*": ["x-pack/plugins/observability_solution/investigate_app/*"],
"@kbn/investigate-plugin": ["x-pack/plugins/observability_solution/investigate"],
Expand Down
1 change: 1 addition & 0 deletions x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"xpack.ingestPipelines": "plugins/ingest_pipelines",
"xpack.integrationAssistant": "plugins/integration_assistant",
"xpack.inference": "plugins/inference",
"xpack.inventory": "plugins/observability_solution/inventory",
"xpack.investigate": "plugins/observability_solution/investigate",
"xpack.investigateApp": "plugins/observability_solution/investigate_app",
"xpack.kubernetesSecurity": "plugins/kubernetes_security",
Expand Down
16 changes: 16 additions & 0 deletions x-pack/plugins/inference/common/util/truncate_list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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.
*/

import { take } from 'lodash';

export function truncateList<T>(values: T[], limit: number): Array<T | string> {
if (values.length <= limit) {
return values;
}

return [...take(values, limit), `${values.length - limit} more values`];
}
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

import type { IScopedClusterClient, SavedObjectsClientContract } from '@kbn/core/server';
import { findEntityDefinitions } from '../entities/find_entity_definition';
import type { EntityDefinitionWithState } from '../entities/types';

export class EntityManagerClient {
constructor(
private readonly esClient: IScopedClusterClient,
private readonly soClient: SavedObjectsClientContract
) {}

findEntityDefinitions({ page, perPage }: { page?: number; perPage?: number } = {}): Promise<
EntityDefinitionWithState[]
> {
return findEntityDefinitions({
esClient: this.esClient.asCurrentUser,
soClient: this.soClient,
page,
perPage,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
PluginInitializerContext,
PluginConfigDescriptor,
Logger,
KibanaRequest,
} from '@kbn/core/server';
import { installEntityManagerTemplates } from './lib/manage_index_templates';
import { setupRoutes } from './routes';
Expand All @@ -26,6 +27,7 @@ import { EntityManagerConfig, configSchema, exposeToBrowserConfig } from '../com
import { entityDefinition, EntityDiscoveryApiKeyType } from './saved_objects';
import { upgradeBuiltInEntityDefinitions } from './lib/entities/upgrade_entity_definition';
import { builtInDefinitions } from './lib/entities/built_in';
import { EntityManagerClient } from './lib/client';

export type EntityManagerServerPluginSetup = ReturnType<EntityManagerServerPlugin['setup']>;
export type EntityManagerServerPluginStart = ReturnType<EntityManagerServerPlugin['start']>;
Expand Down Expand Up @@ -104,7 +106,13 @@ export class EntityManagerServerPlugin
})
.catch((err) => this.logger.error(err));

return {};
return {
getClientWithRequest: async ({ request }: { request: KibanaRequest }) => {
const scopedEsClient = core.elasticsearch.client.asScoped(request);
const soClient = core.savedObjects.getScopedClient(request);
return new EntityManagerClient(scopedEsClient, soClient);
},
};
}

public stop() {}
Expand Down
Loading