-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/dydxprotocol/v4-chain into …
…wl/send_hb
- Loading branch information
Showing
223 changed files
with
15,797 additions
and
3,146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,33 @@ jobs: | |
DOCKER_BUILDKIT=1 docker build \ | ||
--platform amd64 \ | ||
-f Dockerfile.bazooka.remote . | ||
check-build-auxo: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./indexer | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
|
||
- name: Install pnpm | ||
run: | ||
npm install -g [email protected] | ||
|
||
- name: Build and install | ||
run: | | ||
pnpm install --loglevel warn --frozen-lockfile | ||
pnpm run build:prod:all | ||
- name: Build docker image for auxo | ||
id: build-image | ||
run: | | ||
DOCKER_BUILDKIT=1 docker build \ | ||
--platform amd64 \ | ||
-f Dockerfile.auxo.remote . |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @dydxprotocol/backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { setInstanceId, getInstanceId, resetForTests } from '../src/instance-id'; | ||
import { axiosRequest } from '../src/axios'; | ||
import { asMock } from '@dydxprotocol-indexer/dev'; | ||
import logger from '../src/logger'; | ||
import config from '../src/config'; | ||
|
||
jest.mock('../src/axios', () => ({ | ||
...(jest.requireActual('../src/axios') as object), | ||
axiosRequest: jest.fn(), | ||
})); | ||
|
||
describe('instance-id', () => { | ||
describe('setInstanceId', () => { | ||
const defaultTaskArn = 'defaultTaskArn'; | ||
const defaultResponse = { | ||
TaskARN: defaultTaskArn, | ||
}; | ||
const ecsUrl = config.ECS_CONTAINER_METADATA_URI_V4; | ||
|
||
beforeEach(() => { | ||
config.ECS_CONTAINER_METADATA_URI_V4 = ecsUrl; | ||
resetForTests(); | ||
jest.resetAllMocks(); | ||
jest.restoreAllMocks(); | ||
asMock(axiosRequest).mockResolvedValue(defaultResponse); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.clearAllMocks(); | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it('should set instance id to task ARN in staging', async () => { | ||
jest.spyOn(config, 'isStaging').mockReturnValueOnce(true); | ||
config.ECS_CONTAINER_METADATA_URI_V4 = 'url'; | ||
await setInstanceId(); | ||
|
||
expect(getInstanceId()).toEqual(defaultTaskArn); | ||
}); | ||
|
||
it('should set instance id to task ARN in production', async () => { | ||
jest.spyOn(config, 'isProduction').mockReturnValueOnce(true); | ||
config.ECS_CONTAINER_METADATA_URI_V4 = 'url'; | ||
await setInstanceId(); | ||
|
||
expect(getInstanceId()).toEqual(defaultTaskArn); | ||
}); | ||
|
||
it('should not call metadata endpoint if not production or staging', async () => { | ||
config.ECS_CONTAINER_METADATA_URI_V4 = 'url'; | ||
await setInstanceId(); | ||
|
||
expect(getInstanceId()).not.toEqual(defaultTaskArn); | ||
expect(asMock(axiosRequest)).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not set instance id if already set', async () => { | ||
jest.spyOn(config, 'isStaging').mockReturnValue(true); | ||
config.ECS_CONTAINER_METADATA_URI_V4 = 'url'; | ||
await setInstanceId(); | ||
const instanceId = getInstanceId(); | ||
await setInstanceId(); | ||
|
||
expect(getInstanceId()).toEqual(instanceId); | ||
expect(axiosRequest).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should log error and set instance id to uuid if request errors', async () => { | ||
jest.spyOn(config, 'isStaging').mockReturnValue(true); | ||
config.ECS_CONTAINER_METADATA_URI_V4 = 'url'; | ||
const loggerErrorSpy = jest.spyOn(logger, 'error'); | ||
const emptyInstanceId = getInstanceId(); | ||
asMock(axiosRequest).mockRejectedValueOnce(new Error()); | ||
await setInstanceId(); | ||
|
||
expect(loggerErrorSpy).toHaveBeenCalledTimes(1); | ||
expect(getInstanceId()).not.toEqual(emptyInstanceId); | ||
}); | ||
|
||
it('should not call metadata endpoint if url is empty', async () => { | ||
jest.spyOn(config, 'isStaging').mockReturnValue(true); | ||
await setInstanceId(); | ||
|
||
expect(axiosRequest).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
import { axiosRequest } from './axios'; | ||
import config from './config'; | ||
import logger from './logger'; | ||
|
||
let INSTANCE_ID: string = ''; | ||
|
||
export function getInstanceId(): string { | ||
return INSTANCE_ID; | ||
} | ||
|
||
export async function setInstanceId(): Promise<void> { | ||
if (INSTANCE_ID !== '') { | ||
return; | ||
} | ||
if (config.ECS_CONTAINER_METADATA_URI_V4 !== '' && | ||
( | ||
config.isProduction() || config.isStaging() | ||
) | ||
) { | ||
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4.html | ||
const taskUrl = `${config.ECS_CONTAINER_METADATA_URI_V4}/task`; | ||
try { | ||
const response = await axiosRequest({ | ||
method: 'GET', | ||
url: taskUrl, | ||
}) as { TaskARN: string }; | ||
INSTANCE_ID = response.TaskARN; | ||
} catch (error) { | ||
logger.error({ | ||
at: 'instance-id#setInstanceId', | ||
message: 'Failed to retrieve task arn from metadata endpoint. Falling back to uuid.', | ||
error, | ||
taskUrl, | ||
}); | ||
INSTANCE_ID = uuidv4(); | ||
} | ||
} else { | ||
INSTANCE_ID = uuidv4(); | ||
|
||
} | ||
} | ||
|
||
// Exported for tests | ||
export function resetForTests(): void { | ||
if (!config.isTest()) { | ||
throw new Error(`resetForTests() cannot be called for env: ${config.NODE_ENV}`); | ||
} | ||
INSTANCE_ID = ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"outDir": "build" | ||
}, | ||
"include": [ | ||
"src" | ||
"src", | ||
"__tests__" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.