Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(observability): utilise new logger in stats-web #462

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion .commitlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"repo",
"styling",
"observability",
"analytics"
"analytics",
"template"
]
]
}
Expand Down
43 changes: 43 additions & 0 deletions apps/api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@


## [2.35.2](https://github.com/akash-network/console/compare/console-api/v2.35.2-beta.0...console-api/v2.35.2) (2024-12-02)

## [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)


### Bug Fixes

* **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)

## [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)

## [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)


### Bug Fixes

* **deployment:** provider deployments query fix ([4278bbd](https://github.com/akash-network/console/commit/4278bbd718d56a71d49baefd73d1b2d35e427aff)), closes [#504](https://github.com/akash-network/console/issues/504)

## [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)


### Bug Fixes

* **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)

## [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)

## [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)


### Features

* **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)

## [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)

## [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)


### Features

* **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)

## [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)


Expand Down
2 changes: 1 addition & 1 deletion apps/api/env/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORS_WEBSITE_URLS=https://stats.akash.network,https://console.akash.network,https://akash.network,https://akash.hooman.digital,http://localhost:3000,http://localhost:3001,https://akashconsole.vercel.app,https://console-beta.akash.network
CORS_WEBSITE_URLS=https://stats.akash.network,https://console.akash.network,https://akash.network,https://akash.hooman.digital,http://localhost:3000,http://localhost:3001,https://akashconsole.vercel.app,https://console-beta.akash.network,https://provider-console-beta.akash.network,https://provider-console.akash.network
WEBSITE_URL=https://console-beta.akash.network
TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT=10000000
DEPLOYMENT_ALLOWANCE_REFILL_AMOUNT=10000000
Expand Down
2 changes: 1 addition & 1 deletion apps/api/mvm.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"@akashnetwork/database": "1.0.0",
"@akashnetwork/env-loader": "1.0.1",
"@akashnetwork/http-sdk": "1.0.8",
"@akashnetwork/logging": "2.0.1"
"@akashnetwork/logging": "2.0.2"
}
}
8 changes: 4 additions & 4 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@akashnetwork/console-api",
"version": "2.34.0-beta.0",
"version": "2.35.2",
"description": "Api providing data to the deploy tool",
"repository": {
"type": "git",
Expand Down Expand Up @@ -54,9 +54,9 @@
"@hono/swagger-ui": "0.2.1",
"@hono/zod-openapi": "0.9.5",
"@octokit/rest": "^18.12.0",
"@opentelemetry/instrumentation": "^0.54.0",
"@opentelemetry/instrumentation-http": "^0.54.0",
"@opentelemetry/sdk-node": "^0.54.0",
"@opentelemetry/instrumentation": "^0.54.2",
"@opentelemetry/instrumentation-http": "^0.54.2",
"@opentelemetry/sdk-node": "^0.54.2",
"@sentry/node": "^7.55.2",
"@supercharge/promise-pool": "^3.2.0",
"@ucast/core": "^1.10.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { LoggerService } from "@akashnetwork/logging";
import { singleton } from "tsyringe";

import { BillingConfig, InjectBillingConfig } from "@src/billing/providers";
import { UserWalletOutput, UserWalletRepository } from "@src/billing/repositories";
import { ManagedUserWalletService, RpcMessageService } from "@src/billing/services";
import { ErrorService } from "@src/core/services/error/error.service";
import { ProviderCleanupSummarizer } from "@src/deployment/lib/provider-cleanup-summarizer/provider-cleanup-summarizer";
import { DeploymentRepository } from "@src/deployment/repositories/deployment/deployment.repository";
import { TxSignerService } from "../tx-signer/tx-signer.service";

export interface ProviderCleanupParams {
concurrency: number;
provider: string;
dryRun: boolean;
}

@singleton()
export class ProviderCleanupService {
private readonly logger = LoggerService.forContext(ProviderCleanupService.name);

constructor(
@InjectBillingConfig() private readonly config: BillingConfig,
private readonly userWalletRepository: UserWalletRepository,
private readonly managedUserWalletService: ManagedUserWalletService,
private readonly txSignerService: TxSignerService,
private readonly deploymentRepository: DeploymentRepository,
private readonly rpcMessageService: RpcMessageService,
private readonly errorService: ErrorService
) {}

async cleanup(options: ProviderCleanupParams) {
const summary = new ProviderCleanupSummarizer();
await this.userWalletRepository.paginate({ query: { isTrialing: true }, limit: options.concurrency || 10 }, async wallets => {
const cleanUpAllWallets = wallets.map(async wallet => {
await this.errorService.execWithErrorHandler(
{
wallet,
event: "PROVIDER_CLEAN_UP_ERROR",
context: ProviderCleanupService.name
},
() => this.cleanUpForWallet(wallet, options, summary)
);
});

await Promise.all(cleanUpAllWallets);
});

this.logger.info({ event: "PROVIDER_CLEAN_UP_SUMMARY", summary: summary.summarize(), dryRun: options.dryRun });
}

private async cleanUpForWallet(wallet: UserWalletOutput, options: ProviderCleanupParams, summary: ProviderCleanupSummarizer) {
const client = await this.txSignerService.getClientForAddressIndex(wallet.id);
const deployments = await this.deploymentRepository.findDeploymentsForProvider({
owner: wallet.address,
provider: options.provider
});

const closeAllWalletStaleDeployments = deployments.map(async deployment => {
const message = this.rpcMessageService.getCloseDeploymentMsg(wallet.address, deployment.dseq);
this.logger.info({ event: "PROVIDER_CLEAN_UP", params: { owner: wallet.address, dseq: deployment.dseq } });

try {
if (!options.dryRun) {
await client.signAndBroadcast([message]);
this.logger.info({ event: "PROVIDER_CLEAN_UP_SUCCESS" });
}
} catch (error) {
if (error.message.includes("not allowed to pay fees")) {
if (!options.dryRun) {
await this.managedUserWalletService.authorizeSpending({
address: wallet.address,
limits: {
fees: this.config.FEE_ALLOWANCE_REFILL_AMOUNT
}
});
await client.signAndBroadcast([message]);
this.logger.info({ event: "PROVIDER_CLEAN_UP_SUCCESS" });
}
} else {
throw error;
}
} finally {
summary.inc("deploymentCount");
}
});

await Promise.all(closeAllWalletStaleDeployments);
}
}
15 changes: 14 additions & 1 deletion apps/api/src/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { chainDb } from "@src/db/dbConnection";
import { TopUpDeploymentsController } from "@src/deployment/controllers/deployment/deployment.controller";
import { UserController } from "@src/user/controllers/user/user.controller";
import { UserConfigService } from "@src/user/services/user-config/user-config.service";
import { ProviderController } from "./deployment/controllers/provider/provider.controller";

const program = new Command();

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

program
.command("cleanup-provider-deployments")
.description("Close trial deployments for a provider")
.option("-c, --concurrency <number>", "How many wallets is processed concurrently", value => z.number({ coerce: true }).optional().default(10).parse(value))
.option("-d, --dry-run", "Dry run the trial provider cleanup", false)
.option("-p, --provider <string>", "Provider address", value => z.string().parse(value))
.action(async (options, command) => {
await executeCliHandler(command.name(), async () => {
await container.resolve(ProviderController).cleanupProviderDeployments(options);
});
});

const userConfig = container.resolve(UserConfigService);
program
.command("cleanup-stale-anonymous-users")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { singleton } from "tsyringe";

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

@singleton()
export class ProviderController {
constructor(private readonly trialProvidersService: TrialProvidersService) {}
constructor(
private readonly trialProvidersService: TrialProvidersService,
private readonly providerCleanupService: ProviderCleanupService
) {}

async getTrialProviders(): Promise<string[]> {
return await this.trialProvidersService.getTrialProviders();
}

async cleanupProviderDeployments(options: ProviderCleanupParams) {
return await this.providerCleanupService.cleanup(options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
interface ProviderCleanupSummary {
deploymentCount: number;
}

export class ProviderCleanupSummarizer {
private deploymentCount = 0;

inc(param: keyof ProviderCleanupSummary, value = 1) {
this[param] += value;
}

set(param: keyof ProviderCleanupSummary, value: number) {
this[param] = value;
}

get(param: keyof ProviderCleanupSummary) {
return this[param];
}

summarize(): ProviderCleanupSummary {
return {
deploymentCount: this.deploymentCount
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export interface StaleDeploymentsOptions {
owner: string;
}

export interface ProviderCleanupOptions {
owner: string;
provider: string;
}

export interface StaleDeploymentsOutput {
dseq: number;
}
Expand Down Expand Up @@ -37,4 +42,27 @@ export class DeploymentRepository {

return deployments ? (deployments as unknown as StaleDeploymentsOutput[]) : [];
}

async findDeploymentsForProvider(options: ProviderCleanupOptions): Promise<StaleDeploymentsOutput[]> {
const deployments = await Deployment.findAll({
attributes: ["dseq"],
where: {
owner: options.owner,
closedHeight: null
},
include: [
{
model: Lease,
attributes: [],
required: true,
where: {
providerAddress: options.provider
}
}
],
raw: true
});

return deployments ? (deployments as unknown as StaleDeploymentsOutput[]) : [];
}
}
28 changes: 15 additions & 13 deletions apps/api/src/routes/v1/templates/byId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ const route = createRoute({
content: {
"application/json": {
schema: z.object({
id: z.string(),
name: z.string(),
path: z.string(),
logoUrl: z.string().nullable(),
summary: z.string(),
readme: z.string().nullable(),
deploy: z.string(),
persistentStorageEnabled: z.boolean(),
guide: z.string().nullable(),
githubUrl: z.string(),
config: z.object({
ssh: z.boolean().optional()
data: z.object({
id: z.string(),
name: z.string(),
path: z.string(),
logoUrl: z.string().nullable(),
summary: z.string(),
readme: z.string().nullable(),
deploy: z.string(),
persistentStorageEnabled: z.boolean(),
guide: z.string().nullable(),
githubUrl: z.string(),
config: z.object({
ssh: z.boolean().optional()
})
})
})
}
Expand All @@ -51,5 +53,5 @@ export default new OpenAPIHono().openapi(route, async c => {
return c.text("Template not found", 404);
}

return c.json(template);
return c.json({ data: template });
});
6 changes: 3 additions & 3 deletions apps/api/test/seeders/deployment-grant.seeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export class DeploymentGrantSeeder {
spend_limit: {
denom: DenomSeeder.create(),
amount: faker.number.int({ min: 0, max: 10000000 }).toString()
},
expiration: faker.date.future().toISOString()
}
}
},
expiration: faker.date.future().toISOString()
},
input
);
Expand Down
28 changes: 28 additions & 0 deletions apps/deploy-web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@


## [2.25.1-beta.1](https://github.com/akash-network/console/compare/console-web/v2.25.1-beta.0...console-web/v2.25.1-beta.1) (2024-12-03)


### Bug Fixes

* ensure proper schema type on server props getter ([aedf03d](https://github.com/akash-network/console/commit/aedf03d837fd6b2ebd6e76b32a694e043053a441))

## [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)


### Bug Fixes

* **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)

## [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)

## [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)


### Features

* **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)


### Bug Fixes

* **billing:** ensure checkout pricing is displayed correctly ([3bcb4a8](https://github.com/akash-network/console/commit/3bcb4a881e3bb58e741de8bb8a0a661dede0d8ae))

## [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)


Expand Down
Loading
Loading