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

[Rename] kibana-usage-collection plugin #162

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kibana Usage Collection
# OpenSearch Dashboards Usage Collection

This plugin registers the basic usage collectors from Kibana:
This plugin registers the basic usage collectors from OpenSearch Dashboards:

- [Application Usage](./server/collectors/application_usage/README.md)
- UI Metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* under the License.
*/

export const PLUGIN_ID = 'kibanaUsageCollection';
export const PLUGIN_NAME = 'kibana_usage_collection';
export const PLUGIN_ID = 'opensearchDashboardsUsageCollection';
export const PLUGIN_NAME = 'opensearch_dashboards_usage_collection';

/**
* The type name used to publish Kibana usage stats in the formatted as bulk.
* The type name used to publish OpenSearch Dashboards usage stats in the formatted as bulk.
*/
export const KIBANA_STATS_TYPE = 'kibana_stats';
export const OPENSEARCH_DASHBOARDS_STATS_TYPE = 'opensearch_dashboards_stats';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "kibanaUsageCollection",
"version": "kibana",
"id": "opensearchDashboardsUsageCollection",
"version": "opensearchDashboards",
"server": true,
"ui": false,
"requiredPlugins": [
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Application Usage

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

The final payload matches the following contract:

Expand All @@ -24,7 +24,7 @@ The final payload matches the following contract:
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.
**Note to maintainers in the OpenSearch Dashboards 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 OpenSearch Dashboards, you'll need to give the OpenSearch Dashboards Telemetry team a heads up to update the mappings in the Telemetry Cluster accordingly.

## Developer notes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { ISavedObjectsRepository, SavedObject, Logger } from 'kibana/server';
import { ISavedObjectsRepository, SavedObject, Logger } from 'opensearch-dashboards/server';
import moment from 'moment';
import {
ApplicationUsageDaily,
Expand Down Expand Up @@ -81,7 +81,7 @@ export async function rollDailyData(logger: Logger, savedObjectsClient?: ISavedO
type: SAVED_OBJECTS_DAILY_TYPE,
id,
attributes,
version, // Providing version to ensure via conflict matching that only 1 Kibana instance (or interval) is taking care of the updates
version, // Providing version to ensure via conflict matching that only 1 OpenSearch Dashboards instance (or interval) is taking care of the updates
})),
{ overwrite: true }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { SavedObjectAttributes, SavedObjectsServiceSetup } from 'kibana/server';
import { SavedObjectAttributes, SavedObjectsServiceSetup } from 'opensearch-dashboards/server';

/**
* Used for accumulating the totals of all the stats older than 90d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const applicationUsageSchema = {
dev_tools: commonSchema,
discover: commonSchema,
home: commonSchema,
kibana: commonSchema, // It's a forward app so we'll likely never report it
opensearch_dashboards: commonSchema, // It's a forward app so we'll likely never report it
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this using '_' it looks like it's referring to the module so it should be opensearch-dashboards

Copy link
Contributor

Choose a reason for hiding this comment

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

I think trying to follow what other in below following.

management: commonSchema,
short_url_redirect: commonSchema, // It's a forward app so we'll likely never report it
timelion: commonSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import {
savedObjectsRepositoryMock,
loggingSystemMock,
elasticsearchServiceMock,
opensearchDashboardsServiceMock,
} from '../../../../../core/server/mocks';
import {
CollectorOptions,
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('telemetry_application_usage', () => {
const getUsageCollector = jest.fn();
const registerType = jest.fn();
const callCluster = jest.fn();
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
const esClient = opensearchDashboardsServiceMock.createClusterClient().asInternalUser;

beforeAll(() =>
registerApplicationUsageCollector(logger, usageCollectionMock, registerType, getUsageCollector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import moment from 'moment';
import { timer } from 'rxjs';
import { ISavedObjectsRepository, Logger, SavedObjectsServiceSetup } from 'kibana/server';
import { ISavedObjectsRepository, Logger, SavedObjectsServiceSetup } from 'opensearch-dashboards/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import {
ApplicationUsageDaily,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function getCoreUsageCollector(
isReady: () => typeof getCoreUsageDataService() !== 'undefined',
schema: {
config: {
elasticsearch: {
opensearch: {
sniffOnStart: { type: 'boolean' },
sniffIntervalMs: { type: 'long' },
sniffOnConnectionFault: { type: 'boolean' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
export { registerUiMetricUsageCollector } from './ui_metric';
export { registerManagementUsageCollector } from './management';
export { registerApplicationUsageCollector } from './application_usage';
export { registerKibanaUsageCollector } from './kibana';
export { registerOpenSearchDashboardsUsageCollector } from './opensearch_dashboards';
export { registerOpsStatsCollector } from './ops_stats';
export { registerCspCollector } from './csp';
export { registerCoreUsageCollector } from './core';
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { MakeSchemaFrom } from 'src/plugins/usage_collection/server';
import { UsageStats } from './telemetry_management_collector';

// Retrieved by changing all the current settings in Kibana (we'll need to revisit it in the future).
// Retrieved by changing all the current settings in OpenSearch Dashboards (we'll need to revisit it in the future).
// I would suggest we use flattened type for the mappings of this collector.
export const stackManagementSchema: MakeSchemaFrom<UsageStats> = {
'visualize:enableLabs': { type: 'boolean' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { IUiSettingsClient } from 'kibana/server';
import { IUiSettingsClient } from 'opensearch-dashboards/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { stackManagementSchema } from './schema';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('getSavedObjectsCounts', () => {
test('Get all the saved objects equal to 0 because no results were found', async () => {
const callCluster = jest.fn(() => ({}));

const results = await getSavedObjectsCounts(callCluster as any, '.kibana');
const results = await getSavedObjectsCounts(callCluster as any, '.opensearch-dashboards');
expect(results).toStrictEqual({
dashboard: { total: 0 },
visualization: { total: 0 },
Expand All @@ -48,7 +48,7 @@ describe('getSavedObjectsCounts', () => {
},
}));

const results = await getSavedObjectsCounts(callCluster as any, '.kibana');
const results = await getSavedObjectsCounts(callCluster as any, '.opensearch-dashboards');
expect(results).toStrictEqual({
dashboard: { total: 1 },
visualization: { total: 0 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/**
* Moved from /x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_kibana_usage_collector.ts
* Moved from /x-pack/plugins/monitoring/server/opensearch_dashboards_monitoring/collectors/get_opensearch_dashboards_usage_collector.ts
*
* The PR https://github.com/elastic/kibana/pull/62665 proved what the issue https://github.com/elastic/kibana/issues/58249
* was claiming: the structure and payload for common telemetry bits differs between Monitoring and OSS/X-Pack collections.
Expand All @@ -27,7 +27,7 @@
*/

import { snakeCase } from 'lodash';
import { LegacyAPICaller } from 'kibana/server';
import { LegacyAPICaller } from 'opensearch-dashboards/server';

const TYPES = [
'dashboard',
Expand All @@ -38,7 +38,7 @@ const TYPES = [
'timelion-sheet',
];

export interface KibanaSavedObjectCounts {
export interface OpenSearchDashboardsSavedObjectCounts {
dashboard: { total: number };
visualization: { total: number };
search: { total: number };
Expand All @@ -49,10 +49,10 @@ export interface KibanaSavedObjectCounts {

export async function getSavedObjectsCounts(
callCluster: LegacyAPICaller,
kibanaIndex: string // Typically '.kibana'. We might need a way to obtain it from the SavedObjects client (or the SavedObjects client to provide a way to run aggregations?)
): Promise<KibanaSavedObjectCounts> {
opensearchDashboardsIndex: string // Typically '.opensearch-dashboards'. We might need a way to obtain it from the SavedObjects client (or the SavedObjects client to provide a way to run aggregations?)
): Promise<OpenSearchDashboardsSavedObjectCounts> {
const savedObjectCountSearchParams = {
index: kibanaIndex,
index: opensearchDashboardsIndex,
ignoreUnavailable: true,
filterPath: 'aggregations.types.buckets',
body: {
Expand All @@ -72,9 +72,9 @@ export async function getSavedObjectsCounts(
resp.aggregations?.types?.buckets || [];

// Initialise the object with all zeros for all the types
const allZeros: KibanaSavedObjectCounts = TYPES.reduce(
const allZeros: OpenSearchDashboardsSavedObjectCounts = TYPES.reduce(
(acc, type) => ({ ...acc, [snakeCase(type)]: { total: 0 } }),
{} as KibanaSavedObjectCounts
{} as OpenSearchDashboardsSavedObjectCounts
);

// Add the doc_count from each bucket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {
createUsageCollectionSetupMock,
} from '../../../../usage_collection/server/usage_collection.mock';

import { registerKibanaUsageCollector } from './';
import { registerOpenSearchDashboardsUsageCollector } from './';

describe('telemetry_kibana', () => {
describe('telemetry_opensearch_dashboards', () => {
let collector: CollectorOptions;

const usageCollectionMock = createUsageCollectionSetupMock();
Expand All @@ -37,17 +37,17 @@ describe('telemetry_kibana', () => {
const legacyConfig$ = pluginInitializerContextConfigMock({}).legacy.globalConfig$;
const callCluster = jest.fn().mockImplementation(() => ({}));

beforeAll(() => registerKibanaUsageCollector(usageCollectionMock, legacyConfig$));
beforeAll(() => registerOpenSearchDashboardsUsageCollector(usageCollectionMock, legacyConfig$));
afterAll(() => jest.clearAllTimers());

test('registered collector is set', () => {
expect(collector).not.toBeUndefined();
expect(collector.type).toBe('kibana');
expect(collector.type).toBe('opensearchDashboards');
});

test('fetch', async () => {
expect(await collector.fetch(callCluster)).toStrictEqual({
index: '.kibana-tests',
index: '.opensearch-dashboards-tests',
dashboard: { total: 0 },
visualization: { total: 0 },
search: { total: 0 },
Expand All @@ -59,7 +59,7 @@ describe('telemetry_kibana', () => {

test('formatForBulkUpload', async () => {
const resultFromFetch = {
index: '.kibana-tests',
index: '.opensearch-dashboards-tests',
dashboard: { total: 0 },
visualization: { total: 0 },
search: { total: 0 },
Expand All @@ -69,7 +69,7 @@ describe('telemetry_kibana', () => {
};

expect(collector.formatForBulkUpload!(resultFromFetch)).toStrictEqual({
type: 'kibana_stats',
type: 'opensearch_dashboards_stats',
payload: {
usage: resultFromFetch,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export { registerKibanaUsageCollector } from './kibana_usage_collector';
export { registerOpenSearchDashboardsUsageCollector } from './opensearch_dashboards_usage_collector';
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@

import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import { SharedGlobalConfig } from 'kibana/server';
import { SharedGlobalConfig } from 'opensearch-dashboards/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { KIBANA_STATS_TYPE } from '../../../common/constants';
import { getSavedObjectsCounts, KibanaSavedObjectCounts } from './get_saved_object_counts';
import { OPENSEARCH_DASHBOARDS_STATS_TYPE } from '../../../common/constants';
import { getSavedObjectsCounts, OpenSearchDashboardsSavedObjectCounts } from './get_saved_object_counts';

interface KibanaUsage extends KibanaSavedObjectCounts {
interface OpenSearchDashboardsUsage extends OpenSearchDashboardsSavedObjectCounts {
index: string;
}

export function getKibanaUsageCollector(
export function getOpenSearchDashboardsUsageCollector(
usageCollection: UsageCollectionSetup,
legacyConfig$: Observable<SharedGlobalConfig>
) {
return usageCollection.makeUsageCollector<KibanaUsage, { usage: KibanaUsage }>({
type: 'kibana',
return usageCollection.makeUsageCollector<OpenSearchDashboardsUsage, { usage: OpenSearchDashboardsUsage }>({
type: 'opensearchDashboards',
isReady: () => true,
schema: {
index: { type: 'keyword' },
Expand All @@ -46,7 +46,7 @@ export function getKibanaUsageCollector(
},
async fetch(callCluster) {
const {
kibana: { index },
opensearchDashboards: { index },
} = await legacyConfig$.pipe(take(1)).toPromise();
return {
index,
Expand All @@ -56,12 +56,12 @@ export function getKibanaUsageCollector(

/*
* Format the response data into a model for internal upload
* 1. Make this data part of the "kibana_stats" type
* 1. Make this data part of the "opensearch_dashboards_stats" type
* 2. Organize the payload in the usage namespace of the data payload (usage.index, etc)
*/
formatForBulkUpload: (result) => {
return {
type: KIBANA_STATS_TYPE,
type: OPENSEARCH_DASHBOARDS_STATS_TYPE,
payload: {
usage: result,
},
Expand All @@ -70,9 +70,9 @@ export function getKibanaUsageCollector(
});
}

export function registerKibanaUsageCollector(
export function registerOpenSearchDashboardsUsageCollector(
usageCollection: UsageCollectionSetup,
legacyConfig$: Observable<SharedGlobalConfig>
) {
usageCollection.registerCollector(getKibanaUsageCollector(usageCollection, legacyConfig$));
usageCollection.registerCollector(getOpenSearchDashboardsUsageCollector(usageCollection, legacyConfig$));
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('telemetry_ops_stats', () => {

test('registered collector is set', () => {
expect(collector).not.toBeUndefined();
expect(collector.type).toBe('kibana_stats');
expect(collector.type).toBe('opensearch_dashboards_stats');
});

test('isReady should return false because no metrics have been provided yet', () => {
Expand Down
Loading