Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
feat(branding): report each process's Jev rollout share as a gauge (#5163)
Abimael Martellc31e88c07afe
diff --git a/apps/api/src/__tests__/lib/branding/jev.test.ts b/apps/api/src/__tests__/lib/branding/jev.test.tsindex bbbe9ec43..4e04e779d 100644--- a/apps/api/src/__tests__/lib/branding/jev.test.ts+++ b/apps/api/src/__tests__/lib/branding/jev.test.ts@@ -31,6 +31,7 @@ import {brandingRoutedTotal,brandingJevBreakerOpensTotal,brandingJevCallsTotal,+ brandingJevRolloutPercent,} from "../../../lib/branding/metrics";import { mergeBrandingResults } from "../../../lib/branding/merge";import { BrandingLLMInput } from "../../../lib/branding/types";@@ -992,3 +993,19 @@ describe("branding metrics", () => {expect(mocks.systemOne).not.toHaveBeenCalled();});});++describe("rollout gauge", () => {+ it("reports the share of teams this process sends to Jev", async () => {+ const read = async () =>+ (await brandingJevRolloutPercent.get()).values[0]?.value;++ config.BRANDING_JEV_ROLLOUT_PERCENT = 75;+ expect(await read()).toBe(75);++ config.BRANDING_JEV = true;+ expect(await read()).toBe(100);++ config.TYPESAFE_API_KEY = undefined;+ expect(await read()).toBe(0);+ });+});diff --git a/apps/api/src/lib/branding/metrics.ts b/apps/api/src/lib/branding/metrics.tsindex b3893e06b..a9727a556 100644--- a/apps/api/src/lib/branding/metrics.ts+++ b/apps/api/src/lib/branding/metrics.ts@@ -1,4 +1,5 @@-import { Counter, Histogram } from "prom-client";+import { Counter, Gauge, Histogram } from "prom-client";+import { config } from "../../config";// Fixed labels only: never team ids or anything from the page.@@ -27,6 +28,22 @@ export const brandingJevDurationSeconds = new Histogram({buckets: [0.1, 0.15, 0.2, 0.3, 0.5, 0.75, 1, 1.5, 2, 3, 5, 7.5, 10],});+// Each pod reports the share it was started with; pods that disagree are+// running an older config.+export const brandingJevRolloutPercent = new Gauge({+ name: "firecrawl_branding_jev_rollout_percent",+ help: "Share of teams this process sends to Jev, from its own config: 0 without a TypeSafe key, 100 with BRANDING_JEV on, else BRANDING_JEV_ROLLOUT_PERCENT",+ collect() {+ this.set(effectiveJevRolloutPercent());+ },+});++function effectiveJevRolloutPercent(): number {+ if (!config.TYPESAFE_API_KEY) return 0;+ if (config.BRANDING_JEV === true) return 100;+ return config.BRANDING_JEV_ROLLOUT_PERCENT;+}+export type JevCallOutcome =| "ok"| "timeout"