import { Request, Response } from "express"; import { BaseController } from "./BaseController"; import MetricService, { BucketSet } from "../services/metric.service"; import constants from "../utils/constants"; import InternalFunnel from "../funnels/internal.funnel"; import HeaderBiddingFunnel from "../funnels/header-bidding.funnel"; const heapdump = require("heapdump"); export class InternalApiController extends BaseController { metricService: MetricService; constructor( private readonly internalInventoryService: InternalFunnel, private readonly headerBiddingService: HeaderBiddingFunnel ) { super(); this.post("/bestCampaigns", this.chooseInternal); this.post("/header-bidding", this.chooseHeaderBidding); this.get("/memory", this.memorySnapshot); this.metricService = MetricService.getInstance(); this.metricService.addSection( constants.CHOICES_REQUEST_SECTION, constants.CHOICES_REQUEST_SECTION_LABELS, BucketSet.zeroTo600ms ); } async chooseHeaderBidding(req: Request, res: Response) { const request = JSON.parse(req.body); return this.headerBiddingService.choose(request, res); } async chooseInternal(req: Request, res: Response) { const request = JSON.parse(req.body); return this.internalInventoryService.choose(request, res); } async memorySnapshot(_req: Request, res: Response) { res.status(200); res.send(); heapdump.writeSnapshot("/var/local/" + Date.now() + ".heapsnapshot"); } }