Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into refactor/timelines-…
Browse files Browse the repository at this point in the history
…delete-cases-dead-code
  • Loading branch information
Esteban Beltran committed Mar 7, 2022
2 parents 4c7c45b + a79562a commit 91fe9da
Show file tree
Hide file tree
Showing 186 changed files with 3,304 additions and 3,724 deletions.
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ x-pack/plugins/session_view @elastic/awp-platform
# Security Asset Management
/x-pack/plugins/osquery @elastic/security-asset-management

# Cloud Posture Security
/x-pack/plugins/cloud_security_posture/ @elastic/cloud-posture-security
# Cloud Security Posture
/x-pack/plugins/cloud_security_posture/ @elastic/cloud-security-posture-control-plane

# Design (at the bottom for specificity of SASS files)
**/*.scss @elastic/kibana-design
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function DevToolsSettingsModal(props: Props) {
const [fields, setFields] = useState(props.settings.autocomplete.fields);
const [indices, setIndices] = useState(props.settings.autocomplete.indices);
const [templates, setTemplates] = useState(props.settings.autocomplete.templates);
const [dataStreams, setDataStreams] = useState(props.settings.autocomplete.dataStreams);
const [polling, setPolling] = useState(props.settings.polling);
const [pollInterval, setPollInterval] = useState(props.settings.pollInterval);
const [tripleQuotes, setTripleQuotes] = useState(props.settings.tripleQuotes);
Expand Down Expand Up @@ -97,12 +98,20 @@ export function DevToolsSettingsModal(props: Props) {
}),
stateSetter: setTemplates,
},
{
id: 'dataStreams',
label: i18n.translate('console.settingsPage.dataStreamsLabelText', {
defaultMessage: 'Data streams',
}),
stateSetter: setDataStreams,
},
];

const checkboxIdToSelectedMap = {
fields,
indices,
templates,
dataStreams,
};

const onAutocompleteChange = (optionId: AutocompleteOptions) => {
Expand All @@ -120,6 +129,7 @@ export function DevToolsSettingsModal(props: Props) {
fields,
indices,
templates,
dataStreams,
},
polling,
pollInterval,
Expand Down Expand Up @@ -170,6 +180,7 @@ export function DevToolsSettingsModal(props: Props) {
fields,
indices,
templates,
dataStreams,
});
}}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { getDataStreams } from '../../mappings/mappings';
import { ListComponent } from './list_component';

export class DataStreamAutocompleteComponent extends ListComponent {
constructor(name, parent, multiValued) {
super(name, getDataStreams, parent, multiValued);
}

getContextKey() {
return 'data_stream';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export { IdAutocompleteComponent } from './id_autocomplete_component';
export { UsernameAutocompleteComponent } from './username_autocomplete_component';
export { IndexTemplateAutocompleteComponent } from './index_template_autocomplete_component';
export { ComponentTemplateAutocompleteComponent } from './component_template_autocomplete_component';
export { DataStreamAutocompleteComponent } from './data_stream_autocomplete_component';
export * from './legacy';
4 changes: 4 additions & 0 deletions src/plugins/console/public/lib/kb/kb.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
UsernameAutocompleteComponent,
IndexTemplateAutocompleteComponent,
ComponentTemplateAutocompleteComponent,
DataStreamAutocompleteComponent,
} from '../autocomplete/components';

import $ from 'jquery';
Expand Down Expand Up @@ -94,6 +95,9 @@ const parametrizedComponentFactories = {
component_template: function (name, parent) {
return new ComponentTemplateAutocompleteComponent(name, parent);
},
data_stream: function (name, parent) {
return new DataStreamAutocompleteComponent(name, parent);
},
};

export function getUnmatchedEndpointComponents() {
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/console/public/lib/mappings/mapping.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,13 @@ describe('Mappings', () => {
expect(mappings.getIndexTemplates()).toEqual(expectedResult);
expect(mappings.getComponentTemplates()).toEqual(expectedResult);
});

test('Data streams', function () {
mappings.loadDataStreams({
data_streams: [{ name: 'test_index1' }, { name: 'test_index2' }, { name: 'test_index3' }],
});

const expectedResult = ['test_index1', 'test_index2', 'test_index3'];
expect(mappings.getDataStreams()).toEqual(expectedResult);
});
});
24 changes: 21 additions & 3 deletions src/plugins/console/public/lib/mappings/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let perAliasIndexes = [];
let legacyTemplates = [];
let indexTemplates = [];
let componentTemplates = [];
let dataStreams = [];

const mappingObj = {};

Expand Down Expand Up @@ -60,6 +61,10 @@ export function getComponentTemplates() {
return [...componentTemplates];
}

export function getDataStreams() {
return [...dataStreams];
}

export function getFields(indices, types) {
// get fields for indices and types. Both can be a list, a string or null (meaning all).
let ret = [];
Expand Down Expand Up @@ -128,7 +133,9 @@ export function getTypes(indices) {
export function getIndices(includeAliases) {
const ret = [];
$.each(perIndexTypes, function (index) {
ret.push(index);
if (!index.startsWith('.ds')) {
ret.push(index);
}
});
if (typeof includeAliases === 'undefined' ? true : includeAliases) {
$.each(perAliasIndexes, function (alias) {
Expand Down Expand Up @@ -204,6 +211,10 @@ export function loadComponentTemplates(data) {
componentTemplates = (data.component_templates ?? []).map(({ name }) => name);
}

export function loadDataStreams(data) {
dataStreams = (data.data_streams ?? []).map(({ name }) => name);
}

export function loadMappings(mappings) {
perIndexTypes = {};

Expand Down Expand Up @@ -265,6 +276,7 @@ function retrieveSettings(settingsKey, settingsToRetrieve) {
legacyTemplates: '_template',
indexTemplates: '_index_template',
componentTemplates: '_component_template',
dataStreams: '_data_stream',
};

// Fetch autocomplete info if setting is set to true, and if user has made changes.
Expand Down Expand Up @@ -326,14 +338,16 @@ export function retrieveAutoCompleteInfo(settings, settingsToRetrieve) {
'componentTemplates',
templatesSettingToRetrieve
);
const dataStreamsPromise = retrieveSettings('dataStreams', settingsToRetrieve);

$.when(
mappingPromise,
aliasesPromise,
legacyTemplatesPromise,
indexTemplatesPromise,
componentTemplatesPromise
).done((mappings, aliases, legacyTemplates, indexTemplates, componentTemplates) => {
componentTemplatesPromise,
dataStreamsPromise
).done((mappings, aliases, legacyTemplates, indexTemplates, componentTemplates, dataStreams) => {
let mappingsResponse;
try {
if (mappings && mappings.length) {
Expand Down Expand Up @@ -365,6 +379,10 @@ export function retrieveAutoCompleteInfo(settings, settingsToRetrieve) {
loadComponentTemplates(JSON.parse(componentTemplates[0]));
}

if (dataStreams) {
loadDataStreams(JSON.parse(dataStreams[0]));
}

if (mappings && aliases) {
// Trigger an update event with the mappings, aliases
$(mappingObj).trigger('update', [mappingsResponse, aliases[0]]);
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/console/public/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const DEFAULT_SETTINGS = Object.freeze({
pollInterval: 60000,
tripleQuotes: true,
wrapMode: true,
autocomplete: Object.freeze({ fields: true, indices: true, templates: true }),
autocomplete: Object.freeze({ fields: true, indices: true, templates: true, dataStreams: true }),
historyDisabled: false,
});

Expand All @@ -25,6 +25,7 @@ export interface DevToolsSettings {
fields: boolean;
indices: boolean;
templates: boolean;
dataStreams: boolean;
};
polling: boolean;
pollInterval: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"DELETE"
],
"patterns": [
"_data_stream/{name}"
"_data_stream/{data_stream}"
],
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
],
"patterns": [
"_data_stream",
"_data_stream/{name}"
"_data_stream/{name}",
"{data_stream}"
],
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html"
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data_views/common/data_views/data_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ export class DataViewsService {
);

if (!savedObject.version) {
throw new SavedObjectNotFound(DATA_VIEW_SAVED_OBJECT_TYPE, id, 'management/kibana/dataViews');
throw new SavedObjectNotFound('data view', id, 'management/kibana/dataViews');
}

return this.initFromSavedObject(savedObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ describe('DependencyManager', () => {
expect(DependencyManager.orderDependencies(graph)).toEqual(sortedTopology);
});

it('should include final vertex if it has dependencies', () => {
const graph = {
A: [],
B: [],
C: ['A', 'B'],
};
const sortedTopology = ['A', 'B', 'C'];
expect(DependencyManager.orderDependencies(graph)).toEqual(sortedTopology);
});

it('orderDependencies. Should return base topology if no depended vertices', () => {
const graph = {
N: [],
Expand All @@ -34,22 +44,34 @@ describe('DependencyManager', () => {
expect(DependencyManager.orderDependencies(graph)).toEqual(sortedTopology);
});

it('orderDependencies. Should detect circular dependencies and throw error with path', () => {
const graph = {
N: ['R'],
R: ['A'],
A: ['B'],
B: ['C'],
C: ['D'],
D: ['E'],
E: ['F'],
F: ['L'],
L: ['G'],
G: ['N'],
};
const circularPath = ['N', 'R', 'A', 'B', 'C', 'D', 'E', 'F', 'L', 'G', 'N'].join(' -> ');
const errorMessage = `Circular dependency detected while setting up services: ${circularPath}`;
describe('circular dependencies', () => {
it('should detect circular dependencies and throw error with path', () => {
const graph = {
N: ['R'],
R: ['A'],
A: ['B'],
B: ['C'],
C: ['D'],
D: ['E'],
E: ['F'],
F: ['L'],
L: ['G'],
G: ['N'],
};
const circularPath = ['G', 'L', 'F', 'E', 'D', 'C', 'B', 'A', 'R', 'N'].join(' -> ');
const errorMessage = `Circular dependency detected while setting up services: ${circularPath}`;

expect(() => DependencyManager.orderDependencies(graph)).toThrowError(errorMessage);
});

it('should detect circular dependency if circular reference is the first dependency for a vertex', () => {
const graph = {
A: ['B'],
B: ['A', 'C'],
C: [],
};

expect(() => DependencyManager.orderDependencies(graph)).toThrowError(errorMessage);
expect(() => DependencyManager.orderDependencies(graph)).toThrow();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export class DependencyManager {
return cycleInfo;
}

return DependencyManager.sortVerticesFrom(srcVertex, graph, sortedVertices, {}, {});
return DependencyManager.sortVerticesFrom(
srcVertex,
graph,
sortedVertices,
{},
{},
cycleInfo
);
}, DependencyManager.createCycleInfo());
}

Expand All @@ -58,32 +65,41 @@ export class DependencyManager {
graph: Graph<T>,
sortedVertices: Set<T>,
visited: BreadCrumbs = {},
inpath: BreadCrumbs = {}
inpath: BreadCrumbs = {},
cycle: CycleDetectionResult<T>
): CycleDetectionResult<T> {
visited[srcVertex] = true;
inpath[srcVertex] = true;
const cycleInfo = graph[srcVertex]?.reduce<CycleDetectionResult<T> | undefined>(
(info, vertex) => {
if (inpath[vertex]) {
const path = (Object.keys(inpath) as T[]).filter(
(visitedVertex) => inpath[visitedVertex]
);
return DependencyManager.createCycleInfo([...path, vertex], true);
} else if (!visited[vertex]) {
return DependencyManager.sortVerticesFrom(vertex, graph, sortedVertices, visited, inpath);
}
return info;
},
undefined
);

const vertexEdges =
graph[srcVertex] === undefined || graph[srcVertex] === null ? [] : graph[srcVertex];

cycle = vertexEdges!.reduce<CycleDetectionResult<T>>((info, vertex) => {
if (inpath[vertex]) {
return { ...info, hasCycle: true };
} else if (!visited[vertex]) {
return DependencyManager.sortVerticesFrom(
vertex,
graph,
sortedVertices,
visited,
inpath,
info
);
}
return info;
}, cycle);

inpath[srcVertex] = false;

if (!sortedVertices.has(srcVertex)) {
sortedVertices.add(srcVertex);
}

return cycleInfo ?? DependencyManager.createCycleInfo<T>([...sortedVertices]);
return {
...cycle,
path: [...sortedVertices],
};
}

private static createCycleInfo<T extends GraphVertex = GraphVertex>(
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/vis_types/xy/public/config/get_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ScaleContinuousType } from '@elastic/charts';
import { Fit, ScaleContinuousType } from '@elastic/charts';

import { Datatable } from '../../../../expressions/public';
import { BUCKET_TYPES } from '../../../../data/public';
Expand Down Expand Up @@ -92,7 +92,7 @@ export function getConfig(
return {
// NOTE: downscale ratio to match current vislib implementation
markSizeRatio: radiusRatio * 0.6,
fittingFunction,
fittingFunction: fittingFunction ?? Fit.Linear,
fillOpacity,
detailedTooltip,
orderBucketsBySum,
Expand Down
Loading

0 comments on commit 91fe9da

Please sign in to comment.