Skip to content

Commit

Permalink
adding telemetry to schema and agent config
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jul 12, 2021
1 parent 54baad5 commit dd1dcc5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
htmlIdGenerator,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { useUiTracker } from '../../../../../../observability/public';
import { ElasticDocsLink } from '../../../shared/Links/ElasticDocsLink';

interface Props {
Expand All @@ -27,6 +28,7 @@ export function ConfirmSwitchModal({
onCancel,
unsupportedConfigs,
}: Props) {
const trackApmEvent = useUiTracker({ app: 'apm' });
const [isConfirmChecked, setIsConfirmChecked] = useState(false);
const hasUnsupportedConfigs = !!unsupportedConfigs.length;
return (
Expand All @@ -48,7 +50,12 @@ export function ConfirmSwitchModal({
}
)}
defaultFocusedButton="confirm"
onConfirm={onConfirm}
onConfirm={() => {
trackApmEvent({
metric: 'confirm_data_stream_switch',
});
onConfirm();
}}
confirmButtonDisabled={!isConfirmChecked}
>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
CoreStart,
SavedObjectsClientContract,
} from 'kibana/server';
import { TelemetryUsageCounter } from '../../routes/typings';
import { APMPluginStartDependencies } from '../../types';
import { getInternalSavedObjectsClient } from '../helpers/get_internal_saved_objects_client';
import { Setup } from '../helpers/setup_request';
Expand All @@ -21,11 +22,19 @@ export async function syncAgentConfigsToApmPackagePolicies({
core,
fleetPluginStart,
setup,
telemetryUsageCounter,
}: {
core: { setup: CoreSetup; start: () => Promise<CoreStart> };
fleetPluginStart: NonNullable<APMPluginStartDependencies['fleet']>;
setup: Setup;
telemetryUsageCounter?: TelemetryUsageCounter;
}) {
if (telemetryUsageCounter) {
telemetryUsageCounter.incrementCounter({
counterName: 'sync_agent_config_to_apm_package_policies',
counterType: 'success',
});
}
const coreStart = await core.start();
const esClient = coreStart.elasticsearch.client.asInternalUser;
const [
Expand Down
12 changes: 7 additions & 5 deletions x-pack/plugins/apm/server/routes/register_routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ import {
routeValidationObject,
} from '@kbn/server-route-repository';
import { mergeRt, jsonRt } from '@kbn/io-ts-utils';
import { UsageCollectionSetup } from '../../../../../../src/plugins/usage_collection/server';
import { pickKeys } from '../../../common/utils/pick_keys';
import { APMRouteHandlerResources, InspectResponse } from '../typings';
import {
APMRouteHandlerResources,
InspectResponse,
TelemetryUsageCounter,
} from '../typings';
import type { ApmPluginRequestHandlerContext } from '../typings';

const inspectRt = t.exact(
Expand Down Expand Up @@ -56,9 +59,7 @@ export function registerRoutes({
repository: ServerRouteRepository<APMRouteHandlerResources>;
config: APMRouteHandlerResources['config'];
ruleDataClient: APMRouteHandlerResources['ruleDataClient'];
telemetryUsageCounter?: ReturnType<
UsageCollectionSetup['createUsageCounter']
>;
telemetryUsageCounter?: TelemetryUsageCounter;
}) {
const routes = repository.getRoutes();

Expand Down Expand Up @@ -104,6 +105,7 @@ export function registerRoutes({
logger,
core,
plugins,
telemetryUsageCounter,
params: merge(
{
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const deleteAgentConfigurationRoute = createApmServerRoute({
}),
handler: async (resources) => {
const setup = await setupRequest(resources);
const { params, logger, core } = resources;
const { params, logger, core, telemetryUsageCounter } = resources;

const { service } = params.body;

Expand All @@ -106,6 +106,7 @@ const deleteAgentConfigurationRoute = createApmServerRoute({
core,
fleetPluginStart: await resources.plugins.fleet.start(),
setup,
telemetryUsageCounter,
});
logger.info(
`Updated Fleet integration policy for APM to remove the deleted agent configuration.`
Expand All @@ -128,7 +129,7 @@ const createOrUpdateAgentConfigurationRoute = createApmServerRoute({
]),
handler: async (resources) => {
const setup = await setupRequest(resources);
const { params, logger, core } = resources;
const { params, logger, core, telemetryUsageCounter } = resources;
const { body, query } = params;

// if the config already exists, it is fetched and updated
Expand Down Expand Up @@ -162,6 +163,7 @@ const createOrUpdateAgentConfigurationRoute = createApmServerRoute({
core,
fleetPluginStart: await resources.plugins.fleet.start(),
setup,
telemetryUsageCounter,
});
logger.info(
`Saved latest agent settings to Fleet integration policy for APM.`
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/apm/server/routes/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { RacApiRequestHandlerContext } from '../../../rule_registry/server'
import { LicensingApiRequestHandlerContext } from '../../../licensing/server';
import { APMConfig } from '..';
import { APMPluginDependencies } from '../types';
import { UsageCollectionSetup } from '../../../../../src/plugins/usage_collection/server';

export interface ApmPluginRequestHandlerContext extends RequestHandlerContext {
licensing: LicensingApiRequestHandlerContext;
Expand Down Expand Up @@ -47,6 +48,10 @@ export interface APMRouteCreateOptions {
};
}

export type TelemetryUsageCounter = ReturnType<
UsageCollectionSetup['createUsageCounter']
>;

export interface APMRouteHandlerResources {
request: KibanaRequest;
context: ApmPluginRequestHandlerContext;
Expand All @@ -68,4 +73,5 @@ export interface APMRouteHandlerResources {
};
};
ruleDataClient: RuleDataClient;
telemetryUsageCounter?: TelemetryUsageCounter;
}

0 comments on commit dd1dcc5

Please sign in to comment.