Skip to content

Commit

Permalink
feat: store memory footprints to grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus committed Dec 19, 2024
1 parent dc9a58b commit 8d77f69
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
IFeatureToggleQuery,
IFlagResolver,
ISegmentReadModel,
IUnleashConfig,
} from '../../../types';
import type ConfigurationRevisionService from '../../feature-toggle/configuration-revision-service';
import { UPDATE_REVISION } from '../../feature-toggle/configuration-revision-service';
Expand All @@ -15,6 +16,7 @@ import type {
} from './client-feature-toggle-delta-read-model-type';
import { CLIENT_DELTA_MEMORY } from '../../../metric-events';
import type EventEmitter from 'events';
import type { Logger } from '../../../logger';

type DeletedFeature = {
name: string;
Expand Down Expand Up @@ -115,21 +117,24 @@ export class ClientFeatureToggleDelta {

private eventBus: EventEmitter;

private readonly logger: Logger;

constructor(
clientFeatureToggleDeltaReadModel: IClientFeatureToggleDeltaReadModel,
segmentReadModel: ISegmentReadModel,
eventStore: IEventStore,
configurationRevisionService: ConfigurationRevisionService,
flagResolver: IFlagResolver,
eventBus: EventEmitter,
config: IUnleashConfig,
) {
this.eventStore = eventStore;
this.configurationRevisionService = configurationRevisionService;
this.clientFeatureToggleDeltaReadModel =
clientFeatureToggleDeltaReadModel;
this.flagResolver = flagResolver;
this.segmentReadModel = segmentReadModel;
this.eventBus = eventBus;
this.eventBus = config.eventBus;
this.logger = config.getLogger('delta/client-feature-toggle-delta.js');
this.onUpdateRevisionEvent = this.onUpdateRevisionEvent.bind(this);
this.delta = {};

Expand Down Expand Up @@ -303,10 +308,14 @@ export class ClientFeatureToggleDelta {
}

storeFootprint() {
const featuresMemory = this.getCacheSizeInBytes(this.delta);
const segmentsMemory = this.getCacheSizeInBytes(this.segments);
const memory = featuresMemory + segmentsMemory;
this.eventBus.emit(CLIENT_DELTA_MEMORY, { memory });
try {
const featuresMemory = this.getCacheSizeInBytes(this.delta);
const segmentsMemory = this.getCacheSizeInBytes(this.segments);
const memory = featuresMemory + segmentsMemory;
this.eventBus.emit(CLIENT_DELTA_MEMORY, { memory });
} catch (e) {
this.logger.error('Client delta footprint error', e);
}
}

getCacheSizeInBytes(value: any): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const createClientFeatureToggleDelta = (
eventStore,
configurationRevisionService,
flagResolver,
eventBus,
config,
);

return clientFeatureToggleDelta;
Expand Down

0 comments on commit 8d77f69

Please sign in to comment.