Use new es client in Uptime usage collector (#86718)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
a2b4517b9e
commit
ff94674919
|
@ -5,29 +5,21 @@
|
|||
*/
|
||||
|
||||
import moment from 'moment';
|
||||
import {
|
||||
ISavedObjectsRepository,
|
||||
ILegacyScopedClusterClient,
|
||||
SavedObjectsClientContract,
|
||||
ElasticsearchClient,
|
||||
} from 'kibana/server';
|
||||
import { ISavedObjectsRepository, SavedObjectsClientContract } from 'kibana/server';
|
||||
import { CollectorFetchContext, UsageCollectionSetup } from 'src/plugins/usage_collection/server';
|
||||
import { PageViewParams, UptimeTelemetry, Usage } from './types';
|
||||
import { savedObjectsAdapter } from '../../saved_objects';
|
||||
import { UptimeESClient } from '../../lib';
|
||||
import { UptimeESClient, createUptimeESClient } from '../../lib';
|
||||
|
||||
interface UptimeTelemetryCollector {
|
||||
[key: number]: UptimeTelemetry;
|
||||
}
|
||||
|
||||
// seconds in an hour
|
||||
const BUCKET_SIZE = 3600;
|
||||
// take buckets in the last day
|
||||
const BUCKET_NUMBER = 24;
|
||||
|
||||
export class KibanaTelemetryAdapter {
|
||||
public static callCluster: ILegacyScopedClusterClient['callAsCurrentUser'] | ElasticsearchClient;
|
||||
|
||||
public static registerUsageCollector = (
|
||||
usageCollector: UsageCollectionSetup,
|
||||
getSavedObjectsClient: () => ISavedObjectsRepository | undefined
|
||||
|
@ -76,10 +68,11 @@ export class KibanaTelemetryAdapter {
|
|||
},
|
||||
},
|
||||
},
|
||||
fetch: async ({ callCluster }: CollectorFetchContext) => {
|
||||
fetch: async ({ esClient }: CollectorFetchContext) => {
|
||||
const savedObjectsClient = getSavedObjectsClient()!;
|
||||
if (savedObjectsClient) {
|
||||
await this.countNoOfUniqueMonitorAndLocations(callCluster, savedObjectsClient);
|
||||
const uptimeEsClient = createUptimeESClient({ esClient, savedObjectsClient });
|
||||
await this.countNoOfUniqueMonitorAndLocations(uptimeEsClient, savedObjectsClient);
|
||||
}
|
||||
const report = this.getReport();
|
||||
return { last_24_hours: { hits: { ...report } } };
|
||||
|
@ -132,7 +125,7 @@ export class KibanaTelemetryAdapter {
|
|||
}
|
||||
|
||||
public static async countNoOfUniqueMonitorAndLocations(
|
||||
callCluster: ILegacyScopedClusterClient['callAsCurrentUser'] | UptimeESClient,
|
||||
callCluster: UptimeESClient,
|
||||
savedObjectsClient: ISavedObjectsRepository | SavedObjectsClientContract
|
||||
) {
|
||||
const dynamicSettings = await savedObjectsAdapter.getUptimeDynamicSettings(savedObjectsClient);
|
||||
|
@ -194,15 +187,12 @@ export class KibanaTelemetryAdapter {
|
|||
},
|
||||
};
|
||||
|
||||
const { body: result } =
|
||||
typeof callCluster === 'function'
|
||||
? await callCluster('search', params)
|
||||
: await callCluster.search(params);
|
||||
const { body: result } = await callCluster.search(params);
|
||||
|
||||
const numberOfUniqueMonitors: number = result?.aggregations?.unique_monitors?.value ?? 0;
|
||||
const numberOfUniqueLocations: number = result?.aggregations?.unique_locations?.value ?? 0;
|
||||
const monitorNameStats: any = result?.aggregations?.monitor_name;
|
||||
const locationNameStats: any = result?.aggregations?.observer_loc_name;
|
||||
const monitorNameStats = result?.aggregations?.monitor_name;
|
||||
const locationNameStats = result?.aggregations?.observer_loc_name;
|
||||
const uniqueMonitors: any = result?.aggregations?.monitors.buckets;
|
||||
|
||||
const bucketId = this.getBucketToIncrement();
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { ElasticsearchClient, SavedObjectsClientContract, KibanaRequest } from 'kibana/server';
|
||||
import {
|
||||
ElasticsearchClient,
|
||||
SavedObjectsClientContract,
|
||||
KibanaRequest,
|
||||
ISavedObjectsRepository,
|
||||
} from 'kibana/server';
|
||||
import chalk from 'chalk';
|
||||
import { UMBackendFrameworkAdapter } from './adapters';
|
||||
import { UMLicenseCheck } from './domains';
|
||||
|
@ -41,7 +46,7 @@ export function createUptimeESClient({
|
|||
}: {
|
||||
esClient: ElasticsearchClient;
|
||||
request?: KibanaRequest;
|
||||
savedObjectsClient: SavedObjectsClientContract;
|
||||
savedObjectsClient: SavedObjectsClientContract | ISavedObjectsRepository;
|
||||
}) {
|
||||
const { _debug = false } = (request?.query as { _debug: boolean }) ?? {};
|
||||
|
||||
|
|
|
@ -99,6 +99,7 @@ export interface AggregationOptionsByType {
|
|||
extended_stats: {
|
||||
field: string;
|
||||
};
|
||||
string_stats: { field: string };
|
||||
top_hits: {
|
||||
from?: number;
|
||||
size?: number;
|
||||
|
@ -274,6 +275,13 @@ interface AggregationResponsePart<TAggregationOptionsMap extends AggregationOpti
|
|||
lower: number | null;
|
||||
};
|
||||
};
|
||||
string_stats: {
|
||||
count: number;
|
||||
min_length: number;
|
||||
max_length: number;
|
||||
avg_length: number;
|
||||
entropy: number;
|
||||
};
|
||||
top_hits: {
|
||||
hits: {
|
||||
total: {
|
||||
|
|
Loading…
Reference in a new issue