MNTOR-3380 - pass nimbus_preview param to Cirrus (#5307)

* pass nimbus_preview param to Cirrus

* simplify URL construction from env var
This commit is contained in:
Robert Helmer 2024-11-18 07:55:30 -08:00 коммит произвёл GitHub
Родитель 7db92ffe2b
Коммит 6198bd99a8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
6 изменённых файлов: 17 добавлений и 26 удалений

Просмотреть файл

@ -51,7 +51,7 @@ type Props = {
slug: string[] | undefined;
};
searchParams: {
nimbus_web_preview?: string;
nimbus_preview?: string;
dialog?: "subscriptions";
};
};
@ -126,7 +126,7 @@ export default async function DashboardPage({ params, searchParams }: Props) {
experimentationId: experimentationId,
countryCode: countryCode,
locale: getLocale(getL10n()),
previewMode: searchParams.nimbus_web_preview === "true",
previewMode: searchParams.nimbus_preview === "true",
});
const monthlySubscriptionUrl = getPremiumSubscriptionUrl({ type: "monthly" });

Просмотреть файл

@ -28,7 +28,7 @@ import { checkUserHasMonthlySubscription } from "../../../../../../functions/ser
import { getEmailPreferenceForPrimaryEmail } from "../../../../../../../db/tables/subscriber_email_preferences";
type Props = {
searchParams: {
nimbus_web_preview?: string;
nimbus_preview?: string;
};
};
@ -79,7 +79,7 @@ export default async function SettingsPage({ searchParams }: Props) {
experimentationId: experimentationId,
countryCode: countryCode,
locale: getLocale(getL10n()),
previewMode: searchParams.nimbus_web_preview === "true",
previewMode: searchParams.nimbus_preview === "true",
});
const lastOneRepScan = await getLatestOnerepScan(

Просмотреть файл

@ -25,7 +25,7 @@ type Props = {
};
searchParams: {
referrer?: string;
nimbus_web_preview?: string;
nimbus_preview?: string;
};
};
@ -67,7 +67,7 @@ export default async function Onboarding({ params, searchParams }: Props) {
experimentationId,
countryCode,
locale: getLocale(getL10n()),
previewMode: searchParams.nimbus_web_preview === "true",
previewMode: searchParams.nimbus_preview === "true",
});
return (

Просмотреть файл

@ -24,7 +24,7 @@ import { AccountsMetricsFlowProvider } from "../../../../contextProviders/accoun
type Props = {
searchParams: {
nimbus_web_preview?: string;
nimbus_preview?: string;
};
};
@ -41,7 +41,7 @@ export default async function Page({ searchParams }: Props) {
experimentationId,
countryCode,
locale: getLocale(getL10n()),
previewMode: searchParams.nimbus_web_preview === "true",
previewMode: searchParams.nimbus_preview === "true",
});
// request the profile stats for the last 30 days

Просмотреть файл

@ -92,7 +92,7 @@ export async function POST(
experimentationId: experimentationId,
countryCode: getCountryCode(headers()),
locale: getLocale(getL10n()),
previewMode: searchParams.get("nimbus_web_preview") === "true",
previewMode: searchParams.get("nimbus_preview") === "true",
});
const optionalInfoExperimentData =
experimentData["welcome-scan-optional-info"];

Просмотреть файл

@ -28,30 +28,21 @@ export async function getExperiments(params: {
countryCode: string;
previewMode: boolean;
}): Promise<ExperimentData> {
// TODO MNTOR-3380 - until Cirrus implements preview mode, set all Nimbus features to `true` for QA purposes.
if (params.previewMode === true) {
// Clone the `localExperimentData` object so we don't modify the exported data structure.
const overriddenExperimentData = Object.fromEntries(
Object.entries(localExperimentData).map(
([experimentId, experimentConfig]) => {
return [experimentId, { ...experimentConfig, enabled: true }];
},
),
) as ExperimentData;
return overriddenExperimentData;
}
if (["local"].includes(process.env.APP_ENV ?? "local")) {
return localExperimentData;
}
const serverUrl = process.env.NIMBUS_SIDECAR_URL;
if (!serverUrl) {
if (!process.env.NIMBUS_SIDECAR_URL) {
throw new Error("env var NIMBUS_SIDECAR_URL not set");
}
const serverUrl = new URL(`${process.env.NIMBUS_SIDECAR_URL}/v1/features`);
try {
const response = await fetch(`${serverUrl}/v1/features`, {
if (params.previewMode === true) {
serverUrl.searchParams.set("nimbus_preview", "true");
}
const response = await fetch(serverUrl, {
headers: {
"Content-Type": "application/json",
},
@ -70,7 +61,7 @@ export async function getExperiments(params: {
return (experimentData as ExperimentData) ?? defaultExperimentData;
} catch (ex) {
logger.error(`Could not connect to Cirrus on ${serverUrl}`, ex);
logger.error("Could not connect to Cirrus", { serverUrl, ex });
captureException(ex);
return defaultExperimentData;
}