Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: store memory footprints to grafana #9001

Merged
merged 4 commits into from
Dec 19, 2024
Merged

feat: store memory footprints to grafana #9001

merged 4 commits into from
Dec 19, 2024

Conversation

sjaanus
Copy link
Contributor

@sjaanus sjaanus commented Dec 19, 2024

When there is new revision, we will start storing memory footprint for old client-api and the new delta-api.
We will be sending it as prometheus metrics.

The memory size will only be recalculated if revision changes, which does not happen very often.

Copy link

vercel bot commented Dec 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Dec 19, 2024 10:57am
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Visit Preview Dec 19, 2024 10:57am

Copy link
Contributor

@sjaanus, core features have been modified in this pull request. Please review carefully!

Copy link
Contributor

github-actions bot commented Dec 19, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

@@ -69,6 +70,8 @@ export default class FeatureController extends Controller {

private eventBus: EventEmitter;

private clientFeaturesCacheMap = new Map<string, number>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can not read the size of memoizee directly, so we will be storing the memory usage for each query key into new cache. This will be calculated on new revision id.

@@ -162,6 +165,32 @@ export default class FeatureController extends Controller {
private async resolveFeaturesAndSegments(
query?: IFeatureToggleQuery,
): Promise<[FeatureConfigurationClient[], IClientSegment[]]> {
if (this.flagResolver.isEnabled('deltaApi')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if flag on, do this logic, otherwise go default. We will start very gradual rollout.

featuresSize + segmentsSize,
);

await this.clientFeatureToggleService.getClientDelta(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are just making the same call in delta API to request for cache update.

try {
const featuresSize = this.getCacheSizeInBytes(features);
const segmentsSize = this.getCacheSizeInBytes(segments);
this.clientFeaturesCacheMap.set(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saving the current key into cache.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again: can query be undefined here (because we force it with ! later)?

So is this the size of the query without delta or with?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now. This is specified in the store footprint method. This is for features.

);
this.storeFootprint();
} catch (e) {
this.logger.error('Delta diff failed', e);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting all in try catch if something fails for extra safety.


await this.clientFeatureToggleService.getClientDelta(
undefined,
query!,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will query not be present? This ! is a little icky

try {
const featuresSize = this.getCacheSizeInBytes(features);
const segmentsSize = this.getCacheSizeInBytes(segments);
this.clientFeaturesCacheMap.set(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again: can query be undefined here (because we force it with ! later)?

So is this the size of the query without delta or with?

try {
const featuresSize = this.getCacheSizeInBytes(features);
const segmentsSize = this.getCacheSizeInBytes(segments);
this.clientFeaturesCacheMap.set(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now. This is specified in the store footprint method. This is for features.


storeFootprint() {
try {
const featuresMemory = this.getCacheSizeInBytes(this.delta);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many of these do we keep at the same time? Help me wrap my head around this: can the delta be different for each connected client (assuming they're polling and you're making a flag change every second)?

presumably this uses the revision id to store something, right, so it doesn't need that. I ... remember you saying something about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We keep a delta for each environment. So all clients that connect from same environment, share it.

@sjaanus sjaanus merged commit b701fec into main Dec 19, 2024
8 checks passed
@sjaanus sjaanus deleted the delta-rev branch December 19, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants