Skip to content

Commit

Permalink
[7.x] [Usage Collection] [schema] static_telemetry (#77902) (#78396)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
afharo and elasticmachine committed Sep 24, 2020
1 parent 2ff1156 commit d419d88
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .telemetryrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"src/plugins/testbed/",
"src/plugins/kibana_utils/",
"src/plugins/kibana_usage_collection/server/collectors/management/telemetry_management_collector.ts",
"src/plugins/kibana_usage_collection/server/collectors/ui_metric/telemetry_ui_metric_collector.ts",
"src/plugins/telemetry/server/collectors/usage/telemetry_usage_collector.ts"
"src/plugins/kibana_usage_collection/server/collectors/ui_metric/telemetry_ui_metric_collector.ts"
]
}
]
115 changes: 115 additions & 0 deletions src/plugins/telemetry/schema/oss_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,121 @@
}
}
},
"static_telemetry": {
"properties": {
"ece": {
"properties": {
"kb_uuid": {
"type": "keyword"
},
"es_uuid": {
"type": "keyword"
},
"account_id": {
"type": "keyword"
},
"license": {
"properties": {
"uuid": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"issued_to": {
"type": "text"
},
"issuer": {
"type": "text"
},
"issue_date_in_millis": {
"type": "long"
},
"start_date_in_millis": {
"type": "long"
},
"expiry_date_in_millis": {
"type": "long"
},
"max_resource_units": {
"type": "long"
}
}
}
}
},
"ess": {
"properties": {
"kb_uuid": {
"type": "keyword"
},
"es_uuid": {
"type": "keyword"
},
"account_id": {
"type": "keyword"
},
"license": {
"properties": {
"uuid": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"issued_to": {
"type": "text"
},
"issuer": {
"type": "text"
},
"issue_date_in_millis": {
"type": "long"
},
"start_date_in_millis": {
"type": "long"
},
"expiry_date_in_millis": {
"type": "long"
},
"max_resource_units": {
"type": "long"
}
}
}
}
},
"eck": {
"properties": {
"operator_uuid": {
"type": "keyword"
},
"operator_roles": {
"type": "keyword"
},
"custom_operator_namespace": {
"type": "boolean"
},
"distribution": {
"type": "text"
},
"build": {
"properties": {
"hash": {
"type": "text"
},
"date": {
"type": "date"
},
"version": {
"type": "keyword"
}
}
}
}
}
}
},
"tsvb-validation": {
"properties": {
"failed_validations": {
Expand Down
58 changes: 58 additions & 0 deletions src/plugins/telemetry/server/collectors/usage/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { MakeSchemaFrom } from 'src/plugins/usage_collection/server';
import { LicenseUsage, StaticTelemetryUsage } from './telemetry_usage_collector';

const licenseSchema: MakeSchemaFrom<LicenseUsage> = {
uuid: { type: 'keyword' },
type: { type: 'keyword' },
issued_to: { type: 'text' },
issuer: { type: 'text' },
issue_date_in_millis: { type: 'long' },
start_date_in_millis: { type: 'long' },
expiry_date_in_millis: { type: 'long' },
max_resource_units: { type: 'long' },
};

export const staticTelemetrySchema: MakeSchemaFrom<Required<StaticTelemetryUsage>> = {
ece: {
kb_uuid: { type: 'keyword' },
es_uuid: { type: 'keyword' },
account_id: { type: 'keyword' },
license: licenseSchema,
},
ess: {
kb_uuid: { type: 'keyword' },
es_uuid: { type: 'keyword' },
account_id: { type: 'keyword' },
license: licenseSchema,
},
eck: {
operator_uuid: { type: 'keyword' },
operator_roles: { type: 'keyword' },
custom_operator_namespace: { type: 'boolean' },
distribution: { type: 'text' },
build: {
hash: { type: 'text' },
date: { type: 'date' },
version: { type: 'keyword' },
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { TelemetryConfigType } from '../../config';

// look for telemetry.yml in the same places we expect kibana.yml
import { ensureDeepObject } from './ensure_deep_object';
import { staticTelemetrySchema } from './schema';

/**
* The maximum file size before we ignore it (note: this limit is arbitrary).
Expand Down Expand Up @@ -60,10 +61,12 @@ export function isFileReadable(path: string): boolean {
* @param configPath The config file path.
* @returns The unmodified JSON object if the file exists and is a valid YAML file.
*/
export async function readTelemetryFile(path: string): Promise<object | undefined> {
export async function readTelemetryFile<T extends object>(
configPath: string
): Promise<T | undefined> {
try {
if (isFileReadable(path)) {
const yaml = readFileSync(path);
if (isFileReadable(configPath)) {
const yaml = readFileSync(configPath);
const data = safeLoad(yaml.toString());

// don't bother returning empty objects
Expand All @@ -79,18 +82,56 @@ export async function readTelemetryFile(path: string): Promise<object | undefine
return undefined;
}

export interface LicenseUsage {
uuid: string;
type: string;
issued_to: string;
issuer: string;
issue_date_in_millis: number;
start_date_in_millis: number;
expiry_date_in_millis: number;
max_resource_units: number;
}

export interface StaticTelemetryUsage {
ece?: {
kb_uuid: string;
es_uuid: string;
account_id: string;
license: LicenseUsage;
};
ess?: {
kb_uuid: string;
es_uuid: string;
account_id: string;
license: LicenseUsage;
};
eck?: {
operator_uuid: string;
operator_roles: string;
custom_operator_namespace: boolean;
distribution: string;
build: {
hash: string;
date: string;
version: string;
};
};
}

export function createTelemetryUsageCollector(
usageCollection: UsageCollectionSetup,
getConfigPathFn: () => Promise<string>
) {
return usageCollection.makeUsageCollector({
return usageCollection.makeUsageCollector<StaticTelemetryUsage | undefined>({
type: 'static_telemetry',
isReady: () => true,
fetch: async () => {
const configPath = await getConfigPathFn();
const telemetryPath = join(dirname(configPath), 'telemetry.yml');
return await readTelemetryFile(telemetryPath);
},
schema: staticTelemetrySchema,
});
}

Expand Down

0 comments on commit d419d88

Please sign in to comment.