-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.0] Add API tests for dependencies metadata (#116648) | Add API tes…
…ts for top dependencies (#116788) | [APM] Adding api tests for error group (#116771) | [APM] Synthtrace ES Client (#116770) | Revert "[APM] Adding api tests for error grou (#117257) * Add API tests for dependencies metadata (#116648) * Add API tests for dependencies metadata * Rename metadata tests to event metadata Co-authored-by: Nathan L Smith <nathan.smith@elastic.co> * Add API tests for top dependencies (#116788) * Add top dependencies API tests Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com> * [APM] Adding api tests for error group (#116771) * adding api tests for error group * addresing pr changes * [APM] Synthtrace ES Client (#116770) Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com> * Revert "[APM] Adding api tests for error group (#116771)" This reverts commit f2402ce. * [APM] Apm errors api tests (#116764) * changes after review * move file to errors folder * [APM] Fixing synthtrace import location (#117017) Co-authored-by: Giorgos Bamparopoulos <georgios.bamparopoulos@elastic.co> Co-authored-by: Nathan L Smith <nathan.smith@elastic.co> Co-authored-by: Cauê Marcondes <55978943+cauemarcondes@users.noreply.github.com> Co-authored-by: Dario Gieselaar <dario.gieselaar@elastic.co> Co-authored-by: Tyler Smalley <tyler.smalley@elastic.co> Co-authored-by: Miriam <31922082+MiriamAparicio@users.noreply.github.com>
- Loading branch information
1 parent
5e571b9
commit aac519f
Showing
29 changed files
with
22,878 additions
and
165 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
55 changes: 55 additions & 0 deletions
55
packages/elastic-apm-synthtrace/src/lib/client/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,55 @@ | ||
/* | ||
* 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 { uploadEvents } from '../../scripts/utils/upload_events'; | ||
import { Fields } from '../entity'; | ||
import { cleanWriteTargets } from '../utils/clean_write_targets'; | ||
import { getBreakdownMetrics } from '../utils/get_breakdown_metrics'; | ||
import { getSpanDestinationMetrics } from '../utils/get_span_destination_metrics'; | ||
import { getTransactionMetrics } from '../utils/get_transaction_metrics'; | ||
import { getWriteTargets } from '../utils/get_write_targets'; | ||
import { Logger } from '../utils/logger'; | ||
|
||
export class SynthtraceEsClient { | ||
constructor(private readonly client: Client, private readonly logger: Logger) {} | ||
|
||
private getWriteTargets() { | ||
return getWriteTargets({ client: this.client }); | ||
} | ||
|
||
clean() { | ||
return this.getWriteTargets().then((writeTargets) => | ||
cleanWriteTargets({ client: this.client, writeTargets, logger: this.logger }) | ||
); | ||
} | ||
|
||
async index(events: Fields[]) { | ||
const eventsToIndex = [ | ||
...events, | ||
...getTransactionMetrics(events), | ||
...getSpanDestinationMetrics(events), | ||
...getBreakdownMetrics(events), | ||
]; | ||
|
||
const writeTargets = await this.getWriteTargets(); | ||
|
||
await uploadEvents({ | ||
batchSize: 1000, | ||
client: this.client, | ||
clientWorkers: 5, | ||
events: eventsToIndex, | ||
logger: this.logger, | ||
writeTargets, | ||
}); | ||
|
||
return this.client.indices.refresh({ | ||
index: Object.values(writeTargets), | ||
}); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,67 @@ | ||
/* | ||
* 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 { isPromise } from 'util/types'; | ||
|
||
export enum LogLevel { | ||
trace = 0, | ||
debug = 1, | ||
info = 2, | ||
error = 3, | ||
} | ||
|
||
function getTimeString() { | ||
return `[${new Date().toLocaleTimeString()}]`; | ||
} | ||
|
||
export function createLogger(logLevel: LogLevel) { | ||
function logPerf(name: string, start: bigint) { | ||
// eslint-disable-next-line no-console | ||
console.debug( | ||
getTimeString(), | ||
`${name}: ${Number(process.hrtime.bigint() - start) / 1000000}ms` | ||
); | ||
} | ||
return { | ||
perf: <T extends any>(name: string, cb: () => T): T => { | ||
if (logLevel <= LogLevel.trace) { | ||
const start = process.hrtime.bigint(); | ||
const val = cb(); | ||
if (isPromise(val)) { | ||
val.then(() => { | ||
logPerf(name, start); | ||
}); | ||
} else { | ||
logPerf(name, start); | ||
} | ||
return val; | ||
} | ||
return cb(); | ||
}, | ||
debug: (...args: any[]) => { | ||
if (logLevel <= LogLevel.debug) { | ||
// eslint-disable-next-line no-console | ||
console.debug(getTimeString(), ...args); | ||
} | ||
}, | ||
info: (...args: any[]) => { | ||
if (logLevel <= LogLevel.info) { | ||
// eslint-disable-next-line no-console | ||
console.log(getTimeString(), ...args); | ||
} | ||
}, | ||
error: (...args: any[]) => { | ||
if (logLevel <= LogLevel.error) { | ||
// eslint-disable-next-line no-console | ||
console.log(getTimeString(), ...args); | ||
} | ||
}, | ||
}; | ||
} | ||
|
||
export type Logger = ReturnType<typeof createLogger>; |
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
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
Oops, something went wrong.