-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x] [Usage Collection] Supports field descriptions as meta data (#9…
…2701) (#93295) * [Usage Collection] Supports field descriptions as meta data (#92701) Co-authored-by: Alejandro Fernández Haro <afharo@gmail.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> # Conflicts: # src/plugins/kibana_usage_collection/server/collectors/management/schema.ts * Updates schema
- Loading branch information
1 parent
04cb7d9
commit 765b083
Showing
23 changed files
with
7,067 additions
and
1,640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/kbn-telemetry-tools/src/tools/__fixture__/mock_schema_with_descriptions.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"properties": { | ||
"my_working_collector_with_description": { | ||
"properties": { | ||
"flat": { | ||
"type": "keyword", | ||
"_meta": { | ||
"description": "A flat keyword string" | ||
} | ||
}, | ||
"my_index_signature_prop": { | ||
"properties": { | ||
"avg": { | ||
"type": "float" | ||
}, | ||
"count": { | ||
"type": "long" | ||
}, | ||
"max": { | ||
"type": "long" | ||
}, | ||
"min": { | ||
"type": "long" | ||
} | ||
} | ||
}, | ||
"my_str": { | ||
"type": "text" | ||
}, | ||
"my_objects": { | ||
"properties": { | ||
"total": { | ||
"type": "long" | ||
}, | ||
"type": { | ||
"type": "boolean" | ||
} | ||
} | ||
}, | ||
"my_array": { | ||
"type": "array", | ||
"items": { | ||
"properties": { | ||
"total": { | ||
"type": "long" | ||
}, | ||
"type": { | ||
"type": "boolean" | ||
} | ||
} | ||
} | ||
}, | ||
"my_str_array": { "type": "array", "items": { "type": "keyword" } } | ||
} | ||
} | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
...es/kbn-telemetry-tools/src/tools/__fixture__/parsed_working_collector_with_description.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* 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 { SyntaxKind } from 'typescript'; | ||
import { ParsedUsageCollection } from '../ts_parser'; | ||
|
||
export const parsedCollectorWithDescription: ParsedUsageCollection = [ | ||
'src/fixtures/telemetry_collectors/working_collector_with_description.ts', | ||
{ | ||
collectorName: 'my_working_collector_with_description', | ||
schema: { | ||
value: { | ||
flat: { | ||
type: 'keyword', | ||
_meta: { | ||
description: 'A flat keyword string', | ||
}, | ||
}, | ||
my_str: { | ||
type: 'text', | ||
}, | ||
my_index_signature_prop: { | ||
avg: { | ||
type: 'float', | ||
}, | ||
count: { | ||
type: 'long', | ||
}, | ||
max: { | ||
type: 'long', | ||
}, | ||
min: { | ||
type: 'long', | ||
}, | ||
}, | ||
my_objects: { | ||
total: { | ||
type: 'long', | ||
}, | ||
type: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
my_array: { | ||
type: 'array', | ||
items: { | ||
total: { | ||
type: 'long', | ||
}, | ||
type: { type: 'boolean' }, | ||
}, | ||
}, | ||
my_str_array: { type: 'array', items: { type: 'keyword' } }, | ||
}, | ||
}, | ||
fetch: { | ||
typeName: 'Usage', | ||
typeDescriptor: { | ||
flat: { | ||
kind: SyntaxKind.StringKeyword, | ||
type: 'StringKeyword', | ||
}, | ||
my_str: { | ||
kind: SyntaxKind.StringKeyword, | ||
type: 'StringKeyword', | ||
}, | ||
my_index_signature_prop: { | ||
'@@INDEX@@': { | ||
kind: SyntaxKind.NumberKeyword, | ||
type: 'NumberKeyword', | ||
}, | ||
}, | ||
my_objects: { | ||
total: { | ||
kind: SyntaxKind.NumberKeyword, | ||
type: 'NumberKeyword', | ||
}, | ||
type: { | ||
kind: SyntaxKind.BooleanKeyword, | ||
type: 'BooleanKeyword', | ||
}, | ||
}, | ||
my_array: { | ||
items: { | ||
total: { | ||
kind: SyntaxKind.NumberKeyword, | ||
type: 'NumberKeyword', | ||
}, | ||
type: { | ||
kind: SyntaxKind.BooleanKeyword, | ||
type: 'BooleanKeyword', | ||
}, | ||
}, | ||
}, | ||
my_str_array: { | ||
items: { | ||
kind: SyntaxKind.StringKeyword, | ||
type: 'StringKeyword', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/fixtures/telemetry_collectors/working_collector_with_description.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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 { CollectorSet } from '../../plugins/usage_collection/server/collector'; | ||
import { loggerMock } from '../../core/server/logging/logger.mock'; | ||
|
||
const { makeUsageCollector } = new CollectorSet({ | ||
logger: loggerMock.create(), | ||
maximumWaitTimeForAllCollectorsInS: 0, | ||
}); | ||
|
||
interface MyObject { | ||
total: number; | ||
type: boolean; | ||
} | ||
|
||
interface Usage { | ||
flat?: string; | ||
my_str?: string; | ||
my_objects: MyObject; | ||
my_array?: MyObject[]; | ||
my_str_array?: string[]; | ||
my_index_signature_prop?: { | ||
[key: string]: number; | ||
}; | ||
} | ||
|
||
const SOME_NUMBER: number = 123; | ||
|
||
export const myCollector = makeUsageCollector<Usage>({ | ||
type: 'my_working_collector_with_description', | ||
isReady: () => true, | ||
fetch() { | ||
const testString = '123'; | ||
// query ES and get some data | ||
|
||
// summarize the data into a model | ||
// return the modeled object that includes whatever you want to track | ||
try { | ||
return { | ||
flat: 'hello', | ||
my_str: testString, | ||
my_objects: { | ||
total: SOME_NUMBER, | ||
type: true, | ||
}, | ||
my_array: [ | ||
{ | ||
total: SOME_NUMBER, | ||
type: true, | ||
}, | ||
], | ||
my_str_array: ['hello', 'world'], | ||
}; | ||
} catch (err) { | ||
return { | ||
my_objects: { | ||
total: 0, | ||
type: true, | ||
}, | ||
}; | ||
} | ||
}, | ||
schema: { | ||
flat: { | ||
type: 'keyword', | ||
_meta: { | ||
description: 'A flat keyword string', | ||
}, | ||
}, | ||
my_str: { | ||
type: 'text', | ||
}, | ||
my_objects: { | ||
total: { | ||
type: 'long', | ||
}, | ||
type: { type: 'boolean' }, | ||
}, | ||
my_array: { | ||
type: 'array', | ||
items: { | ||
total: { | ||
type: 'long', | ||
}, | ||
type: { type: 'boolean' }, | ||
}, | ||
}, | ||
my_str_array: { type: 'array', items: { type: 'keyword' } }, | ||
my_index_signature_prop: { | ||
count: { type: 'long' }, | ||
avg: { type: 'float' }, | ||
max: { type: 'long' }, | ||
min: { type: 'long' }, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.