Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,15 @@ describe("DataRetentionService", () => {
// confirmedTotalSuccess = 100 - 10 = 90
expect(counterMock.labels).toHaveBeenCalledWith({
checkType: "dataRetention",
network: "calibration",
providerId: "1",
providerName: "Provider A",
providerStatus: "approved",
value: "failure",
});
expect(counterMock.labels).toHaveBeenCalledWith({
checkType: "dataRetention",
network: "calibration",
providerId: "1",
providerName: "Provider A",
providerStatus: "approved",
Expand Down Expand Up @@ -379,13 +381,15 @@ describe("DataRetentionService", () => {
// confirmedTotalSuccess = 100 - 10 = 90
expect(counterMock.labels).toHaveBeenCalledWith({
checkType: "dataRetention",
network: "calibration",
providerId: "1",
providerName: "Provider A",
providerStatus: "approved",
value: "failure",
});
expect(counterMock.labels).toHaveBeenCalledWith({
checkType: "dataRetention",
network: "calibration",
providerId: "1",
providerName: "Provider A",
providerStatus: "approved",
Expand Down Expand Up @@ -673,12 +677,14 @@ describe("DataRetentionService", () => {
providerId: 1n,
providerName: "Provider A",
providerIsApproved: true,
network: "calibration",
});
const unapprovedLabels = buildCheckMetricLabels({
checkType: "dataRetention",
providerId: 1n,
providerName: "Provider A",
providerIsApproved: false,
network: "calibration",
});
expect(counterMock.remove).toHaveBeenCalledWith({ ...approvedLabels, value: "success" });
expect(counterMock.remove).toHaveBeenCalledWith({ ...approvedLabels, value: "failure" });
Expand Down Expand Up @@ -1267,12 +1273,14 @@ describe("DataRetentionService", () => {
providerId: 1n,
providerName: "Provider A",
providerIsApproved: true,
network: "calibration",
});
const unapprovedLabels = buildCheckMetricLabels({
checkType: "dataRetention",
providerId: 1n,
providerName: "Provider A",
providerIsApproved: false,
network: "calibration",
});
expect(gaugeMock.remove).toHaveBeenCalledWith(approvedLabels);
expect(gaugeMock.remove).toHaveBeenCalledWith(unapprovedLabels);
Expand Down
9 changes: 6 additions & 3 deletions apps/backend/src/data-retention/data-retention.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ClickhouseService } from "../clickhouse/clickhouse.service.js";
import { toStructuredError } from "../common/logging.js";
import { isSpBlocked } from "../common/sp-blocklist.js";
import type { Network } from "../common/types.js";
import { IBlockchainConfig, IConfig } from "../config/app.config.js";
import { IConfig } from "../config/app.config.js";
import { DataRetentionBaseline } from "../database/entities/data-retention-baseline.entity.js";
import { StorageProvider } from "../database/entities/storage-provider.entity.js";
import { buildCheckMetricLabels, CheckMetricLabels } from "../metrics-prometheus/check-metric-labels.js";
Expand Down Expand Up @@ -72,8 +72,7 @@ export class DataRetentionService {
* challenge delta since the last poll.
*/
async pollDataRetention(): Promise<void> {
const blockchainCfg = this.configService.get<IBlockchainConfig>("blockchain");
const { network, pdpSubgraphEndpoint } = blockchainCfg;
const { network, pdpSubgraphEndpoint } = this.configService.get("blockchain", { infer: true });
if (!pdpSubgraphEndpoint) {
this.logger.error({
event: "pdp_subgraph_endpoint_not_configured",
Expand Down Expand Up @@ -299,12 +298,14 @@ export class DataRetentionService {

if (provider && provider.providerId != null) {
const approvedLabels = buildCheckMetricLabels({
network,
checkType: "dataRetention",
providerId: provider.providerId,
providerName: provider.name,
providerIsApproved: true,
});
const unapprovedLabels = buildCheckMetricLabels({
network,
checkType: "dataRetention",
providerId: provider.providerId,
providerName: provider.name,
Expand Down Expand Up @@ -408,11 +409,13 @@ export class DataRetentionService {
successPeriods: confirmedTotalSuccess,
};

const network = this.configService.get("blockchain", { infer: true }).network;
const providerLabels = buildCheckMetricLabels({
checkType: "dataRetention",
providerId: pdpProvider.id,
providerName: pdpProvider.name,
providerIsApproved: pdpProvider.isApproved,
network,
});

// Emit overdue periods gauge on every poll — this is a separate signal from the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { ConfigService } from "@nestjs/config";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { IConfig } from "../config/app.config.js";
import { DataSetLifecycleCheckMetrics } from "../metrics-prometheus/check-metrics.service.js";
import { WalletSdkService } from "../wallet-sdk/wallet-sdk.service.js";
import { DataSetLifecycleService } from "./data-set-lifecycle.service.js";
Expand Down Expand Up @@ -48,6 +50,10 @@ const mockMetrics = {
recordStatus: vi.fn(),
} as unknown as DataSetLifecycleCheckMetrics;

const mockConfigService = {
get: vi.fn(() => ({ network: "calibration" })),
} as unknown as ConfigService<IConfig, true>;

function setupEmptyVariantMocks() {
vi.mocked(createDataSet).mockResolvedValue({ txHash: "0xhash1", statusUrl: "https://sp.example.com/status/1" });
vi.mocked(waitForCreateDataSet).mockResolvedValue({
Expand Down Expand Up @@ -96,7 +102,7 @@ describe("DataSetLifecycleService", () => {

beforeEach(() => {
vi.clearAllMocks();
service = new DataSetLifecycleService(mockWalletSdkService, mockMetrics);
service = new DataSetLifecycleService(mockWalletSdkService, mockMetrics, mockConfigService);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {
waitForTerminateService,
} from "@filoz/synapse-core/sp";
import { Injectable, Logger } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { awaitWithAbort } from "../common/abort-utils.js";
import { type ProviderJobContext, toStructuredError } from "../common/logging.js";
import type { IConfig } from "../config/app.config.js";
import { buildCheckMetricLabels, classifyFailureStatus } from "../metrics-prometheus/check-metric-labels.js";
import { DataSetLifecycleCheckMetrics } from "../metrics-prometheus/check-metrics.service.js";
import type { SynapseViemClient } from "../wallet-sdk/wallet-sdk.service.js";
Expand Down Expand Up @@ -50,6 +52,7 @@ export class DataSetLifecycleService {
constructor(
private readonly walletSdkService: WalletSdkService,
private readonly lifecycleCheckMetrics: DataSetLifecycleCheckMetrics,
private readonly configService: ConfigService<IConfig, true>,
) {}

/**
Expand Down Expand Up @@ -93,6 +96,7 @@ export class DataSetLifecycleService {

const labels = buildCheckMetricLabels({
checkType: "dataSetLifecycleCheck",
network: this.configService.get("blockchain", { infer: true }).network,
providerId: providerInfo.id,
providerName: providerInfo.name,
providerIsApproved: providerInfo.isApproved,
Expand Down
26 changes: 24 additions & 2 deletions apps/backend/src/deal-addons/strategies/ipni.strategy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CID } from "multiformats/cid";
import type { Mock } from "vitest";
import { describe, expect, it, vi } from "vitest";
import type { Network } from "../../common/types.js";
import { Deal } from "../../database/entities/deal.entity.js";
import { StorageProvider } from "../../database/entities/storage-provider.entity.js";
import { IpniStatus, ServiceType } from "../../database/types.js";
Expand All @@ -11,6 +12,7 @@ import { IpniAddonStrategy } from "./ipni.strategy.js";

describe("IpniAddonStrategy getPieceStatus", () => {
type DealForMetrics = {
network: Network;
spAddress?: string;
storageProvider?: {
providerId?: bigint;
Expand Down Expand Up @@ -49,6 +51,7 @@ describe("IpniAddonStrategy getPieceStatus", () => {
Object.assign(new Deal(), {
id: "deal-1",
spAddress: "0xsp",
network: "calibration",
fileName: "file",
fileSize: 1,
walletAddress: "0xwallet",
Expand All @@ -74,6 +77,7 @@ describe("IpniAddonStrategy getPieceStatus", () => {
if (!deal?.spAddress) return null;
return buildCheckMetricLabels({
checkType: "dataStorage",
network: deal.network,
providerId: deal.storageProvider?.providerId,
providerName: deal.storageProvider?.name,
providerIsApproved: deal.storageProvider?.isApproved,
Expand Down Expand Up @@ -301,6 +305,7 @@ describe("IpniAddonStrategy getPieceStatus", () => {

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "9",
providerName: "SP",
providerStatus: "approved",
Expand Down Expand Up @@ -378,6 +383,7 @@ describe("IpniAddonStrategy getPieceStatus", () => {

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "9",
providerName: "SP",
providerStatus: "approved",
Expand Down Expand Up @@ -471,6 +477,7 @@ describe("IpniAddonStrategy getPieceStatus", () => {

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "9",
providerName: "SP",
providerStatus: "approved",
Expand Down Expand Up @@ -545,7 +552,13 @@ describe("IpniAddonStrategy getPieceStatus", () => {

await strategyForTest.updateDealWithIpniMetrics(deal, result, 10_000, {});

const labels = { checkType: "dataStorage", providerId: "9", providerName: "SP", providerStatus: "approved" };
const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "9",
providerName: "SP",
providerStatus: "approved",
};
expect(discoverabilityMetrics.observeIpniVerifyMs).toHaveBeenCalledWith(
labels,
500,
Expand Down Expand Up @@ -678,7 +691,13 @@ describe("IpniAddonStrategy getPieceStatus", () => {

await expect(strategyForTest.startIpniMonitoring(deal)).resolves.toBeUndefined();

const labels = { checkType: "dataStorage", providerId: "9", providerName: "SP", providerStatus: "approved" };
const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "9",
providerName: "SP",
providerStatus: "approved",
};
const statusCalls = (discoverabilityMetrics.recordStatus as Mock).mock.calls.filter(
([, value]: [unknown, string]) => value.startsWith("failure.") || value === "skipped" || value === "success",
);
Expand Down Expand Up @@ -717,6 +736,7 @@ describe("IpniAddonStrategy getPieceStatus", () => {

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "9",
providerName: "SP",
providerStatus: "approved",
Expand Down Expand Up @@ -756,6 +776,7 @@ describe("IpniAddonStrategy getPieceStatus", () => {

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "9",
providerName: "SP",
providerStatus: "approved",
Expand Down Expand Up @@ -796,6 +817,7 @@ describe("IpniAddonStrategy getPieceStatus", () => {

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "9",
providerName: "SP",
providerStatus: "approved",
Expand Down
5 changes: 5 additions & 0 deletions apps/backend/src/deal/deal.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ describe("DealService", () => {

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "42",
providerName: "Test Provider",
providerStatus: "approved",
Expand Down Expand Up @@ -587,6 +588,7 @@ describe("DealService", () => {

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "7",
providerName: "Test Provider",
providerStatus: "unapproved",
Expand Down Expand Up @@ -621,6 +623,7 @@ describe("DealService", () => {

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "7",
providerName: "Test Provider",
providerStatus: "unapproved",
Expand Down Expand Up @@ -910,6 +913,7 @@ describe("DealService", () => {

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "42",
providerName: "Test Provider",
providerStatus: "approved",
Expand Down Expand Up @@ -959,6 +963,7 @@ describe("DealService", () => {

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "42",
providerName: "Test Provider",
providerStatus: "approved",
Expand Down
6 changes: 5 additions & 1 deletion apps/backend/src/deal/deal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,12 @@ export class DealService implements OnModuleInit, OnModuleDestroy {
extraDataSetMetadata?: Record<string, string>,
logContext?: ProviderJobContext,
): Promise<Deal> {
const network = this.blockchainConfig.network;
const providerAddress = pdpProvider.serviceProvider;
const checkType = "dataStorage" as const;
let providerLabels = buildCheckMetricLabels({
checkType,
network,
providerId: pdpProvider.id,
providerName: pdpProvider.name,
providerIsApproved: pdpProvider.isApproved,
Expand Down Expand Up @@ -312,7 +314,7 @@ export class DealService implements OnModuleInit, OnModuleDestroy {
deal.fileName = dealInput.processedData.name;
deal.fileSize = dealInput.processedData.size;
deal.spAddress = providerAddress;
deal.network = this.blockchainConfig.network;
deal.network = network;
deal.status = DealStatus.PENDING;
deal.walletAddress = this.blockchainConfig.walletAddress;
deal.metadata = dealInput.metadata;
Expand Down Expand Up @@ -343,6 +345,7 @@ export class DealService implements OnModuleInit, OnModuleDestroy {
dealLogContext.providerId = deal.storageProvider?.providerId ?? dealLogContext.providerId;
providerLabels = buildCheckMetricLabels({
checkType,
network,
providerId: deal.storageProvider?.providerId,
providerName: pdpProvider.name ?? deal.storageProvider?.name,
providerIsApproved: pdpProvider.isApproved ?? deal.storageProvider?.isApproved,
Expand Down Expand Up @@ -830,6 +833,7 @@ export class DealService implements OnModuleInit, OnModuleDestroy {
}
const labels = buildCheckMetricLabels({
checkType: "dataSetCreation",
network: this.blockchainConfig.network,
providerId: providerInfo.id,
providerName: providerInfo.name,
providerIsApproved: providerInfo.isApproved,
Expand Down
Loading