Skip to content

Commit

Permalink
feat(observability): utilise new logger in stats-web
Browse files Browse the repository at this point in the history
ref #436
  • Loading branch information
forbesus committed Nov 29, 2024
1 parent 8ad72fa commit 094beaa
Show file tree
Hide file tree
Showing 64 changed files with 1,314 additions and 292 deletions.
41 changes: 41 additions & 0 deletions apps/api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@


## [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/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-beta.0",
"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[]) : [];
}
}
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
21 changes: 21 additions & 0 deletions apps/deploy-web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@


## [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
1 change: 1 addition & 0 deletions apps/deploy-web/mvm.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"dependencies": {
"@akashnetwork/env-loader": "1.0.1",
"@akashnetwork/http-sdk": "1.0.8",
"@akashnetwork/logging": "2.0.2",
"@akashnetwork/network-store": "1.0.1",
"@akashnetwork/ui": "1.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/deploy-web/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
2 changes: 1 addition & 1 deletion apps/deploy-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@akashnetwork/console-web",
"version": "2.25.0-beta.0",
"version": "2.25.1-beta.0",
"private": true,
"description": "Web UI to deploy on the Akash Network and view statistic about network usage.",
"license": "Apache-2.0",
Expand Down
15 changes: 13 additions & 2 deletions apps/deploy-web/src/components/authorizations/Authorizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Bank } from "iconoir-react";
import { NextSeo } from "next-seo";

import { Fieldset } from "@src/components/shared/Fieldset";
import { browserEnvConfig } from "@src/config/browser-env.config";
import { useWallet } from "@src/context/WalletProvider";
import { useAllowance } from "@src/hooks/useAllowance";
import { useAllowancesIssued, useGranteeGrants, useGranterGrants } from "@src/queries/useGrantsQuery";
Expand All @@ -26,6 +27,14 @@ type RefreshingType = "granterGrants" | "granteeGrants" | "allowancesIssued" | "
const defaultRefetchInterval = 30 * 1000;
const refreshingInterval = 1000;

const MASTER_WALLETS = new Set([
browserEnvConfig.NEXT_PUBLIC_USDC_TOP_UP_MASTER_WALLET_ADDRESS,
browserEnvConfig.NEXT_PUBLIC_UAKT_TOP_UP_MASTER_WALLET_ADDRESS
]);

const selectNonMaster = (records: Pick<GrantType, "grantee">[] | Pick<AllowanceType, "grantee">[]) =>
records.filter(({ grantee }) => !MASTER_WALLETS.has(grantee));

export const Authorizations: React.FunctionComponent = () => {
const { address, signAndBroadcastTx, isManaged } = useWallet();
const {
Expand All @@ -41,13 +50,15 @@ export const Authorizations: React.FunctionComponent = () => {
const [selectedGrants, setSelectedGrants] = useState<GrantType[]>([]);
const [selectedAllowances, setSelectedAllowances] = useState<AllowanceType[]>([]);
const { data: granterGrants, isLoading: isLoadingGranterGrants } = useGranterGrants(address, {
refetchInterval: isRefreshing === "granterGrants" ? refreshingInterval : defaultRefetchInterval
refetchInterval: isRefreshing === "granterGrants" ? refreshingInterval : defaultRefetchInterval,
select: selectNonMaster
});
const { data: granteeGrants, isLoading: isLoadingGranteeGrants } = useGranteeGrants(address, {
refetchInterval: isRefreshing === "granteeGrants" ? refreshingInterval : defaultRefetchInterval
});
const { data: allowancesIssued, isLoading: isLoadingAllowancesIssued } = useAllowancesIssued(address, {
refetchInterval: isRefreshing === "allowancesIssued" ? refreshingInterval : defaultRefetchInterval
refetchInterval: isRefreshing === "allowancesIssued" ? refreshingInterval : defaultRefetchInterval,
select: selectNonMaster
});

useEffect(() => {
Expand Down
Loading

0 comments on commit 094beaa

Please sign in to comment.