Skip to content

Commit

Permalink
Merge branch 'main' into enable-func-test
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Feb 2, 2022
2 parents 3593ae2 + 2957036 commit 1aa8fc1
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 83 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@
"callsites": "^3.1.0",
"chai": "3.5.0",
"chance": "1.0.18",
"chromedriver": "^97.0.4",
"chromedriver": "^97.0.2",
"clean-webpack-plugin": "^3.0.0",
"cmd-shim": "^2.1.0",
"compression-webpack-plugin": "^4.0.0",
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/data/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ export type {
GetFieldsOptions,
GetFieldsOptionsTimePattern,
IDataViewsApiClient,
IIndexPatternsApiClient,
SavedObject,
AggregationRestrictions,
TypeMeta,
FieldSpecConflictDescriptions,
FieldSpecExportFmt,
FieldSpec,
DataViewFieldMap,
IndexPatternFieldMap,
DataViewSpec,
IndexPatternSpec,
SourceFilter,
IndexPatternExpressionType,
IndexPatternLoadStartDependencies,
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export type {
IFieldType,
IndexPatternAttributes,
AggregationRestrictions as IndexPatternAggRestrictions,
IndexPatternSpec,
IndexPatternLoadExpressionFunctionDefinition,
GetFieldsOptions,
AggregationRestrictions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface Props {
/**
* Handler for the "save" footer button
*/
onSave: (indexPatternSpec: DataViewSpec) => void;
onSave: (dataViewSpec: DataViewSpec) => void;
/**
* Handler for the "cancel" footer button
*/
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 @@ -367,7 +367,7 @@ export class DataViewsService {
/**
* Converts index pattern saved object to index pattern spec
* @param savedObject
* @returns IndexPatternSpec
* @returns DataViewSpec
*/

savedObjectToSpec = (savedObject: SavedObject<DataViewAttributes>): DataViewSpec => {
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/data_views/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ export type {
GetFieldsOptions,
GetFieldsOptionsTimePattern,
IDataViewsApiClient,
IIndexPatternsApiClient,
SavedObject,
AggregationRestrictions,
TypeMeta,
FieldSpecConflictDescriptions,
FieldSpecExportFmt,
FieldSpec,
DataViewFieldMap,
IndexPatternFieldMap,
DataViewSpec,
IndexPatternSpec,
SourceFilter,
} from './types';
export { DataViewType } from './types';
Expand Down
17 changes: 1 addition & 16 deletions src/plugins/data_views/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface RuntimeField {
/**
* @deprecated
* IIndexPattern allows for an IndexPattern OR an index pattern saved object
* Use IndexPattern or IndexPatternSpec instead
* Use DataView or DataViewSpec instead
*/
export interface IIndexPattern extends DataViewBase {
title: string;
Expand Down Expand Up @@ -145,11 +145,6 @@ export interface IDataViewsApiClient {
hasUserIndexPattern: () => Promise<boolean>;
}

/**
* @deprecated Use IDataViewsApiClient. All index pattern interfaces were renamed.
*/
export type IIndexPatternsApiClient = IDataViewsApiClient;

export type { SavedObject };

export type AggregationRestrictions = Record<
Expand Down Expand Up @@ -229,11 +224,6 @@ export interface FieldSpec extends DataViewFieldBase {

export type DataViewFieldMap = Record<string, FieldSpec>;

/**
* @deprecated Use DataViewFieldMap. All index pattern interfaces were renamed.
*/
export type IndexPatternFieldMap = DataViewFieldMap;

/**
* Static index pattern format
* Serialized data object, representing index pattern attributes and state
Expand All @@ -259,11 +249,6 @@ export interface DataViewSpec {
allowNoIndex?: boolean;
}

/**
* @deprecated Use DataViewSpec. All index pattern interfaces were renamed.
*/
export type IndexPatternSpec = DataViewSpec;

export interface SourceFilter {
value: string;
}
4 changes: 2 additions & 2 deletions src/plugins/data_views/server/index_patterns_api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import { ElasticsearchClient, SavedObjectsClientContract } from 'kibana/server';
import {
GetFieldsOptions,
IIndexPatternsApiClient,
GetFieldsOptionsTimePattern,
IDataViewsApiClient,
} from '../common/types';
import { DataViewMissingIndices } from '../common/lib';
import { IndexPatternsFetcher } from './fetcher';
import { hasUserIndexPattern } from './has_user_index_pattern';

export class IndexPatternsApiServer implements IIndexPatternsApiClient {
export class IndexPatternsApiServer implements IDataViewsApiClient {
esClient: ElasticsearchClient;
constructor(
elasticsearchClient: ElasticsearchClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const createDataView = async ({
return dataViewsService.createAndSave(spec, override, !refreshFields);
};

const indexPatternSpecSchema = schema.object({
const dataViewSpecSchema = schema.object({
title: schema.string(),
version: schema.maybe(schema.string()),
id: schema.maybe(schema.string()),
Expand Down Expand Up @@ -91,9 +91,8 @@ const registerCreateDataViewRouteFactory =
body: schema.object({
override: schema.maybe(schema.boolean({ defaultValue: false })),
refresh_fields: schema.maybe(schema.boolean({ defaultValue: false })),
data_view: serviceKey === SERVICE_KEY ? indexPatternSpecSchema : schema.never(),
index_pattern:
serviceKey === SERVICE_KEY_LEGACY ? indexPatternSpecSchema : schema.never(),
data_view: serviceKey === SERVICE_KEY ? dataViewSpecSchema : schema.never(),
index_pattern: serviceKey === SERVICE_KEY_LEGACY ? dataViewSpecSchema : schema.never(),
}),
},
},
Expand Down
6 changes: 3 additions & 3 deletions test/common/services/index_patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { FtrService } from '../ftr_provider_context';
import { IndexPatternSpec } from '../../../src/plugins/data/common';
import { DataViewSpec } from '../../../src/plugins/data/common';

export class IndexPatternsService extends FtrService {
private readonly kibanaServer = this.ctx.getService('kibanaServer');
Expand All @@ -18,9 +18,9 @@ export class IndexPatternsService extends FtrService {
async create(
indexPattern: { title: string },
{ override = false }: { override: boolean } = { override: false }
): Promise<IndexPatternSpec> {
): Promise<DataViewSpec> {
const response = await this.kibanaServer.request<{
index_pattern: IndexPatternSpec;
index_pattern: DataViewSpec;
}>({
path: '/api/index_patterns/index_pattern',
method: 'POST',
Expand Down
126 changes: 126 additions & 0 deletions x-pack/plugins/fleet/common/services/validate_package_policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,132 @@ describe('Fleet - validatePackagePolicy()', () => {
},
});
});

it('returns package policy validation error if input var does not exist', () => {
expect(
validatePackagePolicy(
{
description: 'Linux Metrics',
enabled: true,
inputs: [
{
enabled: true,
streams: [
{
data_stream: {
dataset: 'linux.memory',
type: 'metrics',
},
enabled: true,
},
],
type: 'linux/metrics',
vars: {
period: {
type: 'string',
value: '1s',
},
},
},
],
name: 'linux-3d13ada6-a9ae-46df-8e57-ff5050f4b671',
namespace: 'default',
output_id: '',
package: {
name: 'linux',
title: 'Linux Metrics',
version: '0.6.2',
},
policy_id: 'b25cb6e0-8347-11ec-96f9-6590c25bacf9',
},
{
...mockPackage,
name: 'linux',
policy_templates: [
{
name: 'system',
title: 'Linux kernel metrics',
description: 'Collect system metrics from Linux operating systems',
inputs: [
{
title: 'Collect system metrics from Linux instances',
vars: [
{
name: 'system.hostfs',
type: 'text',
title: 'Proc Filesystem Directory',
multi: false,
required: false,
show_user: true,
description: 'The proc filesystem base directory.',
},
],
type: 'system/metrics',
description:
'Collecting Linux entropy, Network Summary, RAID, service, socket, and users metrics',
},
{
title: 'Collect low-level system metrics from Linux instances',
vars: [],
type: 'linux/metrics',
description: 'Collecting Linux conntrack, ksm, pageinfo metrics.',
},
],
multiple: true,
},
],
data_streams: [
{
dataset: 'linux.memory',
package: 'linux',
path: 'memory',
streams: [
{
input: 'linux/metrics',
title: 'Linux memory metrics',
vars: [
{
name: 'period',
type: 'text',
title: 'Period',
multi: false,
required: true,
show_user: true,
default: '10s',
},
],
template_path: 'stream.yml.hbs',
description: 'Linux paging and memory management metrics',
},
],
title: 'Linux-only memory metrics',
release: 'experimental',
type: 'metrics',
},
],
},
safeLoad
)
).toEqual({
description: null,
inputs: {
'linux/metrics': {
streams: {
'linux.memory': {
vars: {
period: ['Period is required'],
},
},
},
vars: {
period: ['period var definition does not exist'],
},
},
},
name: null,
namespace: null,
});
});
});

describe('works for packages with multiple policy templates (aka integrations)', () => {
Expand Down
15 changes: 10 additions & 5 deletions x-pack/plugins/fleet/common/services/validate_package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const validatePackagePolicy = (
results[name] = input.enabled
? validatePackagePolicyConfig(
configEntry,
inputVarDefsByPolicyTemplateAndType[inputKey][name],
(inputVarDefsByPolicyTemplateAndType[inputKey] ?? {})[name],
name,
safeLoadYaml
)
Expand Down Expand Up @@ -210,10 +210,15 @@ export const validatePackagePolicyConfig = (
}

if (varDef === undefined) {
// eslint-disable-next-line no-console
console.debug(`No variable definition for ${varName} found`);

return null;
errors.push(
i18n.translate('xpack.fleet.packagePolicyValidation.nonExistentVarMessage', {
defaultMessage: '{varName} var definition does not exist',
values: {
varName,
},
})
);
return errors;
}

if (varDef.required) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import {
} from '../../lib/setup_mode';
import { SetupModeFeature } from '../../../common/enums';
import { AlertsDropdown } from '../../alerts/alerts_dropdown';
import { ActionMenu } from '../../components/action_menu';
import { useRequestErrorHandler } from '../hooks/use_request_error_handler';
import { HeaderMenuPortal } from '../../../../observability/public';
import { HeaderActionMenuContext } from '../../application/contexts/header_action_menu_context';

export interface TabMenuItem {
id: string;
Expand Down Expand Up @@ -53,6 +54,7 @@ export const PageTemplate: React.FC<PageTemplateProps> = ({
const history = useHistory();
const [hasError, setHasError] = useState(false);
const handleRequestError = useRequestErrorHandler();
const { setHeaderActionMenu, theme$ } = useContext(HeaderActionMenuContext);

const getPageDataResponseHandler = useCallback(
(result: any) => {
Expand Down Expand Up @@ -104,9 +106,11 @@ export const PageTemplate: React.FC<PageTemplateProps> = ({

return (
<div className="app-container" data-test-subj="monitoringAppContainer">
<ActionMenu>
<AlertsDropdown />
</ActionMenu>
{setHeaderActionMenu && theme$ && (
<HeaderMenuPortal setHeaderActionMenu={setHeaderActionMenu} theme$={theme$}>
<AlertsDropdown />
</HeaderMenuPortal>
)}
<MonitoringToolbar pageTitle={pageTitle} onRefresh={onRefresh} />
{tabs && (
<EuiTabs>
Expand Down
Loading

0 comments on commit 1aa8fc1

Please sign in to comment.