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

[Streams] Dashboard linking #204309

Merged
merged 149 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 146 commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
5fe1078
Initial setup for streams plugin
simianhacker Oct 31, 2024
6f940eb
migrating to the streams naming schema; adding an abstraction for the…
simianhacker Nov 1, 2024
9b33808
ensure forked streams are marked root:false
simianhacker Nov 1, 2024
c8cd0f7
Commit entities plugins
dgieselaar Nov 6, 2024
7e8f2d7
Move files into streams_*
dgieselaar Nov 6, 2024
999dfef
Rename stuff & remove stuff
dgieselaar Nov 6, 2024
d99a3ff
stream management
flash1293 Nov 8, 2024
0e89345
add delete and listing endpoint
flash1293 Nov 8, 2024
9dd5fde
cleanup
flash1293 Nov 8, 2024
7400a3b
add resync endpoint
flash1293 Nov 8, 2024
5140687
Remove cruft, handle package relocation
dgieselaar Nov 10, 2024
797c93d
Streams table
dgieselaar Nov 10, 2024
fcce628
Only fetch histogram when DS exists
dgieselaar Nov 10, 2024
9d37219
more fixes
flash1293 Nov 10, 2024
d622fa1
more adjustments
flash1293 Nov 11, 2024
fbc6c2a
some more fixes
flash1293 Nov 11, 2024
45787d0
Merge remote-tracking branch 'upstream/main' into init-streams-plugin
flash1293 Nov 12, 2024
e810f53
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Nov 12, 2024
e93ac17
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 12, 2024
cf9f349
add limits
flash1293 Nov 12, 2024
0d676ed
Merge branch 'init-streams-plugin' of github.com:simianhacker/kibana …
flash1293 Nov 12, 2024
7b0a4e5
Add streams to left nav
dgieselaar Nov 12, 2024
34f3c44
fix permissions
flash1293 Nov 12, 2024
0b7de24
remove feature completely
flash1293 Nov 12, 2024
76ed81d
cleanup
flash1293 Nov 12, 2024
2427d2e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 12, 2024
2ad08f4
Merge branch 'main' into init-streams-plugin
flash1293 Nov 12, 2024
c8d99ed
Merge branch 'main' into init-streams-plugin
flash1293 Nov 12, 2024
8c707d1
Merge commit '0d676edfc0681f18d3804e079bad09053bf32247' into init-str…
dgieselaar Nov 12, 2024
e6bb640
[Observability] Split up observability-utils package
dgieselaar Nov 12, 2024
421ea5b
Merge branch 'main' of github.com:elastic/kibana into observability-u…
dgieselaar Nov 12, 2024
7992539
Fix references
dgieselaar Nov 12, 2024
95ae9f8
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Nov 12, 2024
7a88cc5
Fix issues in APM plugin
dgieselaar Nov 12, 2024
74f0678
Merge branch 'observability-utils-pkg-split' of github.com:dgieselaar…
dgieselaar Nov 12, 2024
dab77c1
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Nov 12, 2024
a60a165
Updating the owners and CODEOWNERS to @simianhacker @flash1293 @dgies…
simianhacker Nov 12, 2024
fc031f8
Merge branch 'main' of github.com:elastic/kibana into init-streams-pl…
simianhacker Nov 12, 2024
e9189e0
Merge branch 'main' of github.com:elastic/kibana into observability-u…
dgieselaar Nov 13, 2024
08aef83
Merge branch 'observability-utils-pkg-split' of github.com:dgieselaar…
dgieselaar Nov 13, 2024
2bef512
Fix references
dgieselaar Nov 13, 2024
5c10198
Option to unset value on error
dgieselaar Nov 13, 2024
5d40445
Merge branch 'observability-utils-pkg-split' into init-streams-app-pl…
dgieselaar Nov 13, 2024
9ca2da2
Fix lingering import
dgieselaar Nov 13, 2024
8b0b51c
Merge branch 'observability-utils-pkg-split' into init-streams-app-pl…
dgieselaar Nov 13, 2024
d655c0a
Clean up esql signature
dgieselaar Nov 13, 2024
8e0eba8
Handle sync callbacks in withSpan
dgieselaar Nov 13, 2024
eb61e23
Merge branch 'observability-utils-pkg-split' into init-streams-app-pl…
dgieselaar Nov 13, 2024
5e90008
Make APIs internal
dgieselaar Nov 13, 2024
dd55c3a
Merge branch 'init-streams-plugin' into init-streams-app-plugin
dgieselaar Nov 13, 2024
b9896ab
Merge remote-tracking branch 'upstream/main' into init-streams-app-pl…
dgieselaar Nov 13, 2024
377b365
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 13, 2024
b556194
Move to x-pack/plugins/streams_app
dgieselaar Nov 13, 2024
aa4a2e0
Improve types
dgieselaar Nov 13, 2024
f0276dc
Improve type strictness
dgieselaar Nov 13, 2024
adcd660
Update .i18nrc.json
dgieselaar Nov 14, 2024
224ffeb
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 14, 2024
2edc694
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 14, 2024
bb4dc6e
Conditionally register items in side nav
dgieselaar Nov 14, 2024
2b74f6c
Clean up
dgieselaar Nov 14, 2024
46ffca7
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Nov 14, 2024
bd6f225
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 19, 2024
1ec3a20
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 19, 2024
922d1b4
Review feedback
dgieselaar Nov 19, 2024
d6ee23e
Remove unflattening/field resolution
dgieselaar Nov 19, 2024
ad2cc5e
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Nov 19, 2024
26f5554
Update paths in jest.config.js
dgieselaar Nov 19, 2024
8dc61f3
Update i18n label
dgieselaar Nov 19, 2024
1fde5b4
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 19, 2024
3ffefbb
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 19, 2024
ab533ba
[Streams] API for asset links
dgieselaar Nov 21, 2024
f032b51
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 21, 2024
ac426f5
Add transform option
dgieselaar Nov 21, 2024
97510ca
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Nov 21, 2024
a950210
Fix types in investigate_app
dgieselaar Nov 21, 2024
84e233e
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 21, 2024
d2ba657
Fix jest.config.js
dgieselaar Nov 21, 2024
1ec3ef9
Flyout
dgieselaar Nov 21, 2024
c219042
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 22, 2024
1250723
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Nov 22, 2024
9a487e4
Use top-level security property
dgieselaar Nov 22, 2024
7452c8b
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 22, 2024
5245055
Fix types in onboarding
dgieselaar Nov 22, 2024
37be7f5
Merge branch 'init-streams-app-plugin' into streams-app-asset-linking
dgieselaar Nov 22, 2024
90389fc
Fix type issues in Streams app
dgieselaar Nov 22, 2024
0d8e0eb
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 23, 2024
76d2042
Add tests
dgieselaar Nov 23, 2024
e12aaec
Migrate options.security, fix issues with routing
dgieselaar Nov 23, 2024
1baac8f
Migrate options.security
dgieselaar Nov 23, 2024
3947668
Migrate options.security for entityManager
dgieselaar Nov 23, 2024
244e1d8
Merge branch 'init-streams-app-plugin' into streams-app-asset-linking
dgieselaar Nov 23, 2024
ef89662
Catch error in _status call
dgieselaar Nov 23, 2024
8ed5d23
Catch error in _status call
dgieselaar Nov 23, 2024
1ce43ab
Add streams to app usage schema
dgieselaar Nov 23, 2024
7065f3d
fix telemetry
dgieselaar Nov 23, 2024
ddaabc1
Type changes
dgieselaar Nov 24, 2024
a47ed43
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 24, 2024
d57be23
Update CODEOWNERS
dgieselaar Nov 24, 2024
003c3e6
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 24, 2024
830fc5d
More flexible types
dgieselaar Nov 24, 2024
95440e2
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 24, 2024
c46d94c
Properly pass plugins to routes
dgieselaar Nov 24, 2024
cebd9d0
Strip .text/.keyword suffixes
dgieselaar Nov 25, 2024
44d5b24
Set security for route registration in dataset_quality
dgieselaar Nov 25, 2024
9d297e7
Merge branch 'init-streams-app-plugin' into streams-app-asset-linking
dgieselaar Nov 26, 2024
3967908
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Nov 26, 2024
f1b5d0d
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Nov 27, 2024
c66ed6e
Merge remote-tracking branch 'upstream/main' into streams-app-asset-l…
flash1293 Dec 2, 2024
1fc2da9
make specific to dashboards
flash1293 Dec 2, 2024
de087c0
Merge remote-tracking branch 'upstream/main' into streams-app-asset-l…
flash1293 Dec 3, 2024
2d76780
Merge remote-tracking branch 'upstream/main' into streams-app-asset-l…
flash1293 Dec 3, 2024
17b955d
add assets everywhere
flash1293 Dec 3, 2024
a819748
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Dec 3, 2024
1abbf61
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Dec 3, 2024
4443da5
Merge remote-tracking branch 'upstream/main' into streams-app-asset-l…
flash1293 Dec 4, 2024
e5e2cc0
fix
flash1293 Dec 4, 2024
e9c9813
Merge branch 'streams-app-asset-linking' of github.com:dgieselaar/kib…
flash1293 Dec 4, 2024
d20fff0
fix types
flash1293 Dec 4, 2024
7452b90
fix type
flash1293 Dec 4, 2024
092881e
fix type
flash1293 Dec 4, 2024
ca13422
Use _has_privileges
dgieselaar Dec 12, 2024
1a63b35
Use _bulk API
dgieselaar Dec 13, 2024
1d2c29c
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Dec 13, 2024
32073ff
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Dec 13, 2024
8faf3f2
Fix access checks
dgieselaar Dec 14, 2024
c146287
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Dec 14, 2024
76cb698
Split up dashboards hook
dgieselaar Dec 16, 2024
806d1fd
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Dec 23, 2024
7cf986b
API tests
dgieselaar Dec 23, 2024
18d7788
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Dec 23, 2024
746a068
Storage adapter tests
dgieselaar Dec 27, 2024
0df97c1
Fix tests
dgieselaar Dec 27, 2024
82d94ca
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Dec 27, 2024
ec11424
Clean up types & comments
dgieselaar Dec 27, 2024
51beb26
[CI] Auto-commit changed files from 'node scripts/telemetry_check'
kibanamachine Dec 27, 2024
f9b8345
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Dec 27, 2024
90254e3
Fix quick checks
dgieselaar Dec 27, 2024
92487ba
Merge branch 'streams-app-asset-linking' of github.com:dgieselaar/kib…
dgieselaar Dec 28, 2024
0613385
Revert changes to Fleet files
dgieselaar Dec 28, 2024
7f2a70c
Merge branch 'main' into streams-app-asset-linking
elasticmachine Dec 29, 2024
119c17c
Merge branch 'main' into streams-app-asset-linking
elasticmachine Dec 31, 2024
1666de7
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Jan 6, 2025
0dfc7a1
Merge branch 'streams-app-asset-linking' of github.com:dgieselaar/kib…
dgieselaar Jan 6, 2025
287528f
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Jan 7, 2025
57699d9
Fix issue w/ deleted dashboard, usage example for storage index adapter
dgieselaar Jan 7, 2025
7680759
Use signal from fetch hookC
dgieselaar Jan 7, 2025
1266ea0
Clarify comment
dgieselaar Jan 7, 2025
f0739fb
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Jan 7, 2025
068e60f
Merge branch 'main' of github.com:elastic/kibana into streams-app-ass…
dgieselaar Jan 7, 2025
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,7 @@ packages/kbn-monaco/src/esql @elastic/kibana-esql
/x-pack/solutions/observability/plugins/infra/server/routes/log_analysis @elastic/obs-ux-logs-team
/x-pack/solutions/observability/plugins/infra/server/services/rules @elastic/obs-ux-infra_services-team @elastic/obs-ux-logs-team
/x-pack/test/common/utils/synthtrace @elastic/obs-ux-infra_services-team @elastic/obs-ux-logs-team # Assigned per https://github.com/elastic/kibana/blob/main/packages/kbn-apm-synthtrace/kibana.jsonc#L5
/x-pack/test/common/utils/server_route_repository @elastic/obs-knowledge-team

# Infra Monitoring tests
/x-pack/test/common/services/infra_synthtrace_kibana_client.ts @elastic/obs-ux-infra_services-team
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

import { get } from 'lodash';

export function isRequestAbortedError(error: unknown): error is Error {
export function isRequestAbortedError(error: unknown): error is Error & { name: 'AbortError' } {
Copy link
Member Author

Choose a reason for hiding this comment

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

make sure we can refine errors without falling back to never

return get(error, 'name') === 'AbortError';
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ type DecodedRequestParamsOfType<TRouteParamsRT extends RouteParamsRT> =
: never;

export type EndpointOf<TServerRouteRepository extends ServerRouteRepository> =
keyof TServerRouteRepository;
keyof TServerRouteRepository & string;

export type ReturnOf<
TServerRouteRepository extends ServerRouteRepository,
Expand Down
8 changes: 2 additions & 6 deletions x-pack/packages/kbn-streams-schema/src/helpers/type_guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,11 @@ export function isStream(subject: any): subject is StreamDefinition {
return isSchema(streamDefintionSchema, subject);
}

export function isIngestStream(
subject: IngestStreamDefinition | WiredStreamDefinition
): subject is IngestStreamDefinition {
export function isIngestStream(subject: StreamDefinition): subject is IngestStreamDefinition {
return isSchema(ingestStreamDefinitonSchema, subject);
}

export function isWiredStream(
subject: IngestStreamDefinition | WiredStreamDefinition
): subject is WiredStreamDefinition {
export function isWiredStream(subject: StreamDefinition): subject is WiredStreamDefinition {
Copy link
Member Author

Choose a reason for hiding this comment

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

just a simplification

return isSchema(wiredStreamDefinitonSchema, subject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const ingestStreamDefinitonSchema = z
name: z.string(),
elasticsearch_assets: z.optional(elasticsearchAssetSchema),
stream: ingestStreamConfigDefinitonSchema,
dashboards: z.optional(z.array(z.string())),
})
.strict();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const wiredStreamDefinitonSchema = z
name: z.string(),
elasticsearch_assets: z.optional(elasticsearchAssetSchema),
stream: wiredStreamConfigDefinitonSchema,
dashboards: z.optional(z.array(z.string())),
})
.strict();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@elastic/appex-sharedux"
],
"group": "platform",
"visibility": "private",
"visibility": "shared",
"plugin": {
"id": "savedObjectsTagging",
"browser": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import { schema } from '@kbn/config-schema';

const savedObjectReferenceSchema = schema.object({
type: schema.string(),
id: schema.string(),
});

export const findRulesOptionsSchema = schema.object(
{
perPage: schema.maybe(schema.number()),
Expand All @@ -19,10 +24,7 @@ export const findRulesOptionsSchema = schema.object(
sortField: schema.maybe(schema.string()),
sortOrder: schema.maybe(schema.oneOf([schema.literal('asc'), schema.literal('desc')])),
hasReference: schema.maybe(
schema.object({
type: schema.string(),
id: schema.string(),
})
schema.oneOf([savedObjectReferenceSchema, schema.arrayOf(savedObjectReferenceSchema)])
Copy link
Member Author

Choose a reason for hiding this comment

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

this is what the SO api allows, and what we need to find rules with one of n tags

),
fields: schema.maybe(schema.arrayOf(schema.string())),
filter: schema.maybe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { esqlResultToPlainObjects } from '../esql_result_to_plain_objects';
type SearchRequest = ESSearchRequest & {
index: string | string[];
track_total_hits: number | boolean;
size: number | boolean;
size: number;
};

export interface EsqlOptions {
Expand Down Expand Up @@ -112,10 +112,12 @@ export function createObservabilityEsClient({
client,
logger,
plugin,
labels,
}: {
client: ElasticsearchClient;
logger: Logger;
plugin: string;
plugin?: string;
labels?: Record<string, string>;
}): ObservabilityElasticsearchClient {
// wraps the ES calls in a named APM span for better analysis
// (otherwise it would just eg be a _search span)
Expand All @@ -129,7 +131,8 @@ export function createObservabilityEsClient({
{
name: operationName,
labels: {
plugin,
...labels,
...(plugin ? { plugin } : {}),
},
},
callback,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Storage adapter

Storage adapters are an abstraction for managing & writing data into Elasticsearch, from Kibana plugins.

There are several ways one can use Elasticsearch in Kibana, for instance:

- a simple id-based CRUD table
- timeseries data with regular indices
- timeseries data with data streams

But then there are many choices to be made that make this a very complex problem:

- Elasticsearch asset managmeent
- Authentication
- Schema changes
- Kibana's distributed nature
- Stateful versus serverless

The intent of storage adapters is to come up with an abstraction that allows Kibana developers to have a common interface for writing to and reading data from Elasticsearch. For instance, for setting up your data store, it should not matter how you authenticate (internal user? current user? API keys?).

## Saved objects

Some of these problems are solved by Saved Objects. But Saved Objects come with a lot of baggage - Kibana RBAC, relationships, spaces, all of which might not be
needed for your use case but are still restrictive. One could consider Saved Objects to be the target of an adapter, but Storage Adapters aim to address a wider set of use-cases.

## Philosophy

Storage adapters should largely adhere to the following principles:

- Interfaces are as close to Elasticsearch as possible. Meaning, the `search` method is practically a pass-through for `_search`.
- Strongly-typed. TypeScript types are inferred from the schema. This makes it easy to create fully-typed clients for any storage.
- Lazy writes. No Elasticsearch assets (templates, indices, aliases) get installed unless necessary. Anything that gets persisted to Elasticsearch raises questions (in SDHs, UIs, APIs) and should be avoided when possible. This also helps avoidable upgrade issues (e.g. conflicting mappings for something that never got used).
- Recoverable. If somehow Elasticsearch assets get borked, the adapters should make a best-effort attempt to recover, or log warnings with clear remediation steps.

## Future goals

Currently, we only have the StorageIndexAdapter which writes to plain indices. In the future, we'll want more:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you include a code example for how to consume StorageIndexAdapter?

Copy link
Member Author

Choose a reason for hiding this comment

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

done!


- A StorageDataStreamAdapter or StorageSavedObjectAdapter
- Federated search
- Data/Index Lifecycle Management
- Migration scripts
- Runtime mappings for older versions

## Usage

### Storage index adapter

To use the storage index adapter, instantiate it with an authenticated Elasticsearch client:

```ts
const storageSettings = {
name: '.kibana_streams_assets',
schema: {
properties: {
[ASSET_ASSET_ID]: types.keyword({ required: true }),
[ASSET_TYPE]: types.enum(Object.values(ASSET_TYPES), { required: true }),
},
},
} satisfies IndexStorageSettings;

// create and configure the adapter
const adapter = new StorageIndexAdapter(
esClient: coreStart.elasticsearch.client.asInternalUser,
this.logger.get('assets'),
storageSettings
);

// get the client (which is shared across all adapters)
Copy link
Contributor

Choose a reason for hiding this comment

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

(which is shared across all adapters)

What does this mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

its interface, will update the comment

const client = adapter.getClient();

const response = await client.search('operation_name', {
track_total_hits: true
});

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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 stringify from 'json-stable-stringify';
import objectHash from 'object-hash';
import { IndexStorageSettings } from '.';

export function getSchemaVersion(storage: IndexStorageSettings): string {
const version = objectHash(stringify(storage.schema.properties));
return version;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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 {
BulkOperationContainer,
BulkRequest,
BulkResponse,
DeleteRequest,
DeleteResponse,
IndexRequest,
IndexResponse,
SearchRequest,
} from '@elastic/elasticsearch/lib/api/types';
import { InferSearchResponseOf } from '@kbn/es-types';
import { StorageFieldTypeOf, StorageMappingProperty } from './types';

interface StorageSchemaProperties {
[x: string]: StorageMappingProperty;
}

export interface StorageSchema {
properties: StorageSchemaProperties;
}

interface StorageSettingsBase {
schema: StorageSchema;
}

export interface IndexStorageSettings extends StorageSettingsBase {
name: string;
}

export type StorageSettings = IndexStorageSettings;

export type StorageAdapterSearchRequest = Omit<SearchRequest, 'index'>;
export type StorageAdapterSearchResponse<
TDocument,
TSearchRequest extends Omit<SearchRequest, 'index'>
> = InferSearchResponseOf<TDocument, TSearchRequest>;

export type StorageAdapterBulkOperation = Pick<BulkOperationContainer, 'delete' | 'index'>;

export type StorageAdapterBulkRequest<TDocument extends Record<string, any>> = Omit<
BulkRequest,
'operations' | 'index'
> & {
operations: Array<StorageAdapterBulkOperation | TDocument>;
};
export type StorageAdapterBulkResponse = BulkResponse;

export type StorageAdapterDeleteRequest = DeleteRequest;
export type StorageAdapterDeleteResponse = DeleteResponse;

export type StorageAdapterIndexRequest<TDocument = unknown> = Omit<
IndexRequest<TDocument>,
'index'
>;
export type StorageAdapterIndexResponse = IndexResponse;

export interface IStorageAdapter<TStorageSettings extends StorageSettings = never> {
bulk<TDocument extends Record<string, any>>(
request: StorageAdapterBulkRequest<TDocument>
): Promise<StorageAdapterBulkResponse>;
search<TDocument, TSearchRequest extends Omit<SearchRequest, 'index'>>(
request: StorageAdapterSearchRequest
): Promise<StorageAdapterSearchResponse<TDocument, TSearchRequest>>;
index<TDocument>(
request: StorageAdapterIndexRequest<TDocument>
): Promise<StorageAdapterIndexResponse>;
delete(request: StorageAdapterDeleteRequest): Promise<StorageAdapterDeleteResponse>;
}

export type StorageSettingsOf<TStorageAdapter extends IStorageAdapter<StorageSettings>> =
TStorageAdapter extends IStorageAdapter<infer TStorageSettings>
? TStorageSettings extends StorageSettings
? TStorageSettings
: never
: never;

export type StorageDocumentOf<TStorageSettings extends StorageSettings> = {
[TKey in keyof TStorageSettings['schema']['properties']]: StorageFieldTypeOf<
TStorageSettings['schema']['properties'][TKey]
>;
} & { _id: string };

export { StorageIndexAdapter } from './index_adapter';
export { StorageClient } from './storage_client';
export { types } from './types';
Loading