Skip to content

Commit

Permalink
Merge branch 'master' into alerting/consumer-based-rbac
Browse files Browse the repository at this point in the history
* master:
  [Lens] Fitting functions (elastic#69820)
  [Telemetry] Add documentation about Application Usage (elastic#70624)
  [Ingest Manager] Improve agent unenrollment with unenroll action (elastic#70031)
  Handle timeouts on creating templates (elastic#70635)
  [Lens] Add ability to set colors for y-axis series (elastic#70311)
  [Uptime] Use elastic charts donut (elastic#70364)
  [Ingest Manager] Update registry URL to point to snapshot registry (elastic#70687)
  [Composable template] Create / Edit wizard (elastic#70220)
  [APM] Optimize services overview (elastic#69648)
  • Loading branch information
gmmorris committed Jul 3, 2020
2 parents f0f82f3 + bbda3f9 commit c426139
Show file tree
Hide file tree
Showing 119 changed files with 3,963 additions and 733 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { WithMultiContent, useMultiContentContext, HookProps } from '../multi_co

export interface Props<T extends object> {
onSave: (data: T) => void | Promise<void>;
children: JSX.Element | JSX.Element[];
children: JSX.Element | Array<JSX.Element | null | false>;
isEditing?: boolean;
defaultActiveStep?: number;
defaultValue?: HookProps<T>['defaultValue'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function useMultiContentContext<T extends object = { [key: string]: any }
*
* @param contentId The content id to be added to the "contents" map
*/
export function useContent<T extends object = { [key: string]: any }>(contentId: keyof T) {
export function useContent<T extends object, K extends keyof T>(contentId: K) {
const { updateContentAt, saveSnapshotAndRemoveContent, getData } = useMultiContentContext<T>();

const updateContent = useCallback(
Expand All @@ -71,8 +71,11 @@ export function useContent<T extends object = { [key: string]: any }>(contentId:
};
}, [contentId, saveSnapshotAndRemoveContent]);

const data = getData();
const defaultValue = data[contentId];

return {
defaultValue: getData()[contentId]!,
defaultValue,
updateContent,
getData,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export function useMultiContent<T extends object>({
* Validate the multi-content active content(s) in the DOM
*/
const validate = useCallback(async () => {
if (Object.keys(contents.current).length === 0) {
return Boolean(validation.isValid);
}

const updatedValidation = {} as { [key in keyof T]?: boolean | undefined };

for (const [id, _content] of Object.entries(contents.current)) {
Expand Down
7 changes: 2 additions & 5 deletions src/plugins/es_ui_shared/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* In the future, each top level folder should be exported like that to avoid naming collision
*/
import * as Forms from './forms';
import * as Monaco from './monaco';

export { JsonEditor, OnJsonEditorUpdateHandler } from './components/json_editor';

Expand Down Expand Up @@ -53,10 +54,6 @@ export {
expandLiteralStrings,
} from './console_lang';

import * as Monaco from './monaco';

export { Monaco };

export {
AuthorizationContext,
AuthorizationProvider,
Expand All @@ -69,7 +66,7 @@ export {
useAuthorizationContext,
} from './authorization';

export { Forms };
export { Monaco, Forms };

/** dummy plugin, we just want esUiShared to have its own bundle */
export function plugin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import { ValidationFunc } from '../../hook_form_lib';
import { isJSON } from '../../../validators/string';
import { ERROR_CODE } from './types';

export const isJsonField = (message: string) => (
...args: Parameters<ValidationFunc>
): ReturnType<ValidationFunc<any, ERROR_CODE>> => {
export const isJsonField = (
message: string,
{ allowEmptyString = false }: { allowEmptyString?: boolean } = {}
) => (...args: Parameters<ValidationFunc>): ReturnType<ValidationFunc<any, ERROR_CODE>> => {
const [{ value }] = args;

if (typeof value !== 'string') {
if (typeof value !== 'string' || (allowEmptyString && value.trim() === '')) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kibana_usage_collection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This plugin registers the basic usage collectors from Kibana:

- Application Usage
- [Application Usage](./server/collectors/application_usage/README.md)
- UI Metrics
- Ops stats
- Number of Saved Objects per type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Application Usage

This collector reports the number of general clicks and minutes on screen for each registered application in Kibana.

The final payload matches the following contract:

```JSON
{
"application_usage": {
"application_ID": {
"clicks_7_days": 10,
"clicks_30_days": 100,
"clicks_90_days": 300,
"clicks_total": 600,
"minutes_on_screen_7_days": 10.40,
"minutes_on_screen_30_days": 20.0,
"minutes_on_screen_90_days": 110.1,
"minutes_on_screen_total": 112.5
}
}
}
```

Where `application_ID` matches the `id` registered when calling the method `core.application.register`.
This collection occurs by default for every application registered via the mentioned method and there is no need to do anything else to enable it or _opt-in_ for your plugin.

**Note to maintainers in the Kibana repo:** At the moment of writing, the `usageCollector.schema` is not updated automatically ([#70622](https://github.com/elastic/kibana/issues/70622)) so, if you are adding a new app to Kibana, you'll need to give the Kibana Telemetry team a heads up to update the mappings in the Telemetry Cluster accordingly.

## Developer notes

In order to keep the count of the events, this collector uses 2 Saved Objects:

1. `application_usage_transactional`: It stores each individually reported event (up to 90 days old). Grouped by `timestamp` and `appId`.
2. `application_usage_totals`: It stores the sum of all the events older than 90 days old per `appId`.

Both of them use the shared fields `appId: 'keyword'`, `numberOfClicks: 'long'` and `minutesOnScreen: 'float'`. `application_usage_transactional` also stores `timestamp: { type: 'date' }`.
but they are currently not added in the mappings because we don't use them for search purposes, and we need to be thoughtful with the number of mapped fields in the SavedObjects index ([#43673](https://github.com/elastic/kibana/issues/43673)).
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ export function registerMappings(registerType: SavedObjectsServiceSetup['registe
hidden: false,
namespaceType: 'agnostic',
mappings: {
// Not indexing any of its contents because we use them "as-is" and don't search by these fields
// for more info, see the README.md for application_usage
dynamic: false,
properties: {
// Disabled the mapping of these fields since they are not searched and we need to reduce the amount of indexed fields (#43673)
// appId: { type: 'keyword' },
// numberOfClicks: { type: 'long' },
// minutesOnScreen: { type: 'float' },
},
properties: {},
},
});

Expand All @@ -53,10 +50,6 @@ export function registerMappings(registerType: SavedObjectsServiceSetup['registe
dynamic: false,
properties: {
timestamp: { type: 'date' },
// Disabled the mapping of these fields since they are not searched and we need to reduce the amount of indexed fields (#43673)
// appId: { type: 'keyword' },
// numberOfClicks: { type: 'long' },
// minutesOnScreen: { type: 'float' },
},
},
});
Expand Down
28 changes: 20 additions & 8 deletions x-pack/plugins/apm/common/projections/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,37 @@ import { rangeFilter } from '../utils/range_filter';

export function getServicesProjection({
setup,
noEvents,
}: {
setup: Setup & SetupTimeRange & SetupUIFilters;
noEvents?: boolean;
}) {
const { start, end, uiFiltersES, indices } = setup;

return {
index: [
indices['apm_oss.metricsIndices'],
indices['apm_oss.errorIndices'],
indices['apm_oss.transactionIndices'],
],
...(noEvents
? {}
: {
index: [
indices['apm_oss.metricsIndices'],
indices['apm_oss.errorIndices'],
indices['apm_oss.transactionIndices'],
],
}),
body: {
size: 0,
query: {
bool: {
filter: [
{
terms: { [PROCESSOR_EVENT]: ['transaction', 'error', 'metric'] },
},
...(noEvents
? []
: [
{
terms: {
[PROCESSOR_EVENT]: ['transaction', 'error', 'metric'],
},
},
]),
{ range: rangeFilter(start, end) },
...uiFiltersES,
],
Expand Down
14 changes: 14 additions & 0 deletions x-pack/plugins/apm/common/utils/array_union_to_callable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { ValuesType } from 'utility-types';

// work around a TypeScript limitation described in https://stackoverflow.com/posts/49511416

export const arrayUnionToCallable = <T extends any[]>(
array: T
): Array<ValuesType<T>> => {
return array;
};
104 changes: 104 additions & 0 deletions x-pack/plugins/apm/common/utils/join_by_key/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { joinByKey } from './';

describe('joinByKey', () => {
it('joins by a string key', () => {
const joined = joinByKey(
[
{
serviceName: 'opbeans-node',
avg: 10,
},
{
serviceName: 'opbeans-node',
count: 12,
},
{
serviceName: 'opbeans-java',
avg: 11,
},
{
serviceName: 'opbeans-java',
p95: 18,
},
],
'serviceName'
);

expect(joined.length).toBe(2);

expect(joined).toEqual([
{
serviceName: 'opbeans-node',
avg: 10,
count: 12,
},
{
serviceName: 'opbeans-java',
avg: 11,
p95: 18,
},
]);
});

it('joins by a record key', () => {
const joined = joinByKey(
[
{
key: {
serviceName: 'opbeans-node',
transactionName: '/api/opbeans-node',
},
avg: 10,
},
{
key: {
serviceName: 'opbeans-node',
transactionName: '/api/opbeans-node',
},
count: 12,
},
{
key: {
serviceName: 'opbeans-java',
transactionName: '/api/opbeans-java',
},
avg: 11,
},
{
key: {
serviceName: 'opbeans-java',
transactionName: '/api/opbeans-java',
},
p95: 18,
},
],
'key'
);

expect(joined.length).toBe(2);

expect(joined).toEqual([
{
key: {
serviceName: 'opbeans-node',
transactionName: '/api/opbeans-node',
},
avg: 10,
count: 12,
},
{
key: {
serviceName: 'opbeans-java',
transactionName: '/api/opbeans-java',
},
avg: 11,
p95: 18,
},
]);
});
});
48 changes: 48 additions & 0 deletions x-pack/plugins/apm/common/utils/join_by_key/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { UnionToIntersection, ValuesType } from 'utility-types';
import { isEqual } from 'lodash';

/**
* Joins a list of records by a given key. Key can be any type of value, from
* strings to plain objects, as long as it is present in all records. `isEqual`
* is used for comparing keys.
*
* UnionToIntersection is needed to get all keys of union types, see below for
* example.
*
const agentNames = [{ serviceName: '', agentName: '' }];
const transactionRates = [{ serviceName: '', transactionsPerMinute: 1 }];
const flattened = joinByKey(
[...agentNames, ...transactionRates],
'serviceName'
);
*/

type JoinedReturnType<
T extends Record<string, any>,
U extends UnionToIntersection<T>,
V extends keyof T & keyof U
> = Array<Partial<U> & Record<V, U[V]>>;

export function joinByKey<
T extends Record<string, any>,
U extends UnionToIntersection<T>,
V extends keyof T & keyof U
>(items: T[], key: V): JoinedReturnType<T, U, V> {
return items.reduce<JoinedReturnType<T, U, V>>((prev, current) => {
let item = prev.find((prevItem) => isEqual(prevItem[key], current[key]));

if (!item) {
item = { ...current } as ValuesType<JoinedReturnType<T, U, V>>;
prev.push(item);
} else {
Object.assign(item, current);
}

return prev;
}, []);
}
21 changes: 0 additions & 21 deletions x-pack/plugins/apm/common/utils/left_join.ts

This file was deleted.

Loading

0 comments on commit c426139

Please sign in to comment.