Skip to content

Commit

Permalink
Merge branch 'master' into js-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Sep 24, 2020
2 parents 866fabe + 3618cef commit 96599cf
Show file tree
Hide file tree
Showing 19 changed files with 566 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ export const parsedWorkingCollector: ParsedUsageCollection = [
type: 'StringKeyword',
},
my_index_signature_prop: {
'': {
'@@INDEX@@': {
kind: SyntaxKind.NumberKeyword,
type: 'NumberKeyword',
},
'@@INDEX@@': {
kind: SyntaxKind.NumberKeyword,
type: 'NumberKeyword',
},
},
my_objects: {
Expand Down

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

26 changes: 24 additions & 2 deletions packages/kbn-telemetry-tools/src/tools/serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ export function loadFixtureProgram(fixtureName: string) {
}

describe('getDescriptor', () => {
const usageInterfaces = new Map<string, ts.InterfaceDeclaration>();
const usageInterfaces = new Map<string, ts.InterfaceDeclaration | ts.TypeAliasDeclaration>();
let tsProgram: ts.Program;
beforeAll(() => {
const { program, sourceFile } = loadFixtureProgram('constants');
tsProgram = program;
for (const node of traverseNodes(sourceFile)) {
if (ts.isInterfaceDeclaration(node)) {
if (ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) {
const interfaceName = node.name.getText();
usageInterfaces.set(interfaceName, node);
}
Expand Down Expand Up @@ -102,4 +102,26 @@ describe('getDescriptor', () => {
'Mapping does not support conflicting union types.'
);
});

it('serializes TypeAliasDeclaration', () => {
const usageInterface = usageInterfaces.get('TypeAliasWithUnion')!;
const descriptor = getDescriptor(usageInterface, tsProgram);
expect(descriptor).toEqual({
locale: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
prop1: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
prop2: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
prop3: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
prop4: { kind: ts.SyntaxKind.StringLiteral, type: 'StringLiteral' },
prop5: { kind: ts.SyntaxKind.FirstLiteralToken, type: 'FirstLiteralToken' },
});
});

it('serializes Record entries', () => {
const usageInterface = usageInterfaces.get('TypeAliasWithRecord')!;
const descriptor = getDescriptor(usageInterface, tsProgram);
expect(descriptor).toEqual({
locale: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
'@@INDEX@@': { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
});
});
});
27 changes: 24 additions & 3 deletions packages/kbn-telemetry-tools/src/tools/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ export function getDescriptor(node: ts.Node, program: ts.Program): Descriptor |
}
if (ts.isTypeLiteralNode(node) || ts.isInterfaceDeclaration(node)) {
return node.members.reduce((acc, m) => {
acc[m.name?.getText() || ''] = getDescriptor(m, program);
return acc;
}, {} as any);
const key = m.name?.getText();
if (key) {
return { ...acc, [key]: getDescriptor(m, program) };
} else {
return { ...acc, ...getDescriptor(m, program) };
}
}, {});
}

// If it's defined as signature { [key: string]: OtherInterface }
Expand Down Expand Up @@ -114,6 +118,10 @@ export function getDescriptor(node: ts.Node, program: ts.Program): Descriptor |
if (symbolName === 'Date') {
return { kind: TelemetryKinds.Date, type: 'Date' };
}
// Support `Record<string, SOMETHING>`
if (symbolName === 'Record' && node.typeArguments![0].kind === ts.SyntaxKind.StringKeyword) {
return { '@@INDEX@@': getDescriptor(node.typeArguments![1], program) };
}
const declaration = (symbol?.getDeclarations() || [])[0];
if (declaration) {
return getDescriptor(declaration, program);
Expand Down Expand Up @@ -157,6 +165,19 @@ export function getDescriptor(node: ts.Node, program: ts.Program): Descriptor |
return uniqueKinds[0];
}

// Support `type MyUsageType = SomethingElse`
if (ts.isTypeAliasDeclaration(node)) {
return getDescriptor(node.type, program);
}

// Support `&` unions
if (ts.isIntersectionTypeNode(node)) {
return node.types.reduce(
(acc, unionNode) => ({ ...acc, ...getDescriptor(unionNode, program) }),
{}
);
}

switch (node.kind) {
case ts.SyntaxKind.NumberKeyword:
case ts.SyntaxKind.BooleanKeyword:
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-telemetry-tools/src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export function difference(actual: any, expected: any) {
function (result, value, key) {
if (key && /@@INDEX@@/.test(`${key}`)) {
// The type definition is an Index Signature, fuzzy searching for similar keys
const regexp = new RegExp(`${key}`.replace(/@@INDEX@@/g, '(.+)?'));
const regexp = new RegExp(`^${key}`.replace(/@@INDEX@@/g, '(.+)?'));
const keysInBase = Object.keys(base)
.map((k) => {
const match = k.match(regexp);
Expand Down
4 changes: 4 additions & 0 deletions src/fixtures/telemetry_collectors/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ export const externallyDefinedSchema: MakeSchemaFrom<{ locale: string }> = {
type: 'keyword',
},
};

export type TypeAliasWithUnion = Usage & WithUnion;

export type TypeAliasWithRecord = Usage & Record<string, number>;
30 changes: 11 additions & 19 deletions src/plugins/discover/public/application/angular/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,18 @@ const k7Breadcrumbs = ($route) => {
};

getAngularModule().config(($routeProvider) => {
$routeProvider
// deprecated route, kept for compatibility
// should be removed in the future
.when('/context/:indexPatternId/:type/:id*', {
redirectTo: '/context/:indexPatternId/:id',
})
.when('/context/:indexPatternId/:id*', {
controller: ContextAppRouteController,
k7Breadcrumbs,
controllerAs: 'contextAppRoute',
resolve: {
indexPattern: ($route, Promise) => {
const indexPattern = getServices().indexPatterns.get(
$route.current.params.indexPatternId
);
return Promise.props({ ip: indexPattern });
},
$routeProvider.when('/context/:indexPatternId/:id*', {
controller: ContextAppRouteController,
k7Breadcrumbs,
controllerAs: 'contextAppRoute',
resolve: {
indexPattern: ($route, Promise) => {
const indexPattern = getServices().indexPatterns.get($route.current.params.indexPatternId);
return Promise.props({ ip: indexPattern });
},
template: contextAppRouteTemplate,
});
},
template: contextAppRouteTemplate,
});
});

function ContextAppRouteController($routeParams, $scope, $route) {
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/discover/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ export class DiscoverPlugin
return `#${path}`;
});
plugins.urlForwarding.forwardApp('context', 'discover', (path) => {
const urlParts = path.split('/');
// take care of urls containing legacy url, those split in the following way
// ["", "context", indexPatternId, _type, id + params]
if (urlParts[4]) {
// remove _type part
const newPath = [...urlParts.slice(0, 3), ...urlParts.slice(4)].join('/');
return `#${newPath}`;
}
return `#${path}`;
});
plugins.urlForwarding.forwardApp('discover', 'discover', (path) => {
Expand Down
1 change: 0 additions & 1 deletion x-pack/.telemetryrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"plugins/apm/server/lib/apm_telemetry/index.ts",
"plugins/canvas/server/collectors/collector.ts",
"plugins/infra/server/usage/usage_collector.ts",
"plugins/lens/server/usage/collectors.ts",
"plugins/reporting/server/usage/reporting_usage_collector.ts",
"plugins/maps/server/maps_telemetry/collectors/register.ts"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Given(`a user browses the APM UI application for RUM Data`, () => {
const RANGE_FROM = 'now-24h';
const RANGE_TO = 'now';
loginAndWaitForPage(
`/app/csm`,
`/app/ux`,
{
from: RANGE_FROM,
to: RANGE_TO,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/apm/public/application/csmApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { APMRouteDefinition } from '../application/routes';
import { renderAsRedirectTo } from '../components/app/Main/route_config';
import { ScrollToTopOnPathChange } from '../components/app/Main/ScrollToTopOnPathChange';
import { RumHome } from '../components/app/RumDashboard/RumHome';
import { RumHome, UX_LABEL } from '../components/app/RumDashboard/RumHome';
import { ApmPluginContext } from '../context/ApmPluginContext';
import { LoadingIndicatorProvider } from '../context/LoadingIndicatorContext';
import { UrlParamsProvider } from '../context/UrlParamsContext';
Expand All @@ -39,8 +39,8 @@ export const rumRoutes: APMRouteDefinition[] = [
{
exact: true,
path: '/',
render: renderAsRedirectTo('/csm'),
breadcrumb: 'Client Side Monitoring',
render: renderAsRedirectTo('/ux'),
breadcrumb: UX_LABEL,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { RumOverview } from '../RumDashboard';
import { RumHeader } from './RumHeader';
import { CsmSharedContextProvider } from './CsmSharedContext';

export const UX_LABEL = i18n.translate('xpack.apm.ux.title', {
defaultMessage: 'User Experience',
});

export function RumHome() {
return (
<div>
Expand All @@ -19,11 +23,7 @@ export function RumHome() {
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={false}>
<EuiTitle size="l">
<h1>
{i18n.translate('xpack.apm.csm.title', {
defaultMessage: 'Client Side Monitoring',
})}
</h1>
<h1>{UX_LABEL}</h1>
</EuiTitle>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { useApmPluginContext } from '../../../hooks/useApmPluginContext';

export function ClientSideMonitoringCallout() {
const { core } = useApmPluginContext();
const clientSideMonitoringHref = core.http.basePath.prepend(`/app/csm`);
const clientSideMonitoringHref = core.http.basePath.prepend(`/app/ux`);

return (
<EuiCallOut
iconType="cheer"
title={i18n.translate(
'xpack.apm.transactionOverview.clientSideMonitoring.calloutTitle',
{ defaultMessage: 'Introducing: Client Side Monitoring' }
{ defaultMessage: 'Introducing: Elastic User Experience' }
)}
>
<EuiText>
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
});

core.application.register({
id: 'csm',
title: 'Client Side Monitoring',
id: 'ux',
title: 'User Experience',
order: 8500,
euiIconType: 'logoObservability',
category: DEFAULT_APP_CATEGORIES.observability,
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/apm/server/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import {
export const APM_FEATURE = {
id: 'apm',
name: i18n.translate('xpack.apm.featureRegistry.apmFeatureName', {
defaultMessage: 'APM and Client Side Monitoring',
defaultMessage: 'APM and User Experience',
}),
order: 900,
category: DEFAULT_APP_CATEGORIES.observability,
icon: 'apmApp',
navLinkId: 'apm',
app: ['apm', 'csm', 'kibana'],
app: ['apm', 'ux', 'kibana'],
catalogue: ['apm'],
management: {
insightsAndAlerting: ['triggersActions'],
Expand All @@ -31,7 +31,7 @@ export const APM_FEATURE = {
// see x-pack/plugins/features/common/feature_kibana_privileges.ts
privileges: {
all: {
app: ['apm', 'csm', 'kibana'],
app: ['apm', 'ux', 'kibana'],
api: ['apm', 'apm_write'],
catalogue: ['apm'],
savedObject: {
Expand All @@ -47,7 +47,7 @@ export const APM_FEATURE = {
ui: ['show', 'save', 'alerting:show', 'alerting:save'],
},
read: {
app: ['apm', 'csm', 'kibana'],
app: ['apm', 'ux', 'kibana'],
api: ['apm'],
catalogue: ['apm'],
savedObject: {
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/lens/server/usage/collectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { TaskManagerStartContract } from '../../../task_manager/server';

import { LensUsage, LensTelemetryState } from './types';
import { lensUsageSchema } from './schema';

export function registerLensUsageCollector(
usageCollection: UsageCollectionSetup,
Expand All @@ -20,9 +21,9 @@ export function registerLensUsageCollector(
// mark lensUsageCollector as ready to collect when the TaskManager is ready
isCollectorReady = true;
});
const lensUsageCollector = usageCollection.makeUsageCollector({
const lensUsageCollector = usageCollection.makeUsageCollector<LensUsage>({
type: 'lens',
fetch: async (): Promise<LensUsage> => {
async fetch() {
try {
const docs = await getLatestTaskState(await taskManager);
// get the accumulated state from the recurring task
Expand Down Expand Up @@ -55,6 +56,7 @@ export function registerLensUsageCollector(
}
},
isReady: () => isCollectorReady,
schema: lensUsageSchema,
});

usageCollection.registerCollector(lensUsageCollector);
Expand Down
Loading

0 comments on commit 96599cf

Please sign in to comment.