Skip to content

Commit

Permalink
add gateway logging labels
Browse files Browse the repository at this point in the history
  • Loading branch information
will pankiewicz authored and will pankiewicz committed Dec 22, 2023
1 parent e560c5e commit 2dd903d
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 62 deletions.
4 changes: 2 additions & 2 deletions packages/gateway/src/controllers/Accounting.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BaseContext } from "koa";
import * as AccountingService from "../services/Accounting";
import { response } from "./index";
import { logger } from "@1kv/common";
import { gatewayLabel } from "../run";

export default class AccountingController {
public static async getAccounting(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getAccounting is cached`);
logger.info(`{Gateway} getAccounting is cached`, gatewayLabel);
return;
}
const address = context.params.address;
Expand Down
17 changes: 9 additions & 8 deletions packages/gateway/src/controllers/Candidate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as CandidateService from "../services/Candidate";
import { response } from "./index";
import { logger } from "@1kv/common";
import { gatewayLabel } from "../run";

export default class CandidateController {
public static async getCandidate(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getCandidate is cached`);
logger.info(`{Gateway} getCandidate is cached`, gatewayLabel);
return;
}
const address = context.params.address;
Expand All @@ -15,39 +16,39 @@ export default class CandidateController {

public static async getValidCandidates(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getValidCandidates is cached`);
logger.info(`{Gateway} getValidCandidates is cached`, gatewayLabel);
return;
}
response(context, 200, await CandidateService.getValidCandidates());
}

public static async getInvalidCandidates(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getInvalidCandidates is cached`);
logger.info(`{Gateway} getInvalidCandidates is cached`, gatewayLabel);
return;
}
response(context, 200, await CandidateService.getInvalidCandidates());
}

public static async getCandidates(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getCandidates is cached`);
logger.info(`{Gateway} getCandidates is cached`, gatewayLabel);
return;
}
response(context, 200, await CandidateService.getCandidates());
}

public static async getNodes(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getNodes is cached`);
logger.info(`{Gateway} getNodes is cached`, gatewayLabel);
return;
}
response(context, 200, await CandidateService.getNodes());
}

public static async getLatestNominatorStake(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getLatestNominatorStake is cached`);
logger.info(`{Gateway} getLatestNominatorStake is cached`, gatewayLabel);
return;
}

Expand All @@ -62,7 +63,7 @@ export default class CandidateController {

public static async getEraNominatorStake(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getEraNominatorStake is cached`);
logger.info(`{Gateway} getEraNominatorStake is cached`, gatewayLabel);
return;
}
const { address, era } = context.params;
Expand All @@ -76,7 +77,7 @@ export default class CandidateController {

public static async getLastNominatorStake(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getLastNominatorStake is cached`);
logger.info(`{Gateway} getLastNominatorStake is cached`, gatewayLabel);
return;
}
const { address, limit } = context.params;
Expand Down
76 changes: 49 additions & 27 deletions packages/gateway/src/controllers/Democracy.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { response } from "./index";
import * as DemocracyService from "../services/Democracy";
import { logger } from "@1kv/common";
import { gatewayLabel } from "../run";

export default class DemocracyController {
public static async getElectionStats(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getElectionStats is cached`);
logger.info(`{Gateway} getElectionStats is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getLatestElectionStats());
}

public static async getCouncillors(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getCouncillors is cached`);
logger.info(`{Gateway} getCouncillors is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getCouncillors());
}

public static async getCouncillor(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getCouncillors is cached`);
logger.info(`{Gateway} getCouncillors is cached`, gatewayLabel);
return;
}
const { address } = context.params;
Expand All @@ -30,23 +31,23 @@ export default class DemocracyController {

public static async getVoters(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getVoters is cached`);
logger.info(`{Gateway} getVoters is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getVoters());
}

public static async getAllReferenda(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getAllReferenda is cached`);
logger.info(`{Gateway} getAllReferenda is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getAllReferenda());
}

public static async getReferendum(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getReferendum is cached`);
logger.info(`{Gateway} getReferendum is cached`, gatewayLabel);
return;
}
const { index } = context.params;
Expand All @@ -55,23 +56,23 @@ export default class DemocracyController {

public static async getLastReferendum(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getLastReferendum is cached`);
logger.info(`{Gateway} getLastReferendum is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getLastReferendum());
}

public static async getLastReferendums(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getLastReferendums is cached`);
logger.info(`{Gateway} getLastReferendums is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getLastReferendums());
}

public static async getReferendumIndexVotes(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getReferendumIndexVotes is cached`);
logger.info(`{Gateway} getReferendumIndexVotes is cached`, gatewayLabel);
return;
}
const { index } = context.params;
Expand All @@ -84,7 +85,10 @@ export default class DemocracyController {

public static async getReferendumAccountVotes(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getReferendumAccountVotes is cached`);
logger.info(
`{Gateway} getReferendumAccountVotes is cached`,
gatewayLabel
);
return;
}
const { address } = context.params;
Expand All @@ -97,7 +101,7 @@ export default class DemocracyController {

public static async getDelegations(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getDelegations is cached`);
logger.info(`{Gateway} getDelegations is cached`, gatewayLabel);
return;
}
const { address } = context.params;
Expand All @@ -106,15 +110,18 @@ export default class DemocracyController {

public static async getAllDelegations(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getAllDelegations is cached`);
logger.info(`{Gateway} getAllDelegations is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getAllDelegations());
}

public static async getAddressConvictionVotes(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getAddressConvictionVotes is cached`);
logger.info(
`{Gateway} getAddressConvictionVotes is cached`,
gatewayLabel
);
return;
}
const { address } = context.params;
Expand All @@ -129,7 +136,10 @@ export default class DemocracyController {
context: any
): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getAddressTrackConvictionVotes is cached`);
logger.info(
`{Gateway} getAddressTrackConvictionVotes is cached`,
gatewayLabel
);
return;
}
const { address, track } = context.params;
Expand All @@ -142,7 +152,7 @@ export default class DemocracyController {

public static async getTrackConvictionVotes(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getTrackConvictionVotes is cached`);
logger.info(`{Gateway} getTrackConvictionVotes is cached`, gatewayLabel);
return;
}
const { track } = context.params;
Expand All @@ -157,7 +167,10 @@ export default class DemocracyController {
context: any
): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getReferendumConvictionVotes is cached`);
logger.info(
`{Gateway} getReferendumConvictionVotes is cached`,
gatewayLabel
);
return;
}
const { index } = context.params;
Expand All @@ -172,7 +185,10 @@ export default class DemocracyController {
context: any
): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getOpenGovAddressDelegations is cached`);
logger.info(
`{Gateway} getOpenGovAddressDelegations is cached`,
gatewayLabel
);
return;
}
const { address } = context.params;
Expand All @@ -185,15 +201,15 @@ export default class DemocracyController {

public static async getOpenGovDelegates(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getOpenGovDelegates is cached`);
logger.info(`{Gateway} getOpenGovDelegates is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getOpenGovDelegates());
}

public static async getOpenGovDelegate(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getOpenGovDelegates is cached`);
logger.info(`{Gateway} getOpenGovDelegates is cached`, gatewayLabel);
return;
}
const { address } = context.params;
Expand All @@ -202,23 +218,23 @@ export default class DemocracyController {

public static async getOpenGovTracks(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getOpenGovTracks is cached`);
logger.info(`{Gateway} getOpenGovTracks is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getOpenGovTracks());
}

public static async getOpenGovVoters(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getOpenGovVoters is cached`);
logger.info(`{Gateway} getOpenGovVoters is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getOpenGovVoters());
}

public static async getOpenGovVoter(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getOpenGovVoter is cached`);
logger.info(`{Gateway} getOpenGovVoter is cached`, gatewayLabel);
return;
}
const { address } = context.params;
Expand All @@ -227,15 +243,15 @@ export default class DemocracyController {

public static async getOpenGovReferenda(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getOpenGovReferendaStats is cached`);
logger.info(`{Gateway} getOpenGovReferendaStats is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getOpenGovReferenda());
}

public static async getOpenGovReferendaIndex(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getOpenGovReferendaStats is cached`);
logger.info(`{Gateway} getOpenGovReferendaStats is cached`, gatewayLabel);
return;
}
const { index } = context.params;
Expand All @@ -248,15 +264,18 @@ export default class DemocracyController {

public static async getOpenGovReferendaStats(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getOpenGovReferendaStats is cached`);
logger.info(`{Gateway} getOpenGovReferendaStats is cached`, gatewayLabel);
return;
}
response(context, 200, await DemocracyService.getOpenGovReferendaStats());
}

public static async getOpenGovReferendumStats(context: any): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getOpenGovReferendumStats is cached`);
logger.info(
`{Gateway} getOpenGovReferendumStats is cached`,
gatewayLabel
);
return;
}
const { index } = context.params;
Expand All @@ -271,7 +290,10 @@ export default class DemocracyController {
context: any
): Promise<void> {
if (await context.cashed()) {
logger.info(`{Gateway} getOpenGovReferendumStats is cached`);
logger.info(
`{Gateway} getOpenGovReferendumStats is cached`,
gatewayLabel
);
return;
}
const { index, segment } = context.params;
Expand Down
5 changes: 3 additions & 2 deletions packages/gateway/src/controllers/EraPoints.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { response } from "./index";
import * as EraPointsService from "../services/EraPoints";
import { logger } from "@1kv/common";
import { gatewayLabel } from "../run";

export default class EraPointsController {
public static async getEraPoints(context: any): Promise<any> {
if (await context.cashed()) {
logger.info(`{Gateway} getEraPoints is cached`);
logger.info(`{Gateway} getEraPoints is cached`, gatewayLabel);
return;
}
const { address, last } = context.params;
Expand All @@ -14,7 +15,7 @@ export default class EraPointsController {

public static async getTotalEraPoints(context: any): Promise<any> {
if (await context.cashed()) {
logger.info(`{Gateway} getTotalEraPoints is cached`);
logger.info(`{Gateway} getTotalEraPoints is cached`, gatewayLabel);
return;
}
response(context, 200, await EraPointsService.getTotalEraPoints());
Expand Down
Loading

0 comments on commit 2dd903d

Please sign in to comment.