Skip to content

Commit

Permalink
Merge branch 'master' into alert-status-refresh-pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 12, 2021
2 parents 9239483 + c3f1e0d commit 8cf6f6d
Show file tree
Hide file tree
Showing 122 changed files with 1,686 additions and 1,379 deletions.
51 changes: 44 additions & 7 deletions packages/kbn-dev-utils/src/ci_stats_reporter/ci_stats_reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -127,16 +163,16 @@ 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,
path: '/v1/timings',
body: {
buildId,
upstreamBranch,
defaultMeta,
timings,
defaultMetadata,
},
bodyDesc: timings.length === 1 ? `${timings.length} timing` : `${timings.length} timings`,
});
Expand All @@ -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;
}
Expand All @@ -162,6 +198,7 @@ export class CiStatsReporter {
path: '/v1/metrics',
body: {
buildId,
defaultMeta: options?.defaultMeta,
metrics,
},
bodyDesc: `metrics: ${metrics
Expand Down
25 changes: 20 additions & 5 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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`
});
Expand All @@ -9109,7 +9123,7 @@ class CiStatsReporter {
*/


async metrics(metrics) {
async metrics(metrics, options) {
var _this$config4;

if (!this.hasBuildConfig()) {
Expand All @@ -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(({
Expand Down
61 changes: 54 additions & 7 deletions src/plugins/custom_integrations/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
export const PLUGIN_ID = 'customIntegrations';
export const PLUGIN_NAME = 'customIntegrations';

export interface IntegrationCategoryCount {
count: number;
id: IntegrationCategory;
}

/**
* A map of category names and their corresponding titles.
*/
// TODO: consider i18n
export const INTEGRATION_CATEGORY_DISPLAY = {
// Known EPR
aws: 'AWS',
azure: 'Azure',
cloud: 'Cloud',
Expand Down Expand Up @@ -49,13 +47,62 @@ export const INTEGRATION_CATEGORY_DISPLAY = {
updates_available: 'Updates available',
};

/**
* A category applicable to an Integration.
*/
export type IntegrationCategory = keyof typeof INTEGRATION_CATEGORY_DISPLAY;

/**
* The list of all available categories.
*/
// This `as` is necessary, as Object.keys cannot be strongly typed.
// see: https://github.com/Microsoft/TypeScript/issues/12870
export const category = Object.keys(INTEGRATION_CATEGORY_DISPLAY) as IntegrationCategory[];

/**
* An object containing the id of an `IntegrationCategory` and the count of all Integrations in that category.
*/
export interface IntegrationCategoryCount {
count: number;
id: IntegrationCategory;
}

/**
* A map of shipper names and their corresponding titles.
*/
// TODO: consider i18n
export const SHIPPER_DISPLAY = {
beats: 'Beats',
language_clients: 'Language clients',
other: 'Other',
sample_data: 'Sample data',
tests: 'Tests',
tutorial: 'Tutorials',
};

/**
* A shipper-- an internal or external system capable of storing data in ES/Kibana-- applicable to an Integration.
*/
export type Shipper = keyof typeof SHIPPER_DISPLAY;

/**
* The list of all known shippers.
*/
// This `as` is necessary, as Object.keys cannot be strongly typed.
// see: https://github.com/Microsoft/TypeScript/issues/12870
export const shipper = Object.keys(SHIPPER_DISPLAY) as Shipper[];

/**
* An icon representing an Integration.
*/
export interface CustomIntegrationIcon {
src: string;
type: 'eui' | 'svg';
}

/**
* A definition of a dataintegration, which can be registered with Kibana.
*/
export interface CustomIntegration {
id: string;
title: string;
Expand All @@ -65,7 +112,7 @@ export interface CustomIntegration {
isBeta: boolean;
icons: CustomIntegrationIcon[];
categories: IntegrationCategory[];
shipper: string;
shipper: Shipper;
eprOverlap?: string; // name of the equivalent Elastic Agent integration in EPR. e.g. a beat module can correspond to an EPR-package, or an APM-tutorial. When completed, Integrations-UX can preferentially show the EPR-package, rather than the custom-integration
}

Expand Down
7 changes: 2 additions & 5 deletions src/plugins/data/common/search/aggs/agg_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ import type { SerializableRecord } from '@kbn/utility-types';
import { Assign, Ensure } from '@kbn/utility-types';

import { ISearchOptions, ISearchSource } from 'src/plugins/data/public';
import {
ExpressionAstExpression,
ExpressionAstArgument,
SerializedFieldFormat,
} from 'src/plugins/expressions/common';
import { ExpressionAstExpression, ExpressionAstArgument } from 'src/plugins/expressions/common';
import type { SerializedFieldFormat } from 'src/plugins/field_formats/common';

import { IAggType } from './agg_type';
import { writeParams } from './agg_params';
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/common/search/aggs/agg_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { constant, noop, identity } from 'lodash';
import { i18n } from '@kbn/i18n';

import { ISearchSource } from 'src/plugins/data/public';
import { DatatableColumnType, SerializedFieldFormat } from 'src/plugins/expressions/common';
import { DatatableColumnType } from 'src/plugins/expressions/common';
import type { RequestAdapter } from 'src/plugins/inspector/common';
import type { SerializedFieldFormat } from 'src/plugins/field_formats/common';

import { estypes } from '@elastic/elasticsearch';
import { initParams } from './agg_params';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
/* eslint-disable max-classes-per-file */
import { i18n } from '@kbn/i18n';

import { SerializedFieldFormat } from 'src/plugins/expressions/common/types';
import {
FieldFormat,
FieldFormatInstanceType,
FieldFormatsContentType,
IFieldFormat,
SerializedFieldFormat,
} from '../../../../../field_formats/common';
import { DateRange } from '../../expressions';
import { convertDateRangeToString } from '../buckets/lib/date_range';
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/data_views/common/data_views/data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import { IIndexPattern, IFieldType } from '../../common';
import { DataViewField, IIndexPatternFieldList, fieldList } from '../fields';
import { formatHitProvider } from './format_hit';
import { flattenHitWrapper } from './flatten_hit';
import { FieldFormatsStartCommon, FieldFormat } from '../../../field_formats/common';
import {
FieldFormatsStartCommon,
FieldFormat,
SerializedFieldFormat,
} from '../../../field_formats/common';
import { DataViewSpec, TypeMeta, SourceFilter, DataViewFieldMap } from '../types';
import { SerializedFieldFormat } from '../../../expressions/common';

interface DataViewDeps {
spec?: DataViewSpec;
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/data_views/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import type { SavedObject } from 'src/core/server';
import { KBN_FIELD_TYPES } from '@kbn/field-types';
import { IFieldType } from './fields';
import { RUNTIME_FIELD_TYPES } from './constants';
import { SerializedFieldFormat } from '../../expressions/common';
import { DataViewField } from './fields';
import { FieldFormat } from '../../field_formats/common';
import { FieldFormat, SerializedFieldFormat } from '../../field_formats/common';

export type FieldFormatMap = Record<string, SerializedFieldFormat>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const indexPattern = {
getFieldByName: (name: string) => fields.getByName(name),
timeFieldName: 'timestamp',
getFormatterForField: () => ({ convert: () => 'formatted' }),
isTimeNanosBased: () => false,
popularizeField: () => {},
} as unknown as IndexPattern;

indexPattern.flattenHit = indexPatterns.flattenHitWrapper(indexPattern, indexPattern.metaFields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const mockNavigationPlugin = { ui: { TopNavMenu: mockTopNavMenu } };
describe('ContextApp test', () => {
const defaultProps = {
indexPattern: indexPatternMock,
indexPatternId: 'the-index-pattern-id',
anchorId: 'mocked_anchor_id',
};

Expand Down
Loading

0 comments on commit 8cf6f6d

Please sign in to comment.