Skip to content

Commit

Permalink
fix: propagate SDK version to FeatureHub
Browse files Browse the repository at this point in the history
Propagate GoodData.UI SDK version to FeatureHub, so we can
use it as a split rule.

JIRA: F1-815
  • Loading branch information
kandl committed Oct 16, 2024
1 parent 832d1d2 commit 5791eb7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions libs/api-client-tiger/api/api-client-tiger.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7646,6 +7646,7 @@ export type FeatureContext = {
organizationId: string;
earlyAccessValues: string[];
tier: string;
jsSdkVersion: string;
};

// @public
Expand Down
1 change: 1 addition & 0 deletions libs/api-client-tiger/src/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type FeatureContext = {
organizationId: string;
earlyAccessValues: string[];
tier: string;
jsSdkVersion: string;
};

export interface ILiveFeatures {
Expand Down
4 changes: 4 additions & 0 deletions libs/sdk-backend-tiger/src/backend/features/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ async function getFeatureHubData(
featureHubFlags.push(`tier=${encodeURIComponent(context.tier)}`);
}

if (context.jsSdkVersion) {
featureHubFlags.push(`jsSdkVersion=${encodeURIComponent(context.jsSdkVersion)}`);
}

return axios.get("/features", {
method: "GET",
baseURL: host,
Expand Down
20 changes: 15 additions & 5 deletions libs/sdk-backend-tiger/src/backend/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import { ITigerFeatureFlags, DefaultFeatureFlags } from "../uiFeatures.js";

import { getFeatureHubFeatures } from "./hub.js";
import { getStaticFeatures } from "./static.js";
import { LIB_VERSION } from "../../__version.js";

const getKeyFromContext = (wsContext?: Partial<FeatureContext>): string => {
return `${wsContext?.organizationId}-${wsContext?.earlyAccessValues?.join(",")}`;
return `${wsContext?.organizationId}-${wsContext?.tier}-${
wsContext?.jsSdkVersion
}-${wsContext?.earlyAccessValues?.join(",")}`;
};
const responseMap: LRUCache<string, Promise<ITigerFeatureFlags>> = new LRUCache<
string,
Expand All @@ -32,20 +35,24 @@ export class TigerFeaturesService {
profile?: IUserProfile,
wsContext?: Partial<FeatureContext>,
): Promise<ITigerFeatureFlags> {
const cachedResponse = responseMap.get(getKeyFromContext(wsContext));
const contextWithVersion: Partial<FeatureContext> = {
...wsContext,
jsSdkVersion: LIB_VERSION,
};
const cachedResponse = responseMap.get(getKeyFromContext(contextWithVersion));
if (cachedResponse) {
return cachedResponse;
}
const response = this.authCall(async (client) => {
const prof = profile || (await client.profile.getCurrent());
const results = await loadFeatures(prof, wsContext);
const results = await loadFeatures(prof, contextWithVersion);

return {
...DefaultFeatureFlags,
...results,
};
});
responseMap.set(getKeyFromContext(wsContext), response);
responseMap.set(getKeyFromContext(contextWithVersion), response);
return response;
}
}
Expand Down Expand Up @@ -79,7 +86,10 @@ export function pickContext(
organizationId: string | undefined,
entitlements: ApiEntitlement[],
): Partial<FeatureContext> {
const context: Partial<FeatureContext> = {};
const context: Partial<FeatureContext> = {
jsSdkVersion: LIB_VERSION,
};

const tier = getOrganizationTier(entitlements);

if (attributes?.earlyAccessValues !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { unwrapSettingContent } from "../../../convertors/fromBackend/SettingsCo
import { TigerSettingsService, mapTypeToKey } from "../../settings/index.js";
import { GET_OPTIMIZED_WORKSPACE_PARAMS } from "../constants.js";
import { FeatureContext, isLiveFeatures, isStaticFeatures } from "@gooddata/api-client-tiger";
import { LIB_VERSION } from "../../../__version.js";

export class TigerWorkspaceSettings
extends TigerSettingsService<IWorkspaceSettings>
Expand Down Expand Up @@ -191,7 +192,9 @@ export function getSettingsForCurrentUser(

const resolvedSettings: ISettings = await resolveSettings(authCall, workspace);

const context: Partial<FeatureContext> = {};
const context: Partial<FeatureContext> = {
jsSdkVersion: LIB_VERSION,
};

const staticFeaturesEarlyAccess = isStaticFeatures(profile.features)
? profile.features?.static?.context?.earlyAccessValues ?? []
Expand Down

0 comments on commit 5791eb7

Please sign in to comment.