mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Use client logger in ContentInsightsClient
(#207206)
## Summary fix https://github.com/elastic/kibana-team/issues/1412 (see context, just for cleanup)
This commit is contained in:
parent
7bb2dad38f
commit
6b9d90ef59
8 changed files with 41 additions and 7 deletions
|
@ -7,6 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import type { Logger } from '@kbn/logging';
|
||||
import type { HttpStart } from '@kbn/core-http-browser';
|
||||
import type {
|
||||
ContentInsightsStats,
|
||||
|
@ -27,17 +28,21 @@ export interface ContentInsightsClientPublic {
|
|||
* Client for the Content Management Insights service.
|
||||
*/
|
||||
export class ContentInsightsClient implements ContentInsightsClientPublic {
|
||||
private logger: Logger;
|
||||
constructor(
|
||||
private readonly deps: { http: HttpStart },
|
||||
private readonly deps: { http: HttpStart; logger: Logger },
|
||||
private readonly config: { domainId: string }
|
||||
) {}
|
||||
) {
|
||||
this.logger = deps.logger.get('content_insights_client');
|
||||
}
|
||||
|
||||
track(id: string, eventType: ContentInsightsEventTypes) {
|
||||
this.deps.http
|
||||
.post(`/internal/content_management/insights/${this.config.domainId}/${id}/${eventType}`)
|
||||
.catch((e) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(`Could not track ${eventType} event for ${id}`, e);
|
||||
this.logger.warn(`Could not track ${eventType} event for ${id}. Error: ${e?.message}`, {
|
||||
error: e,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -29,5 +29,6 @@
|
|||
"@kbn/content-management-content-insights-server",
|
||||
"@kbn/content-management-table-list-view-common",
|
||||
"@kbn/charts-theme",
|
||||
"@kbn/logging",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -19,8 +19,10 @@ import {
|
|||
mockDashboardContentManagementCache,
|
||||
mockDashboardContentManagementService,
|
||||
setStubKibanaServices,
|
||||
setStubLogger,
|
||||
} from './public/services/mocks';
|
||||
|
||||
setStubLogger();
|
||||
// Start the kibana services with stubs
|
||||
setStubKibanaServices();
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import { DashboardCreationOptions, DashboardState } from './types';
|
|||
import { getDashboardApi } from './get_dashboard_api';
|
||||
import { startQueryPerformanceTracking } from '../dashboard_container/embeddable/create/performance/query_performance_tracking';
|
||||
import { coreServices } from '../services/kibana_services';
|
||||
import { logger } from '../services/logger';
|
||||
import {
|
||||
PANELS_CONTROL_GROUP_KEY,
|
||||
getDashboardBackupService,
|
||||
|
@ -123,7 +124,7 @@ export async function loadDashboardApi({
|
|||
// however, there is an edge case that we now count a new view when a user is editing a dashboard and is returning from an editor by canceling
|
||||
// TODO: this should be revisited by making embeddable transfer support canceling logic https://github.com/elastic/kibana/issues/190485
|
||||
const contentInsightsClient = new ContentInsightsClient(
|
||||
{ http: coreServices.http },
|
||||
{ http: coreServices.http, logger },
|
||||
{ domainId: 'dashboard' }
|
||||
);
|
||||
contentInsightsClient.track(savedObjectId, 'viewed');
|
||||
|
|
|
@ -26,6 +26,7 @@ import { getDashboardBackupService } from '../../services/dashboard_backup_servi
|
|||
import { getDashboardContentManagementService } from '../../services/dashboard_content_management_service';
|
||||
import { getDashboardRecentlyAccessedService } from '../../services/dashboard_recently_accessed_service';
|
||||
import { coreServices } from '../../services/kibana_services';
|
||||
import { logger } from '../../services/logger';
|
||||
import { getDashboardCapabilities } from '../../utils/get_dashboard_capabilities';
|
||||
import {
|
||||
dashboardListingErrorStrings,
|
||||
|
@ -341,7 +342,7 @@ export const useDashboardListingTable = ({
|
|||
);
|
||||
|
||||
const contentInsightsClient = useMemo(
|
||||
() => new ContentInsightsClient({ http: coreServices.http }, { domainId: 'dashboard' }),
|
||||
() => new ContentInsightsClient({ http: coreServices.http, logger }, { domainId: 'dashboard' }),
|
||||
[]
|
||||
);
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ import {
|
|||
} from './dashboard_container/panel_placement';
|
||||
import type { FindDashboardsService } from './services/dashboard_content_management_service/types';
|
||||
import { setKibanaServices, untilPluginStartServicesReady } from './services/kibana_services';
|
||||
import { setLogger } from './services/logger';
|
||||
import { registerActions } from './dashboard_actions/register_actions';
|
||||
|
||||
export interface DashboardFeatureFlagConfig {
|
||||
|
@ -156,7 +157,9 @@ export class DashboardPlugin
|
|||
implements
|
||||
Plugin<DashboardSetup, DashboardStart, DashboardSetupDependencies, DashboardStartDependencies>
|
||||
{
|
||||
constructor(private initializerContext: PluginInitializerContext) {}
|
||||
constructor(private initializerContext: PluginInitializerContext) {
|
||||
setLogger(initializerContext.logger.get('dashboard'));
|
||||
}
|
||||
|
||||
private appStateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
|
||||
private stopUrlTracking: (() => void) | undefined = undefined;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the "Elastic License
|
||||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
|
||||
* Public License v 1"; you may not use this file except in compliance with, at
|
||||
* your election, the "Elastic License 2.0", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import type { Logger } from '@kbn/logging';
|
||||
|
||||
export let logger: Logger;
|
||||
|
||||
export const setLogger = (_logger: Logger) => {
|
||||
logger = _logger;
|
||||
};
|
|
@ -32,6 +32,7 @@ import { urlForwardingPluginMock } from '@kbn/url-forwarding-plugin/public/mocks
|
|||
import { visualizationsPluginMock } from '@kbn/visualizations-plugin/public/mocks';
|
||||
|
||||
import { setKibanaServices } from './kibana_services';
|
||||
import { setLogger } from './logger';
|
||||
import { DashboardAttributes } from '../../server/content_management';
|
||||
import { DashboardCapabilities } from '../../common';
|
||||
import { LoadDashboardReturn } from './dashboard_content_management_service/types';
|
||||
|
@ -76,6 +77,10 @@ export const setStubKibanaServices = () => {
|
|||
});
|
||||
};
|
||||
|
||||
export const setStubLogger = () => {
|
||||
setLogger(coreMock.createCoreContext().logger);
|
||||
};
|
||||
|
||||
export const mockDashboardContentManagementService = {
|
||||
loadDashboardState: jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue