mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 15:26:15 +08:00
loggign ad provider to prometheus
This commit is contained in:
parent
e97db0cb5a
commit
3fb761d3ee
|
@ -1,9 +1,20 @@
|
|||
import * as PsaDAL from "../../dal/psa";
|
||||
import { MonkeyResponse } from "../../utils/monkey-response";
|
||||
import { recordAdAbTest } from "../../utils/prometheus";
|
||||
|
||||
export async function getPsas(
|
||||
_req: MonkeyTypes.Request
|
||||
req: MonkeyTypes.Request
|
||||
): Promise<MonkeyResponse> {
|
||||
const { adChoiceRaw } = req.query;
|
||||
|
||||
//ensure adchoice raw is a string and either "pw" or "eg"
|
||||
const adChoice =
|
||||
typeof adChoiceRaw === "string" && ["pw", "eg"].includes(adChoiceRaw)
|
||||
? adChoiceRaw
|
||||
: "unknown";
|
||||
|
||||
recordAdAbTest(adChoice);
|
||||
|
||||
const data = await PsaDAL.get();
|
||||
return new MonkeyResponse("PSAs retrieved", data);
|
||||
}
|
||||
|
|
|
@ -322,3 +322,13 @@ export function recordTimeToCompleteJob(
|
|||
timeToCompleteJobTotal.inc({ queueName, jobName }, time);
|
||||
timeToCompleteJobCount.inc({ queueName, jobName });
|
||||
}
|
||||
|
||||
const adAbTest = new Counter({
|
||||
name: "ad_ab_test",
|
||||
help: "Ad AB test",
|
||||
labelNames: ["provider"],
|
||||
});
|
||||
|
||||
export function recordAdAbTest(provider: string): void {
|
||||
adAbTest.inc({ provider });
|
||||
}
|
||||
|
|
|
@ -7,11 +7,14 @@ export default class Psas {
|
|||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
async get(): Ape.EndpointData {
|
||||
async get(adChoice: string): Ape.EndpointData {
|
||||
return await this.httpClient.get(BASE_PATH, {
|
||||
headers: {
|
||||
"Client-Version": CLIENT_VERSION,
|
||||
},
|
||||
searchQuery: {
|
||||
adChoice,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,7 @@ let initialised = false;
|
|||
export let adBlock: boolean;
|
||||
export let cookieBlocker: boolean;
|
||||
|
||||
let choice: "eg" | "pw" = Math.random() < 0.5 ? "eg" : "pw";
|
||||
// let choice: "eg" | "pw" = "eg";
|
||||
export let choice: "eg" | "pw" = Math.random() < 0.5 ? "eg" : "pw";
|
||||
|
||||
console.log("AB choice: " + choice);
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import { isLocalhost, secondsToString } from "../utils/misc";
|
|||
import * as Notifications from "./notifications";
|
||||
import format from "date-fns/format";
|
||||
import * as Alerts from "./alerts";
|
||||
import { choice } from "../controllers/ad-controller";
|
||||
|
||||
function clearMemory(): void {
|
||||
window.localStorage.setItem("confirmedPSAs", JSON.stringify([]));
|
||||
|
@ -19,7 +20,7 @@ function setMemory(id: string): void {
|
|||
}
|
||||
|
||||
async function getLatest(): Promise<MonkeyTypes.PSA[] | null> {
|
||||
const response = await Ape.psas.get();
|
||||
const response = await Ape.psas.get(choice);
|
||||
if (response.status === 500) {
|
||||
if (isLocalhost()) {
|
||||
Notifications.addBanner(
|
||||
|
|
Loading…
Reference in a new issue