Skip to content

Commit

Permalink
Merge branch 'main' into ea-green-execution
Browse files Browse the repository at this point in the history
  • Loading branch information
MadameSheema committed Apr 1, 2024
2 parents c2a60fc + 6e23d50 commit 3e06883
Show file tree
Hide file tree
Showing 17 changed files with 414 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export class AnalyticsClient implements IAnalyticsClient {
this.optInConfig$.next(optInConfigInstance);
};

// @ts-expect-error upgrade typescript v4.9.5
public registerContextProvider = <Context>(contextProviderOpts: ContextProviderOpts<Context>) => {
this.contextService.registerContextProvider(contextProviderOpts);
};
Expand Down
17 changes: 10 additions & 7 deletions packages/analytics/client/src/analytics_client/context_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ContextProviderName, ContextProviderOpts } from './types';
import { schemaToIoTs, validateSchema } from '../schema/validation';

export class ContextService {
private readonly contextProvidersRegistry = new Map<ContextProviderName, Partial<EventContext>>();
private readonly contextProvidersRegistry = new Map<ContextProviderName, unknown>();
private readonly contextProvidersSubscriptions = new Map<ContextProviderName, Subscription>();

constructor(
Expand All @@ -30,7 +30,7 @@ export class ContextService {
public registerContextProvider<Context>({
name,
context$,
schema, // @ts-expect-error upgrade typescript v4.9.5
schema,
}: ContextProviderOpts<Context>) {
if (this.contextProvidersSubscriptions.has(name)) {
throw new Error(`Context provider with name '${name}' already registered`);
Expand Down Expand Up @@ -58,9 +58,8 @@ export class ContextService {
})
)
.subscribe((context) => {
// We store each context linked to the context provider so they can increase and reduce
// We store each context linked to the context provider, so they can increase and reduce
// the number of fields they report without having left-overs in the global context.
// @ts-expect-error upgrade typescript v4.9.5
this.contextProvidersRegistry.set(name, context);

// For every context change, we rebuild the global context.
Expand All @@ -87,7 +86,7 @@ export class ContextService {
*/
private updateGlobalContext() {
this.context$.next(
[...this.contextProvidersRegistry.values()].reduce((acc, context) => {
[...this.contextProvidersRegistry.values()].reduce((acc: Partial<EventContext>, context) => {
return {
...acc,
...this.removeEmptyValues(context),
Expand All @@ -96,8 +95,8 @@ export class ContextService {
);
}

private removeEmptyValues(context?: Partial<EventContext>) {
if (!context) {
private removeEmptyValues(context: unknown) {
if (!isObject(context)) {
return {};
}
return Object.keys(context).reduce((acc, key) => {
Expand All @@ -108,3 +107,7 @@ export class ContextService {
}, {} as Partial<EventContext>);
}
}

function isObject(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null;
}
1 change: 1 addition & 0 deletions packages/analytics/client/src/analytics_client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type {
ShipperName,
// Types for the registerContextProvider API
ContextProviderOpts,
ContextProviderName,
// Types for the registerEventType API
EventTypeOpts,
} from './types';
Expand Down
7 changes: 3 additions & 4 deletions packages/analytics/client/src/analytics_client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { Observable } from 'rxjs';
import type { Logger } from '@kbn/logging';

import type { IShipper } from '../shippers';
import type { EventContext, EventType, TelemetryCounter } from '../events';
import type { EventType, TelemetryCounter } from '../events';
import type { RootSchema } from '../schema';

/**
Expand Down Expand Up @@ -93,7 +93,7 @@ export interface OptInConfigPerType {
}

/**
*
* Options for the optIn API
*/
export interface OptInConfig {
/**
Expand Down Expand Up @@ -128,7 +128,7 @@ export type ContextProviderName = string;
/**
* Definition of a context provider
*/
export interface ContextProviderOpts<Context extends Partial<EventContext>> {
export interface ContextProviderOpts<Context> {
/**
* The name of the provider.
*/
Expand Down Expand Up @@ -205,7 +205,6 @@ export interface IAnalyticsClient {
*
* @track-adoption
*/
// @ts-expect-error upgrade typescript v4.9.5
registerContextProvider: <Context>(contextProviderOpts: ContextProviderOpts<Context>) => void;
/**
* Removes the context provider and stop enriching the events from its context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { enableAllPolicyProtections } from '../../../tasks/endpoint_policy';
import { createEndpointHost } from '../../../tasks/create_endpoint_host';
import { deleteAllLoadedEndpointData } from '../../../tasks/delete_all_endpoint_data';

describe('Response console', { tags: ['@ess', '@serverless'] }, () => {
// FLAKY: https://github.com/elastic/kibana/issues/170373
describe.skip('Response console', { tags: ['@ess', '@serverless'] }, () => {
beforeEach(() => {
login();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { enableAllPolicyProtections } from '../../../tasks/endpoint_policy';
import { createEndpointHost } from '../../../tasks/create_endpoint_host';
import { deleteAllLoadedEndpointData } from '../../../tasks/delete_all_endpoint_data';

describe('Response console', { tags: ['@ess', '@serverless'] }, () => {
// FLAKY: https://github.com/elastic/kibana/issues/170424
describe.skip('Response console', { tags: ['@ess', '@serverless'] }, () => {
beforeEach(() => {
login();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { enableAllPolicyProtections } from '../../../tasks/endpoint_policy';
import { createEndpointHost } from '../../../tasks/create_endpoint_host';
import { deleteAllLoadedEndpointData } from '../../../tasks/delete_all_endpoint_data';

describe('Response console', { tags: ['@ess', '@serverless'] }, () => {
// FLAKY: https://github.com/elastic/kibana/issues/170563
describe.skip('Response console', { tags: ['@ess', '@serverless'] }, () => {
beforeEach(() => {
login();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import { enableAllPolicyProtections } from '../../../tasks/endpoint_policy';
import { createEndpointHost } from '../../../tasks/create_endpoint_host';
import { deleteAllLoadedEndpointData } from '../../../tasks/delete_all_endpoint_data';

describe('Response console', { tags: ['@ess', '@serverless'] }, () => {
// FLAKY: https://github.com/elastic/kibana/issues/172326
describe.skip('Response console', { tags: ['@ess', '@serverless'] }, () => {
let indexedPolicy: IndexedFleetEndpointPolicyResponse;
let policy: PolicyData;
let createdHost: CreateAndEnrollEndpointHostResponse;
Expand Down
Loading

0 comments on commit 3e06883

Please sign in to comment.