Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,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 @@ -380,13 +382,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 @@ -621,12 +625,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 @@ -1215,12 +1221,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 @@ -60,8 +60,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.warn({
event: "pdp_subgraph_endpoint_not_configured",
Expand Down Expand Up @@ -266,12 +265,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 @@ -375,11 +376,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
25 changes: 23 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 @@ -44,6 +46,7 @@ describe("IpniAddonStrategy getPieceStatus", () => {
Object.assign(new Deal(), {
id: "deal-1",
spAddress: "0xsp",
network: "calibration",
fileName: "file",
fileSize: 1,
walletAddress: "0xwallet",
Expand All @@ -68,6 +71,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 @@ -254,6 +258,7 @@ describe("IpniAddonStrategy getPieceStatus", () => {

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

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

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, "error");
});

Expand Down Expand Up @@ -532,7 +544,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 @@ -571,6 +589,7 @@ describe("IpniAddonStrategy getPieceStatus", () => {

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

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "9",
providerName: "SP",
providerStatus: "approved",
Expand Down Expand Up @@ -650,6 +670,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 @@ -392,6 +392,7 @@ describe("DealService", () => {

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

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

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

const labels = {
checkType: "dataStorage",
network: "calibration",
providerId: "42",
providerName: "Test Provider",
providerStatus: "approved",
Expand Down Expand Up @@ -960,6 +964,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 @@ -267,10 +267,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 @@ -865,6 +868,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