Skip to content

Commit 094beaa

Browse files
committed
feat(observability): utilise new logger in stats-web
ref #436
1 parent 8ad72fa commit 094beaa

64 files changed

Lines changed: 1314 additions & 292 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/api/CHANGELOG.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11

22

3+
## [2.35.2-beta.0](https://github.com/akash-network/console/compare/console-api/v2.35.1...console-api/v2.35.2-beta.0) (2024-11-28)
4+
5+
6+
### Bug Fixes
7+
8+
* **observability:** ensure pino-pretty works in built app ([7f6f9ca](https://github.com/akash-network/console/commit/7f6f9ca7ca4e1ff4bc3b85735270f61cc8120242)), closes [#474](https://github.com/akash-network/console/issues/474)
9+
10+
## [2.35.1](https://github.com/akash-network/console/compare/console-api/v2.35.1-beta.1...console-api/v2.35.1) (2024-11-28)
11+
12+
## [2.35.1-beta.1](https://github.com/akash-network/console/compare/console-api/v2.35.1-beta.0...console-api/v2.35.1-beta.1) (2024-11-28)
13+
14+
15+
### Bug Fixes
16+
17+
* **deployment:** provider deployments query fix ([4278bbd](https://github.com/akash-network/console/commit/4278bbd718d56a71d49baefd73d1b2d35e427aff)), closes [#504](https://github.com/akash-network/console/issues/504)
18+
19+
## [2.35.1-beta.0](https://github.com/akash-network/console/compare/console-api/v2.35.0...console-api/v2.35.1-beta.0) (2024-11-28)
20+
21+
22+
### Bug Fixes
23+
24+
* **deployment:** fix console arg to object mapping ([6126106](https://github.com/akash-network/console/commit/6126106a800d7006b726ff98190e09368cc0c130)), closes [#503](https://github.com/akash-network/console/issues/503)
25+
26+
## [2.35.0](https://github.com/akash-network/console/compare/console-api/v2.35.0-beta.0...console-api/v2.35.0) (2024-11-27)
27+
28+
## [2.35.0-beta.0](https://github.com/akash-network/console/compare/console-api/v2.34.0...console-api/v2.35.0-beta.0) (2024-11-27)
29+
30+
31+
### Features
32+
33+
* **deployment:** clean up trial deployments for a provider ([41018af](https://github.com/akash-network/console/commit/41018afc0593621c4627369b9f114f849e249e44)), closes [#502](https://github.com/akash-network/console/issues/502)
34+
35+
## [2.34.0](https://github.com/akash-network/console/compare/console-api/v2.34.0-beta.1...console-api/v2.34.0) (2024-11-26)
36+
37+
## [2.34.0-beta.1](https://github.com/akash-network/console/compare/console-api/v2.34.0-beta.0...console-api/v2.34.0-beta.1) (2024-11-26)
38+
39+
40+
### Features
41+
42+
* **deployment:** implement ato top up setting ([1301314](https://github.com/akash-network/console/commit/130131485a68f699587415f96283e0dc83072502)), closes [#412](https://github.com/akash-network/console/issues/412)
43+
344
## [2.34.0-beta.0](https://github.com/akash-network/console/compare/console-api/v2.33.1...console-api/v2.34.0-beta.0) (2024-11-23)
445

546

‎apps/api/mvm.lock‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"@akashnetwork/database": "1.0.0",
44
"@akashnetwork/env-loader": "1.0.1",
55
"@akashnetwork/http-sdk": "1.0.8",
6-
"@akashnetwork/logging": "2.0.1"
6+
"@akashnetwork/logging": "2.0.2"
77
}
88
}

‎apps/api/package.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@akashnetwork/console-api",
3-
"version": "2.34.0-beta.0",
3+
"version": "2.35.2-beta.0",
44
"description": "Api providing data to the deploy tool",
55
"repository": {
66
"type": "git",
@@ -54,9 +54,9 @@
5454
"@hono/swagger-ui": "0.2.1",
5555
"@hono/zod-openapi": "0.9.5",
5656
"@octokit/rest": "^18.12.0",
57-
"@opentelemetry/instrumentation": "^0.54.0",
58-
"@opentelemetry/instrumentation-http": "^0.54.0",
59-
"@opentelemetry/sdk-node": "^0.54.0",
57+
"@opentelemetry/instrumentation": "^0.54.2",
58+
"@opentelemetry/instrumentation-http": "^0.54.2",
59+
"@opentelemetry/sdk-node": "^0.54.2",
6060
"@sentry/node": "^7.55.2",
6161
"@supercharge/promise-pool": "^3.2.0",
6262
"@ucast/core": "^1.10.2",
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { LoggerService } from "@akashnetwork/logging";
2+
import { singleton } from "tsyringe";
3+
4+
import { BillingConfig, InjectBillingConfig } from "@src/billing/providers";
5+
import { UserWalletOutput, UserWalletRepository } from "@src/billing/repositories";
6+
import { ManagedUserWalletService, RpcMessageService } from "@src/billing/services";
7+
import { ErrorService } from "@src/core/services/error/error.service";
8+
import { ProviderCleanupSummarizer } from "@src/deployment/lib/provider-cleanup-summarizer/provider-cleanup-summarizer";
9+
import { DeploymentRepository } from "@src/deployment/repositories/deployment/deployment.repository";
10+
import { TxSignerService } from "../tx-signer/tx-signer.service";
11+
12+
export interface ProviderCleanupParams {
13+
concurrency: number;
14+
provider: string;
15+
dryRun: boolean;
16+
}
17+
18+
@singleton()
19+
export class ProviderCleanupService {
20+
private readonly logger = LoggerService.forContext(ProviderCleanupService.name);
21+
22+
constructor(
23+
@InjectBillingConfig() private readonly config: BillingConfig,
24+
private readonly userWalletRepository: UserWalletRepository,
25+
private readonly managedUserWalletService: ManagedUserWalletService,
26+
private readonly txSignerService: TxSignerService,
27+
private readonly deploymentRepository: DeploymentRepository,
28+
private readonly rpcMessageService: RpcMessageService,
29+
private readonly errorService: ErrorService
30+
) {}
31+
32+
async cleanup(options: ProviderCleanupParams) {
33+
const summary = new ProviderCleanupSummarizer();
34+
await this.userWalletRepository.paginate({ query: { isTrialing: true }, limit: options.concurrency || 10 }, async wallets => {
35+
const cleanUpAllWallets = wallets.map(async wallet => {
36+
await this.errorService.execWithErrorHandler(
37+
{
38+
wallet,
39+
event: "PROVIDER_CLEAN_UP_ERROR",
40+
context: ProviderCleanupService.name
41+
},
42+
() => this.cleanUpForWallet(wallet, options, summary)
43+
);
44+
});
45+
46+
await Promise.all(cleanUpAllWallets);
47+
});
48+
49+
this.logger.info({ event: "PROVIDER_CLEAN_UP_SUMMARY", summary: summary.summarize(), dryRun: options.dryRun });
50+
}
51+
52+
private async cleanUpForWallet(wallet: UserWalletOutput, options: ProviderCleanupParams, summary: ProviderCleanupSummarizer) {
53+
const client = await this.txSignerService.getClientForAddressIndex(wallet.id);
54+
const deployments = await this.deploymentRepository.findDeploymentsForProvider({
55+
owner: wallet.address,
56+
provider: options.provider
57+
});
58+
59+
const closeAllWalletStaleDeployments = deployments.map(async deployment => {
60+
const message = this.rpcMessageService.getCloseDeploymentMsg(wallet.address, deployment.dseq);
61+
this.logger.info({ event: "PROVIDER_CLEAN_UP", params: { owner: wallet.address, dseq: deployment.dseq } });
62+
63+
try {
64+
if (!options.dryRun) {
65+
await client.signAndBroadcast([message]);
66+
this.logger.info({ event: "PROVIDER_CLEAN_UP_SUCCESS" });
67+
}
68+
} catch (error) {
69+
if (error.message.includes("not allowed to pay fees")) {
70+
if (!options.dryRun) {
71+
await this.managedUserWalletService.authorizeSpending({
72+
address: wallet.address,
73+
limits: {
74+
fees: this.config.FEE_ALLOWANCE_REFILL_AMOUNT
75+
}
76+
});
77+
await client.signAndBroadcast([message]);
78+
this.logger.info({ event: "PROVIDER_CLEAN_UP_SUCCESS" });
79+
}
80+
} else {
81+
throw error;
82+
}
83+
} finally {
84+
summary.inc("deploymentCount");
85+
}
86+
});
87+
88+
await Promise.all(closeAllWalletStaleDeployments);
89+
}
90+
}

‎apps/api/src/console.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { chainDb } from "@src/db/dbConnection";
1414
import { TopUpDeploymentsController } from "@src/deployment/controllers/deployment/deployment.controller";
1515
import { UserController } from "@src/user/controllers/user/user.controller";
1616
import { UserConfigService } from "@src/user/services/user-config/user-config.service";
17+
import { ProviderController } from "./deployment/controllers/provider/provider.controller";
1718

1819
const program = new Command();
1920

@@ -42,13 +43,25 @@ program
4243
program
4344
.command("cleanup-stale-deployments")
4445
.description("Close deployments without leases created at least 10min ago")
45-
.option("-c, --concurrency <number>", "How much wallets is processed concurrently", value => z.number({ coerce: true }).optional().default(10).parse(value))
46+
.option("-c, --concurrency <number>", "How many wallets is processed concurrently", value => z.number({ coerce: true }).optional().default(10).parse(value))
4647
.action(async (options, command) => {
4748
await executeCliHandler(command.name(), async () => {
4849
await container.resolve(TopUpDeploymentsController).cleanUpStaleDeployment(options);
4950
});
5051
});
5152

53+
program
54+
.command("cleanup-provider-deployments")
55+
.description("Close trial deployments for a provider")
56+
.option("-c, --concurrency <number>", "How many wallets is processed concurrently", value => z.number({ coerce: true }).optional().default(10).parse(value))
57+
.option("-d, --dry-run", "Dry run the trial provider cleanup", false)
58+
.option("-p, --provider <string>", "Provider address", value => z.string().parse(value))
59+
.action(async (options, command) => {
60+
await executeCliHandler(command.name(), async () => {
61+
await container.resolve(ProviderController).cleanupProviderDeployments(options);
62+
});
63+
});
64+
5265
const userConfig = container.resolve(UserConfigService);
5366
program
5467
.command("cleanup-stale-anonymous-users")
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import { singleton } from "tsyringe";
22

3+
import { ProviderCleanupParams, ProviderCleanupService } from "@src/billing/services/provider-cleanup/provider-cleanup.service";
34
import { TrialProvidersService } from "@src/deployment/services/trial-providers/trial-providers.service";
45

56
@singleton()
67
export class ProviderController {
7-
constructor(private readonly trialProvidersService: TrialProvidersService) {}
8+
constructor(
9+
private readonly trialProvidersService: TrialProvidersService,
10+
private readonly providerCleanupService: ProviderCleanupService
11+
) {}
812

913
async getTrialProviders(): Promise<string[]> {
1014
return await this.trialProvidersService.getTrialProviders();
1115
}
16+
17+
async cleanupProviderDeployments(options: ProviderCleanupParams) {
18+
return await this.providerCleanupService.cleanup(options);
19+
}
1220
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
interface ProviderCleanupSummary {
2+
deploymentCount: number;
3+
}
4+
5+
export class ProviderCleanupSummarizer {
6+
private deploymentCount = 0;
7+
8+
inc(param: keyof ProviderCleanupSummary, value = 1) {
9+
this[param] += value;
10+
}
11+
12+
set(param: keyof ProviderCleanupSummary, value: number) {
13+
this[param] = value;
14+
}
15+
16+
get(param: keyof ProviderCleanupSummary) {
17+
return this[param];
18+
}
19+
20+
summarize(): ProviderCleanupSummary {
21+
return {
22+
deploymentCount: this.deploymentCount
23+
};
24+
}
25+
}

‎apps/api/src/deployment/repositories/deployment/deployment.repository.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export interface StaleDeploymentsOptions {
77
owner: string;
88
}
99

10+
export interface ProviderCleanupOptions {
11+
owner: string;
12+
provider: string;
13+
}
14+
1015
export interface StaleDeploymentsOutput {
1116
dseq: number;
1217
}
@@ -37,4 +42,27 @@ export class DeploymentRepository {
3742

3843
return deployments ? (deployments as unknown as StaleDeploymentsOutput[]) : [];
3944
}
45+
46+
async findDeploymentsForProvider(options: ProviderCleanupOptions): Promise<StaleDeploymentsOutput[]> {
47+
const deployments = await Deployment.findAll({
48+
attributes: ["dseq"],
49+
where: {
50+
owner: options.owner,
51+
closedHeight: null
52+
},
53+
include: [
54+
{
55+
model: Lease,
56+
attributes: [],
57+
required: true,
58+
where: {
59+
providerAddress: options.provider
60+
}
61+
}
62+
],
63+
raw: true
64+
});
65+
66+
return deployments ? (deployments as unknown as StaleDeploymentsOutput[]) : [];
67+
}
4068
}

‎apps/api/test/seeders/deployment-grant.seeder.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export class DeploymentGrantSeeder {
1818
spend_limit: {
1919
denom: DenomSeeder.create(),
2020
amount: faker.number.int({ min: 0, max: 10000000 }).toString()
21-
},
22-
expiration: faker.date.future().toISOString()
23-
}
21+
}
22+
},
23+
expiration: faker.date.future().toISOString()
2424
},
2525
input
2626
);

‎apps/deploy-web/CHANGELOG.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11

22

3+
## [2.25.1-beta.0](https://github.com/akash-network/console/compare/console-web/v2.25.0...console-web/v2.25.1-beta.0) (2024-11-28)
4+
5+
6+
### Bug Fixes
7+
8+
* **observability:** ensure pino-pretty works in built app ([7f6f9ca](https://github.com/akash-network/console/commit/7f6f9ca7ca4e1ff4bc3b85735270f61cc8120242)), closes [#474](https://github.com/akash-network/console/issues/474)
9+
10+
## [2.25.0](https://github.com/akash-network/console/compare/console-web/v2.25.0-beta.1...console-web/v2.25.0) (2024-11-26)
11+
12+
## [2.25.0-beta.1](https://github.com/akash-network/console/compare/console-web/v2.25.0-beta.0...console-web/v2.25.0-beta.1) (2024-11-26)
13+
14+
15+
### Features
16+
17+
* **deployment:** implement ato top up setting ([1301314](https://github.com/akash-network/console/commit/130131485a68f699587415f96283e0dc83072502)), closes [#412](https://github.com/akash-network/console/issues/412)
18+
19+
20+
### Bug Fixes
21+
22+
* **billing:** ensure checkout pricing is displayed correctly ([3bcb4a8](https://github.com/akash-network/console/commit/3bcb4a881e3bb58e741de8bb8a0a661dede0d8ae))
23+
324
## [2.25.0-beta.0](https://github.com/akash-network/console/compare/console-web/v2.24.1...console-web/v2.25.0-beta.0) (2024-11-23)
425

526

0 commit comments

Comments
 (0)