mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[ci-stats] support sending meta with metrics (#114198)
* [ci-stats] support sending meta with metrics * update kbn/pm dist * improve comments stat * update kbn/pm dist Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
243c2133af
commit
7c087fea82
2 changed files with 64 additions and 12 deletions
|
@ -22,24 +22,43 @@ import { parseConfig, Config } from './ci_stats_config';
|
|||
const BASE_URL = 'https://ci-stats.kibana.dev';
|
||||
|
||||
export interface CiStatsMetric {
|
||||
/** Top-level categorization for the metric, e.g. "page load bundle size" */
|
||||
group: string;
|
||||
/** Specific sub-set of the "group", e.g. "dashboard" */
|
||||
id: string;
|
||||
/** integer value recorded as the value of this metric */
|
||||
value: number;
|
||||
/** optional limit which will generate an error on PRs when the metric exceeds the limit */
|
||||
limit?: number;
|
||||
/**
|
||||
* path, relative to the repo, where the config file contianing limits
|
||||
* is kept. Linked from PR comments instructing contributors how to fix
|
||||
* their PRs.
|
||||
*/
|
||||
limitConfigPath?: string;
|
||||
/** Arbitrary key-value pairs which can be used for additional filtering/reporting */
|
||||
meta?: CiStatsMetadata;
|
||||
}
|
||||
|
||||
export interface CiStatsTimingMetadata {
|
||||
export interface CiStatsMetadata {
|
||||
/**
|
||||
* Arbitrary key-value pairs which can be attached to CiStatsTiming and CiStatsMetric
|
||||
* objects stored in the ci-stats service
|
||||
*/
|
||||
[key: string]: string | string[] | number | boolean | undefined;
|
||||
}
|
||||
export interface CiStatsTiming {
|
||||
/** Top-level categorization for the timing, e.g. "scripts/foo", process type, etc. */
|
||||
group: string;
|
||||
/** Specific timing (witin the "group" being tracked) e.g. "total" */
|
||||
id: string;
|
||||
/** time in milliseconds which should be recorded */
|
||||
ms: number;
|
||||
meta?: CiStatsTimingMetadata;
|
||||
/** hash of key-value pairs which will be stored with the timing for additional filtering and reporting */
|
||||
meta?: CiStatsMetadata;
|
||||
}
|
||||
|
||||
export interface ReqOptions {
|
||||
interface ReqOptions {
|
||||
auth: boolean;
|
||||
path: string;
|
||||
body: any;
|
||||
|
@ -54,17 +73,34 @@ export interface TimingsOptions {
|
|||
/** value of data/uuid, automatically loaded if not specified */
|
||||
kibanaUuid?: string | null;
|
||||
}
|
||||
|
||||
export interface MetricsOptions {
|
||||
/** Default metadata to add to each metric */
|
||||
defaultMeta?: CiStatsMetadata;
|
||||
}
|
||||
export class CiStatsReporter {
|
||||
/**
|
||||
* Create a CiStatsReporter by inspecting the ENV for the necessary config
|
||||
*/
|
||||
static fromEnv(log: ToolingLog) {
|
||||
return new CiStatsReporter(parseConfig(log), log);
|
||||
}
|
||||
|
||||
constructor(private config: Config | undefined, private log: ToolingLog) {}
|
||||
|
||||
/**
|
||||
* Determine if CI_STATS is explicitly disabled by the environment. To determine
|
||||
* if the CiStatsReporter has enough information in the environment to send metrics
|
||||
* for builds use #hasBuildConfig().
|
||||
*/
|
||||
isEnabled() {
|
||||
return process.env.CI_STATS_DISABLED !== 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the CiStatsReporter is disabled by the environment, or properly
|
||||
* configured and able to send stats
|
||||
*/
|
||||
hasBuildConfig() {
|
||||
return this.isEnabled() && !!this.config?.apiToken && !!this.config?.buildId;
|
||||
}
|
||||
|
@ -103,7 +139,7 @@ export class CiStatsReporter {
|
|||
const memUsage = process.memoryUsage();
|
||||
const isElasticCommitter = email && email.endsWith('@elastic.co') ? true : false;
|
||||
|
||||
const defaultMetadata = {
|
||||
const defaultMeta = {
|
||||
kibanaUuid,
|
||||
isElasticCommitter,
|
||||
committerHash: email
|
||||
|
@ -127,7 +163,7 @@ export class CiStatsReporter {
|
|||
totalMem: Os.totalmem(),
|
||||
};
|
||||
|
||||
this.log.debug('CIStatsReporter committerHash: %s', defaultMetadata.committerHash);
|
||||
this.log.debug('CIStatsReporter committerHash: %s', defaultMeta.committerHash);
|
||||
|
||||
return await this.req({
|
||||
auth: !!buildId,
|
||||
|
@ -135,8 +171,8 @@ export class CiStatsReporter {
|
|||
body: {
|
||||
buildId,
|
||||
upstreamBranch,
|
||||
defaultMeta,
|
||||
timings,
|
||||
defaultMetadata,
|
||||
},
|
||||
bodyDesc: timings.length === 1 ? `${timings.length} timing` : `${timings.length} timings`,
|
||||
});
|
||||
|
@ -146,7 +182,7 @@ export class CiStatsReporter {
|
|||
* Report metrics data to the ci-stats service. If running outside of CI this method
|
||||
* does nothing as metrics can only be reported when associated with a specific CI build.
|
||||
*/
|
||||
async metrics(metrics: CiStatsMetric[]) {
|
||||
async metrics(metrics: CiStatsMetric[], options?: MetricsOptions) {
|
||||
if (!this.hasBuildConfig()) {
|
||||
return;
|
||||
}
|
||||
|
@ -162,6 +198,7 @@ export class CiStatsReporter {
|
|||
path: '/v1/metrics',
|
||||
body: {
|
||||
buildId,
|
||||
defaultMeta: options?.defaultMeta,
|
||||
metrics,
|
||||
},
|
||||
bodyDesc: `metrics: ${metrics
|
||||
|
|
25
packages/kbn-pm/dist/index.js
vendored
25
packages/kbn-pm/dist/index.js
vendored
|
@ -9010,6 +9010,9 @@ var _ci_stats_config = __webpack_require__(218);
|
|||
const BASE_URL = 'https://ci-stats.kibana.dev';
|
||||
|
||||
class CiStatsReporter {
|
||||
/**
|
||||
* Create a CiStatsReporter by inspecting the ENV for the necessary config
|
||||
*/
|
||||
static fromEnv(log) {
|
||||
return new CiStatsReporter((0, _ci_stats_config.parseConfig)(log), log);
|
||||
}
|
||||
|
@ -9018,10 +9021,21 @@ class CiStatsReporter {
|
|||
this.config = config;
|
||||
this.log = log;
|
||||
}
|
||||
/**
|
||||
* Determine if CI_STATS is explicitly disabled by the environment. To determine
|
||||
* if the CiStatsReporter has enough information in the environment to send metrics
|
||||
* for builds use #hasBuildConfig().
|
||||
*/
|
||||
|
||||
|
||||
isEnabled() {
|
||||
return process.env.CI_STATS_DISABLED !== 'true';
|
||||
}
|
||||
/**
|
||||
* Determines if the CiStatsReporter is disabled by the environment, or properly
|
||||
* configured and able to send stats
|
||||
*/
|
||||
|
||||
|
||||
hasBuildConfig() {
|
||||
var _this$config, _this$config2;
|
||||
|
@ -9069,7 +9083,7 @@ class CiStatsReporter {
|
|||
|
||||
const memUsage = process.memoryUsage();
|
||||
const isElasticCommitter = email && email.endsWith('@elastic.co') ? true : false;
|
||||
const defaultMetadata = {
|
||||
const defaultMeta = {
|
||||
kibanaUuid,
|
||||
isElasticCommitter,
|
||||
committerHash: email ? _crypto.default.createHash('sha256').update(email).digest('hex').substring(0, 20) : undefined,
|
||||
|
@ -9090,15 +9104,15 @@ class CiStatsReporter {
|
|||
osRelease: _os.default.release(),
|
||||
totalMem: _os.default.totalmem()
|
||||
};
|
||||
this.log.debug('CIStatsReporter committerHash: %s', defaultMetadata.committerHash);
|
||||
this.log.debug('CIStatsReporter committerHash: %s', defaultMeta.committerHash);
|
||||
return await this.req({
|
||||
auth: !!buildId,
|
||||
path: '/v1/timings',
|
||||
body: {
|
||||
buildId,
|
||||
upstreamBranch,
|
||||
timings,
|
||||
defaultMetadata
|
||||
defaultMeta,
|
||||
timings
|
||||
},
|
||||
bodyDesc: timings.length === 1 ? `${timings.length} timing` : `${timings.length} timings`
|
||||
});
|
||||
|
@ -9109,7 +9123,7 @@ class CiStatsReporter {
|
|||
*/
|
||||
|
||||
|
||||
async metrics(metrics) {
|
||||
async metrics(metrics, options) {
|
||||
var _this$config4;
|
||||
|
||||
if (!this.hasBuildConfig()) {
|
||||
|
@ -9127,6 +9141,7 @@ class CiStatsReporter {
|
|||
path: '/v1/metrics',
|
||||
body: {
|
||||
buildId,
|
||||
defaultMeta: options === null || options === void 0 ? void 0 : options.defaultMeta,
|
||||
metrics
|
||||
},
|
||||
bodyDesc: `metrics: ${metrics.map(({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue