From ed735dc74cdcb809dac13da0be38d1853e64314c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A8=20Audrey=20=E2=9C=A8?= Date: Tue, 11 Mar 2025 12:45:11 -0400 Subject: [PATCH] format refinement; delete dead code --- libs/common/src/tools/achievements/types.ts | 4 +- libs/common/src/tools/log/ecs-format/core.ts | 2 +- libs/common/src/tools/log/ecs-format/event.ts | 31 ++++---- libs/common/src/tools/log/ecs-format/index.ts | 1 + .../src/tools/log/ecs-format/service.ts | 23 ++++++ libs/common/src/tools/log/log-subject.ts | 79 ------------------- 6 files changed, 43 insertions(+), 97 deletions(-) create mode 100644 libs/common/src/tools/log/ecs-format/service.ts delete mode 100644 libs/common/src/tools/log/log-subject.ts diff --git a/libs/common/src/tools/achievements/types.ts b/libs/common/src/tools/achievements/types.ts index 3f606ee5dd6..4981ad47e7d 100644 --- a/libs/common/src/tools/achievements/types.ts +++ b/libs/common/src/tools/achievements/types.ts @@ -1,13 +1,13 @@ import { RequireAtLeastOne } from "type-fest"; import { Tagged } from "type-fest/source/opaque"; -import { EcsFormat, EventFormat } from "../log/ecs-format"; +import { EventFormat, ServiceFormat } from "../log/ecs-format"; export type AchievementId = string & Tagged<"achievement">; type Progress = { type: "progress"; name: AchievementId; value: number }; type Earned = { type: "earned"; name: AchievementId }; -export type AchievementFormat = EcsFormat & EventFormat & { achievement: Progress | Earned }; +export type AchievementFormat = EventFormat & ServiceFormat & { achievement: Progress | Earned }; // consumed by validator and achievement list (should this include a "toast-alerter"?) export type Achievement = { diff --git a/libs/common/src/tools/log/ecs-format/core.ts b/libs/common/src/tools/log/ecs-format/core.ts index 18cf72e4b20..8e9447ce041 100644 --- a/libs/common/src/tools/log/ecs-format/core.ts +++ b/libs/common/src/tools/log/ecs-format/core.ts @@ -3,7 +3,7 @@ import { Primitive } from "type-fest"; /** Elastic Common Schema log format - core fields. */ export interface EcsFormat { - "@timestamp": Date; + "@timestamp": number; /** custom key/value pairs */ labels?: Record; diff --git a/libs/common/src/tools/log/ecs-format/event.ts b/libs/common/src/tools/log/ecs-format/event.ts index 7b677496b9b..fac05df873c 100644 --- a/libs/common/src/tools/log/ecs-format/event.ts +++ b/libs/common/src/tools/log/ecs-format/event.ts @@ -4,26 +4,27 @@ import { EcsFormat } from "./core"; /** extends core event logs with additional information */ export type EventFormat = EcsFormat & { - - event: Partial & Partial & { - /** event severity as a number */ - severity?: LogLevelType, - }, -} + action?: string; + event: Partial & + Partial & { + /** event severity as a number */ + severity?: LogLevelType; + }; +}; export type ProcessEvent = { - start: Date, - duration: number, - end: Date, + start: Date; + duration: number; + end: Date; }; export type ApplicationEvent = { - /** source of the event; this is usually a client type or service name */ - provider: string, + /** source of the event; this is usually a client type or service name */ + provider: string; - /** reason why the event occurred, according to the source */ - reason: string, + /** reason why the event occurred, according to the source */ + reason: string; - /** reference URL for the event */ - reference: string, + /** reference URL for the event */ + reference: string; }; diff --git a/libs/common/src/tools/log/ecs-format/index.ts b/libs/common/src/tools/log/ecs-format/index.ts index 2c8b20f7a98..e067c80135a 100644 --- a/libs/common/src/tools/log/ecs-format/index.ts +++ b/libs/common/src/tools/log/ecs-format/index.ts @@ -2,4 +2,5 @@ export { EcsFormat } from "./core"; export { ErrorFormat } from "./error"; export { EventFormat } from "./event"; export { LogFormat } from "./log"; +export { ServiceFormat } from "./service"; export { UserFormat } from "./user"; diff --git a/libs/common/src/tools/log/ecs-format/service.ts b/libs/common/src/tools/log/ecs-format/service.ts new file mode 100644 index 00000000000..24cf6972f06 --- /dev/null +++ b/libs/common/src/tools/log/ecs-format/service.ts @@ -0,0 +1,23 @@ +import { EcsFormat } from "./core"; + +export type ServiceFormat = EcsFormat & { + /** documents the program providing the log */ + service: { + /** Which kind of client is it? */ + name: "android" | "cli" | "desktop" | "extension" | "ios" | "web"; + + /** identifies the service as a type of client device */ + type: "client"; + + /** Information about the instance of the service providing the log */ + node: { + /** a unique identifier(s) for this client installation */ + name: string; + }; + /** The environment to which the client was connected */ + environment: "production" | "testing" | "development" | "local"; + + /** the unique identifier(s) for this client installation */ + version: "2025.3.1-innovation-sprint"; + }; +}; diff --git a/libs/common/src/tools/log/log-subject.ts b/libs/common/src/tools/log/log-subject.ts deleted file mode 100644 index 07283aac568..00000000000 --- a/libs/common/src/tools/log/log-subject.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { Observable, Observer, ReplaySubject, SubjectLike, Subscription, Unsubscribable, map } from "rxjs"; - -import { EcsFormat } from "./ecs-format"; -import { LogKey } from "./log-key"; -import { LogSubjectDependencyProvider } from "./log-subject-dependency-provider"; - -/** A subject that captures the last N values it observes. - * Subscribers use one of several endpoints to retrieve values. - * - * `LogSubject$`: monitoring the LogSubject directly emits all captured - * values individually (like `ReplaySubject`). - * `LogSubject.window$(size:number)`: emit captured values in blocks less than or equal - * to the size of the capture buffer. - * `LogSubject.new$`: emit values received after the subscription occurs - */ -export class LogSubject - extends Observable - implements SubjectLike -{ - constructor( - private key: LogKey, - private providers: LogSubjectDependencyProvider - ) { - super(); - } - - // window$(size:number) : Observable; - // new$(size:number) : Observable; - - next(value: LogFormat) { - this.input?.next(value); - } - - error(err: any) { - this.input?.error(err); - } - - complete() { - this.input?.complete(); - } - - /** Subscribe to the subject's event stream - * @param observer listening for events - * @returns the subscription - */ - subscribe(observer?: Partial> | ((value: LogFormat) => void) | null): Subscription { - return this.output.pipe(map((log) => log)).subscribe(observer); - } - - // using subjects to ensure the right semantics are followed; - // if greater efficiency becomes desirable, consider implementing - // `SubjectLike` directly - private input? = new ReplaySubject(this.key.size); - private readonly output = new ReplaySubject(this.key.size); - - private inputSubscription?: Unsubscribable; - private outputSubscription?: Unsubscribable; - - private get isDisposed() { - return this.input === null; - } - - private dispose() { - if (!this.isDisposed) { - this.providers.log.debug("disposing LogSubject"); - - // clean up internal subscriptions - this.inputSubscription?.unsubscribe(); - this.outputSubscription?.unsubscribe(); - this.inputSubscription = undefined; - this.outputSubscription = undefined; - - // drop input to ensure its value is removed from memory - this.input = undefined; - - this.providers.log.debug("disposed LogSubject"); - } - } -}