Skip to content

Commit

Permalink
FOLLOW-1337: Disable FORCE_CALL_STRATEGY for 10% of sessions (#5593)
Browse files Browse the repository at this point in the history
# Motivation

We want to re-enable the update calls that are disabled via
FORCE_CALL_STRATEGY.
Because this may result in higher subnet load, we want to first roll
this out for 10% of sessions.

# Changes

1. Initialize `FORCE_CALL_STRATEGY` on app load, to `"query"` 90% of the
time and to `undefined` 10% of the time.
2. Output what it was initialized to, in case we need to know this later
for trouble shooting.

# Tests

1. Manually tested by checking the logged value and by adding additional
logging in `queryAndUpdate`.
2. `FORCE_CALL_STRATEGY` itself has existing test coverage so it should
work either way.

# Todos

- [x] Add entry to changelog (if necessary).
  • Loading branch information
dskloetd authored Oct 9, 2024
1 parent f5e7bcc commit 481e839
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-Nns-Dapp-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ proposal is successful, the changes it released will be moved from this file to
#### Changed

* Fetch TVL from NNS dapp canister instead of TVL canister.
* `10%` rollout of re-enabling of certification of certain calls.

#### Deprecated

Expand Down
28 changes: 27 additions & 1 deletion frontend/src/lib/constants/mockable.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,33 @@

export const DEV = import.meta.env.DEV;

export const FORCE_CALL_STRATEGY: "query" | undefined = "query";
// We use FORCE_CALL_STRATEGY to turn query+update into just a query call in a
// number of places. We want to go back to doing query+update calls in all these
// places. We want to do this as a percentage rollout.
//
// 0: means we still do only query calls in these places.
// 100: means we do query+update calls in all these places.
// 10: means we do query+update calls in these places for 10% of sessions.
//
// Whether we do query+update calls remains fixed for the duration of the
// sessions, by which we mean until the next time the app/page is reloaded.
const RESTORE_QUERY_AND_UPDATE_ROLLOUT_PERCENTAGE: number = 10;

const getForceCallStrategyForPercentage = (
percentage: number
): undefined | "query" => {
return Math.random() * 100 <= percentage ? undefined : "query";
};

const initForceCallStrategy = (): undefined | "query" => {
const strategy = getForceCallStrategyForPercentage(
RESTORE_QUERY_AND_UPDATE_ROLLOUT_PERCENTAGE
);
console.info("FORCE_CALL_STRATEGY is initialized to:", strategy);
return strategy;
};

export const FORCE_CALL_STRATEGY: "query" | undefined = initForceCallStrategy();

export const isForceCallStrategy = (): boolean =>
FORCE_CALL_STRATEGY === "query";
Expand Down

0 comments on commit 481e839

Please sign in to comment.