forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dataset quality] Enable page for synthetics (elastic#191846)
Closes elastic/observability-dev#3457. This PR enables Dataset quality for being used for synthetics datasets. ### Changes - Added `synthetics` to `KNOWN_TYPES` array. - Permissions were updated in `Data_quality` plugin. https://github.com/user-attachments/assets/e9945012-166b-4704-bb73-11e6fe6eed76
- Loading branch information
Showing
27 changed files
with
542 additions
and
77 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
103 changes: 103 additions & 0 deletions
103
packages/kbn-apm-synthtrace-client/src/lib/synthetics/index.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,103 @@ | ||
/* | ||
* 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 { Fields } from '../entity'; | ||
import { Serializable } from '../serializable'; | ||
|
||
export type SyntheticsMonitorDocument = Fields & | ||
Partial<{ | ||
'data_stream.namespace': string; | ||
'data_stream.type': string; | ||
'data_stream.dataset': string; | ||
'monitor.id': string; | ||
'monitor.origin': string; | ||
'monitor.name': string; | ||
'monitor.type': string; | ||
'monitor.check_group': string; | ||
'monitor.timespan.lt': string; | ||
'monitor.timespan.gte': string; | ||
'monitor.duration.us'?: number; | ||
'monitor.ip'?: string; | ||
'monitor.project.name'?: string; | ||
'monitor.project.id'?: string; | ||
'monitor.fleet_managed'?: boolean; | ||
'monitor.status'?: string; | ||
'synthetics.type'?: string; | ||
'synthetics.step.index'?: number; | ||
'observer.os.name'?: string; | ||
'observer.product'?: string; | ||
}>; | ||
|
||
type MonitorDataStream = | ||
| 'http' | ||
| 'tcp' | ||
| 'icmp' | ||
| 'browser' | ||
| 'browser.screenshot' | ||
| 'browser.network'; | ||
|
||
class SyntheticsMonitor extends Serializable<SyntheticsMonitorDocument> { | ||
constructor(fields: SyntheticsMonitorDocument) { | ||
super({ | ||
...fields, | ||
}); | ||
} | ||
|
||
namespace(value: string) { | ||
this.fields['data_stream.namespace'] = value; | ||
return this; | ||
} | ||
|
||
dataset(value: MonitorDataStream) { | ||
this.fields['data_stream.dataset'] = value; | ||
|
||
if (value === 'browser.screenshot' || value === 'browser.network') { | ||
this.fields['monitor.type'] = 'browser'; | ||
return this; | ||
} | ||
|
||
this.fields['monitor.type'] = value; | ||
return this; | ||
} | ||
|
||
name(value: string) { | ||
this.fields['monitor.name'] = value; | ||
return this; | ||
} | ||
|
||
origin(value: string) { | ||
this.fields['monitor.origin'] = value; | ||
return this; | ||
} | ||
|
||
ip(value: string) { | ||
this.fields['monitor.ip'] = value; | ||
return this; | ||
} | ||
|
||
status(value: string) { | ||
this.fields['monitor.status'] = value; | ||
return this; | ||
} | ||
|
||
timestamp(time: number) { | ||
super.timestamp(time); | ||
return this; | ||
} | ||
} | ||
|
||
function create(): SyntheticsMonitor { | ||
return new SyntheticsMonitor({ | ||
'data_stream.namespace': 'default', | ||
'data_stream.type': 'synthetics', | ||
}).dataset('http'); | ||
} | ||
|
||
export const syntheticsMonitor = { | ||
create, | ||
}; |
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
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
33 changes: 33 additions & 0 deletions
33
packages/kbn-apm-synthtrace/src/cli/utils/get_synthetics_es_client.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,33 @@ | ||
/* | ||
* 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 { Client } from '@elastic/elasticsearch'; | ||
import { Logger } from '../../lib/utils/create_logger'; | ||
import { RunOptions } from './parse_run_cli_flags'; | ||
import { getEsClientTlsSettings } from './ssl'; | ||
import { SyntheticsSynthtraceEsClient } from '../../lib/synthetics/synthetics_synthtrace_es_client'; | ||
|
||
export function getSyntheticsEsClient({ | ||
target, | ||
logger, | ||
concurrency, | ||
}: Pick<RunOptions, 'concurrency'> & { | ||
target: string; | ||
logger: Logger; | ||
}) { | ||
const client = new Client({ | ||
node: target, | ||
tls: getEsClientTlsSettings(target), | ||
}); | ||
|
||
return new SyntheticsSynthtraceEsClient({ | ||
client, | ||
logger, | ||
concurrency, | ||
}); | ||
} |
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
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
25 changes: 25 additions & 0 deletions
25
packages/kbn-apm-synthtrace/src/lib/shared/data_stream_get_routing_transform.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,25 @@ | ||
/* | ||
* 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 { ESDocumentWithOperation, Fields } from '@kbn/apm-synthtrace-client'; | ||
import { Transform } from 'stream'; | ||
|
||
export function getRoutingTransform<T extends Fields>(dataStreamType: string) { | ||
return new Transform({ | ||
objectMode: true, | ||
transform(document: ESDocumentWithOperation<T>, encoding, callback) { | ||
if ('data_stream.dataset' in document && 'data_stream.namespace' in document) { | ||
document._index = `${dataStreamType}-${document['data_stream.dataset']}-${document['data_stream.namespace']}`; | ||
} else { | ||
throw new Error('Cannot determine index for event'); | ||
} | ||
|
||
callback(null, document); | ||
}, | ||
}); | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/kbn-apm-synthtrace/src/lib/synthetics/synthetics_synthtrace_es_client.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,42 @@ | ||
/* | ||
* 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 { Client } from '@elastic/elasticsearch'; | ||
import { SyntheticsMonitorDocument } from '@kbn/apm-synthtrace-client'; | ||
import { pipeline, Readable } from 'stream'; | ||
import { SynthtraceEsClient, SynthtraceEsClientOptions } from '../shared/base_client'; | ||
import { getSerializeTransform } from '../shared/get_serialize_transform'; | ||
import { Logger } from '../utils/create_logger'; | ||
import { getRoutingTransform } from '../shared/data_stream_get_routing_transform'; | ||
|
||
export type SyntheticsSynthtraceEsClientOptions = Omit<SynthtraceEsClientOptions, 'pipeline'>; | ||
|
||
export class SyntheticsSynthtraceEsClient extends SynthtraceEsClient<SyntheticsMonitorDocument> { | ||
constructor(options: { client: Client; logger: Logger } & SyntheticsSynthtraceEsClientOptions) { | ||
super({ | ||
...options, | ||
pipeline: syntheticsPipeline(), | ||
}); | ||
this.dataStreams = ['synthetics-*-*']; | ||
} | ||
} | ||
|
||
function syntheticsPipeline() { | ||
return (base: Readable) => { | ||
return pipeline( | ||
base, | ||
getSerializeTransform<SyntheticsMonitorDocument>(), | ||
getRoutingTransform('synthetics'), | ||
(err: unknown) => { | ||
if (err) { | ||
throw err; | ||
} | ||
} | ||
); | ||
}; | ||
} |
Oops, something went wrong.