Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Usage Collection] [schema] static_telemetry #77902

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .telemetryrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"src/plugins/kibana_utils/",
"src/plugins/kibana_usage_collection/server/collectors/kibana/kibana_usage_collector.ts",
"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 @@ -1310,6 +1310,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> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using configPath rather than path now matches the function description, thanks for making them consistent. We could have gone either way here, either updating the param as is the case here or changing the description.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for noticing. I decided on the configPath side because path matches the 'path' library (and I tend to avoid it as a variable when possible).

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