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: add region to relay headers #965

Open
wants to merge 2 commits into
base: develop
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: 3 additions & 0 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class PocketGatewayApplication extends BootMixin(ServiceMixin(RepositoryM
REDIS_LOCAL_TTL_FACTOR,
RATE_LIMITER_URL,
RATE_LIMITER_TOKEN,
REGION,
}: // eslint-disable-next-line @typescript-eslint/no-explicit-any
any = await this.get('configuration.environment.values')

Expand All @@ -89,6 +90,7 @@ export class PocketGatewayApplication extends BootMixin(ServiceMixin(RepositoryM
const ttlFactor = parseFloat(REDIS_LOCAL_TTL_FACTOR) || 1
const rateLimiterURL: string = RATE_LIMITER_URL || ''
const rateLimiterToken: string = RATE_LIMITER_TOKEN || ''
const region: string = REGION || ''

if (aatPlan !== AatPlans.PREMIUM && !AatPlans.values.includes(aatPlan)) {
throw new HttpErrors.InternalServerError('Unrecognized AAT Plan')
Expand All @@ -112,6 +114,7 @@ export class PocketGatewayApplication extends BootMixin(ServiceMixin(RepositoryM
this.bind('alwaysRedirectToAltruists').to(alwaysRedirectToAltruists)
this.bind('rateLimiterURL').to(rateLimiterURL)
this.bind('rateLimiterToken').to(rateLimiterToken)
this.bind('region').to(region)

const redisPort: string = REDIS_PORT || ''

Expand Down
14 changes: 11 additions & 3 deletions src/controllers/v1.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class V1Controller {
@inject('secretKey') private secretKey: string,
@inject('host') private host: string,
@inject('origin') private origin: string,
@inject('region') private region: string,
@inject('userAgent') private userAgent: string,
@inject('contentType') private contentType: string,
@inject('ipAddress') private ipAddress: string,
Expand Down Expand Up @@ -88,12 +89,19 @@ export class V1Controller {
cherryPicker: this.cherryPicker,
processUID: this.processUID,
})
this.syncChecker = new SyncChecker(this.cache, this.metricsRecorder, this.defaultSyncAllowance, this.origin)
this.chainChecker = new ChainChecker(this.cache, this.metricsRecorder, this.origin)
this.mergeChecker = new MergeChecker(this.cache, this.metricsRecorder, this.origin)
this.syncChecker = new SyncChecker(
this.cache,
this.metricsRecorder,
this.defaultSyncAllowance,
this.origin,
this.region
)
this.chainChecker = new ChainChecker(this.cache, this.metricsRecorder, this.origin, this.region)
this.mergeChecker = new MergeChecker(this.cache, this.metricsRecorder, this.origin, this.region)
this.pocketRelayer = new PocketRelayer({
host: this.host,
origin: this.origin,
headers: { 'Content-Type': 'application/json', region: this.region },
userAgent: this.userAgent,
ipAddress: this.ipAddress,
relayer: this.relayer,
Expand Down
5 changes: 4 additions & 1 deletion src/services/chain-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export class ChainChecker {
metricsRecorder: MetricsRecorder
origin: string
sessionErrors: number
region: string

constructor(cache: Cache, metricsRecorder: MetricsRecorder, origin: string) {
constructor(cache: Cache, metricsRecorder: MetricsRecorder, origin: string, region: string) {
this.cache = cache
this.metricsRecorder = metricsRecorder
this.origin = origin
this.region = region
}

async chainIDFilter({
Expand Down Expand Up @@ -270,6 +272,7 @@ export class ChainChecker {
blockchain: blockchainID,
data: chainCheck,
method: '',
headers: { 'Content-Type': 'application/json', region: this.region },
path,
node,
pocketAAT,
Expand Down
5 changes: 4 additions & 1 deletion src/services/merge-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ export class MergeChecker {
metricsRecorder: MetricsRecorder
origin: string
sessionErrors: number
region: string

constructor(cache: Cache, metricsRecorder: MetricsRecorder, origin: string) {
constructor(cache: Cache, metricsRecorder: MetricsRecorder, origin: string, region: string) {
this.cache = cache
this.metricsRecorder = metricsRecorder
this.origin = origin
this.region = region
}

async mergeStatusFilter({
Expand Down Expand Up @@ -288,6 +290,7 @@ export class MergeChecker {
blockchain: blockchainID,
data: MERGE_CHECK_PAYLOAD,
method: '',
headers: { 'Content-Type': 'application/json', region: this.region },
path,
node,
pocketAAT,
Expand Down
7 changes: 6 additions & 1 deletion src/services/pocket-relayer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EvidenceSealedError, Relayer } from '@pokt-foundation/pocketjs-relayer'
import { Session, Node, PocketAAT, HTTPMethod } from '@pokt-foundation/pocketjs-types'
import { Session, Node, PocketAAT, HTTPMethod, RelayHeaders } from '@pokt-foundation/pocketjs-types'
import axios, { AxiosRequestConfig, Method } from 'axios'
import jsonrpc, { ErrorObject, IParsedObject } from 'jsonrpc-lite'
import AatPlans from '../config/aat-plans.json'
Expand Down Expand Up @@ -34,6 +34,7 @@ const logger = require('../services/logger')
export class PocketRelayer {
host: string
origin: string
headers?: RelayHeaders
userAgent: string
ipAddress: string
relayer: Relayer
Expand All @@ -57,6 +58,7 @@ export class PocketRelayer {
constructor({
host,
origin,
headers = {},
userAgent,
ipAddress,
relayer,
Expand All @@ -78,6 +80,7 @@ export class PocketRelayer {
}: {
host: string
origin: string
headers?: RelayHeaders
userAgent: string
ipAddress: string
relayer: Relayer
Expand All @@ -99,6 +102,7 @@ export class PocketRelayer {
}) {
this.host = host
this.origin = origin
this.headers = headers
this.userAgent = userAgent
this.ipAddress = ipAddress
this.relayer = relayer
Expand Down Expand Up @@ -881,6 +885,7 @@ export class PocketRelayer {
blockchain: blockchainID,
data,
method: '',
headers: this.headers,
node,
path: relayPath,
pocketAAT,
Expand Down
13 changes: 11 additions & 2 deletions src/services/sync-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@ export class SyncChecker {
defaultSyncAllowance: number
origin: string
sessionErrors: number

constructor(cache: Cache, metricsRecorder: MetricsRecorder, defaultSyncAllowance: number, origin: string) {
region: string

constructor(
cache: Cache,
metricsRecorder: MetricsRecorder,
defaultSyncAllowance: number,
origin: string,
region: string
) {
this.cache = cache
this.metricsRecorder = metricsRecorder
this.defaultSyncAllowance = defaultSyncAllowance
this.origin = origin
this.region = region
this.sessionErrors = 0
}

Expand Down Expand Up @@ -451,6 +459,7 @@ export class SyncChecker {
path: syncCheckOptions.path,
node,
method: '',
headers: { 'Content-Type': 'application/json', region: this.region },
pocketAAT,
session,
options: {
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/chain-checker.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ describe('Chain checker service (unit)', () => {
let axiosMock: MockAdapter

const origin = 'unit-test'
const region = 'us-east-1'

before('initialize variables', async () => {
cache = new Cache(new Redis(0, ''), new Redis(1, ''))
cherryPicker = new CherryPicker({ redis: cache.remote, checkDebug: false })
metricsRecorder = metricsRecorderMock(cache.remote, cherryPicker)
chainChecker = new ChainChecker(cache, metricsRecorder, origin)
chainChecker = new ChainChecker(cache, metricsRecorder, origin, region)

axiosMock = new MockAdapter(axios)
axiosMock.onPost('https://user:[email protected]:18081/v1/query/node').reply(200, {
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/merge-checker.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ describe('Merge checker service (unit)', () => {
let axiosMock: MockAdapter

const origin = 'unit-test'
const region = 'us-east-1'

before('initialize variables', async () => {
cache = new Cache(new Redis(0, ''), new Redis(1, ''))
cherryPicker = new CherryPicker({ redis: cache.remote, checkDebug: false })
metricsRecorder = metricsRecorderMock(cache.remote, cherryPicker)
mergeChecker = new MergeChecker(cache, metricsRecorder, origin)
mergeChecker = new MergeChecker(cache, metricsRecorder, origin, region)

axiosMock = new MockAdapter(axios)
axiosMock.onPost('https://user:[email protected]:18081/v1/query/node').reply(200, {
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/pocket-relayer.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,15 @@ describe('Pocket relayer service (unit)', () => {
let logSpy: sinon.SinonSpy

const origin = 'unit-test'
const region = 'us-east-1'

before('initialize variables', async () => {
cache = new Cache(new Redis(0, ''), new Redis(1, ''))
cherryPicker = new CherryPicker({ redis: cache.remote, checkDebug: false })
metricsRecorder = metricsRecorderMock(cache.remote, cherryPicker)
chainChecker = new ChainChecker(cache, metricsRecorder, origin)
syncChecker = new SyncChecker(cache, metricsRecorder, 5, origin)
mergeChecker = new MergeChecker(cache, metricsRecorder, origin)
chainChecker = new ChainChecker(cache, metricsRecorder, origin, region)
syncChecker = new SyncChecker(cache, metricsRecorder, 5, origin, region)
mergeChecker = new MergeChecker(cache, metricsRecorder, origin, region)
blockchainRepository = new BlockchainsRepository(gatewayTestDB)

pocketMock = new PocketMock()
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/sync-checker.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ describe('Sync checker service (unit)', () => {
let logSpy: sinon.SinonSpy

const origin = 'unit-test'
const region = 'us-east-1'

before('initialize variables', async () => {
cache = new Cache(new Redis(0, ''), new Redis(1, ''))
cherryPicker = new CherryPicker({ redis: cache.remote, checkDebug: false })
metricsRecorder = metricsRecorderMock(cache.remote, cherryPicker)
syncChecker = new SyncChecker(cache, metricsRecorder, DEFAULT_SYNC_ALLOWANCE, origin)
syncChecker = new SyncChecker(cache, metricsRecorder, DEFAULT_SYNC_ALLOWANCE, origin, region)
pocketMock = new PocketMock()
axiosMock = new MockAdapter(axios)
})
Expand Down