mirror of
https://github.com/p-stream/p-stream.git
synced 2026-05-15 13:52:02 +00:00
fix metric reporting with multiple servers
This commit is contained in:
parent
a019f3dab4
commit
0d4c6471ab
1 changed files with 18 additions and 5 deletions
|
|
@ -5,14 +5,27 @@ import { useCallback } from "react";
|
||||||
|
|
||||||
import { isExtensionActiveCached } from "@/backend/extension/messaging";
|
import { isExtensionActiveCached } from "@/backend/extension/messaging";
|
||||||
import { ScrapingItems, ScrapingSegment } from "@/hooks/useProviderScrape";
|
import { ScrapingItems, ScrapingSegment } from "@/hooks/useProviderScrape";
|
||||||
import { BACKEND_URL } from "@/setup/constants";
|
import { conf } from "@/setup/config";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
import { PlayerMeta } from "@/stores/player/slices/source";
|
import { PlayerMeta } from "@/stores/player/slices/source";
|
||||||
|
|
||||||
// for anybody who cares - these are anonymous metrics.
|
// for anybody who cares - these are anonymous metrics.
|
||||||
// They are just used for figuring out if providers are broken or not
|
// They are just used for figuring out if providers are broken or not
|
||||||
const metricsEndpoint = `${BACKEND_URL}/metrics/providers`;
|
// Metrics are always sent to the first configured backend
|
||||||
const captchaMetricsEndpoint = `${BACKEND_URL}/metrics/captcha`;
|
function getMetricsBackendUrl(): string | null {
|
||||||
|
const config = conf();
|
||||||
|
return config.BACKEND_URLS.length > 0
|
||||||
|
? config.BACKEND_URLS[0]
|
||||||
|
: config.BACKEND_URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMetricsEndpoint(path: string): string | null {
|
||||||
|
const backendUrl = getMetricsBackendUrl();
|
||||||
|
return backendUrl ? `${backendUrl}${path}` : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const metricsEndpoint = getMetricsEndpoint("/metrics/providers");
|
||||||
|
const captchaMetricsEndpoint = getMetricsEndpoint("/metrics/captcha");
|
||||||
const batchId = () => nanoid(32);
|
const batchId = () => nanoid(32);
|
||||||
|
|
||||||
export type ProviderMetric = {
|
export type ProviderMetric = {
|
||||||
|
|
@ -45,7 +58,7 @@ function getStackTrace(error: Error, lines: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function reportProviders(items: ProviderMetric[]): Promise<void> {
|
export async function reportProviders(items: ProviderMetric[]): Promise<void> {
|
||||||
if (!BACKEND_URL) return;
|
if (!metricsEndpoint) return;
|
||||||
return ofetch(metricsEndpoint, {
|
return ofetch(metricsEndpoint, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: {
|
body: {
|
||||||
|
|
@ -158,7 +171,7 @@ export function useReportProviders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function reportCaptchaSolve(success: boolean) {
|
export function reportCaptchaSolve(success: boolean) {
|
||||||
if (!BACKEND_URL) return;
|
if (!captchaMetricsEndpoint) return;
|
||||||
ofetch(captchaMetricsEndpoint, {
|
ofetch(captchaMetricsEndpoint, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: {
|
body: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue