Skip to content

Commit

Permalink
Merge branch 'main' into feature/DF-19693
Browse files Browse the repository at this point in the history
  • Loading branch information
karen-stepanyan authored Apr 25, 2024
2 parents e348b32 + 38be814 commit 67d846e
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-toys-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/tradingeconomics-adapter': patch
---

Added support for cache TTL refresh on heartbeat messages for Forex endpoint
5 changes: 5 additions & 0 deletions .changeset/quiet-weeks-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/layer2-sequencer-health-adapter': minor
---

Updates Metis healthcheck endpoint
2 changes: 1 addition & 1 deletion packages/sources/layer2-sequencer-health/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Adapter that checks the Layer 2 Sequencer status
| | `BASE_HEALTH_ENDPOINT` | Base Health Endpoint | | |
| | `BASE_CHAIN_ID` | The chain id to connect to | | 8453 |
| | `METIS_RPC_ENDPOINT` | Metis RPC Endpoint | | https://andromeda.metis.io/?owner=1088 |
| | `METIS_HEALTH_ENDPOINT` | Metis Health Endpoint | | https://tokenapi.metis.io/andromeda/health |
| | `METIS_HEALTH_ENDPOINT` | Metis Health Endpoint | | https://andromeda-healthy.metisdevops.link/health |
| | `METIS_CHAIN_ID` | The chain id to connect to | | 1088 |
| | `SCROLL_RPC_ENDPOINT` | Scroll RPC Endpoint | | https://rpc.scroll.io |
| | `SCROLL_HEALTH_ENDPOINT` | Scroll Health Endpoint | | |
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/layer2-sequencer-health/schemas/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"METIS_HEALTH_ENDPOINT": {
"type": "string",
"default": "https://tokenapi.metis.io/andromeda/health"
"default": "https://andromeda-healthy.metisdevops.link/health"
},
"METIS_CHAIN_ID": {
"required": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const CHAIN_IDS: Record<EVMNetworks, number | undefined | string> = {
util.getEnv(ENV_SCROLL_CHAIN_ID),
}

const DEFAULT_METIS_HEALTH_ENDPOINT = 'https://tokenapi.metis.io/andromeda/health'
const DEFAULT_METIS_HEALTH_ENDPOINT = 'https://andromeda-healthy.metisdevops.link/health'
export const HEALTH_ENDPOINTS: Record<
Networks,
{ endpoint: string | undefined; responsePath: string[] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import nock from 'nock'

export const mockResponseSuccessHealth = (): void => {
// #1 Option: Direct check on health endpoint
nock('https://tokenapi.metis.io/andromeda/health')
nock('https://andromeda-healthy.metisdevops.link/health')
.get('')
.query(() => true)
.reply(200, (_) => ({ healthy: 'true' }), [
Expand Down Expand Up @@ -93,7 +93,7 @@ export const mockResponseSuccessRollup = (): void => {

export const mockResponseFailureHealth = (): void => {
// #1 Option: Direct check on health endpoint
nock('https://tokenapi.metis.io/andromeda/health')
nock('https://andromeda-healthy.metisdevops.link/health')
.get('')
.query(() => true)
.reply(200, (_) => ({ healthy: 'false' }), [
Expand Down
6 changes: 6 additions & 0 deletions packages/sources/tradingeconomics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

This document was generated automatically. Please see [README Generator](../../scripts#readme-generator) for more info.

## Known Issues

### CACHE_MAX_AGE interaction with Heartbeat messages

If `CACHE_MAX_AGE` is set below a current heartbeat interval (45000ms), the extended cache TTL feature for out-of-market-hours that relies on heartbeats will not work.

## Environment Variables

| Required? | Name | Description | Type | Options | Default |
Expand Down
5 changes: 5 additions & 0 deletions packages/sources/tradingeconomics/docs/known-issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Known Issues

### CACHE_MAX_AGE interaction with Heartbeat messages

If `CACHE_MAX_AGE` is set below a current heartbeat interval (45000ms), the extended cache TTL feature for out-of-market-hours that relies on heartbeats will not work.
24 changes: 21 additions & 3 deletions packages/sources/tradingeconomics/src/transport/price-ws.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { WebsocketReverseMappingTransport } from '@chainlink/external-adapter-framework/transports'
import {
WebsocketReverseMappingTransport,
WebSocketTransport,
} from '@chainlink/external-adapter-framework/transports'
import { makeLogger } from '@chainlink/external-adapter-framework/util'
import { BaseEndpointTypes } from '../endpoint/price'

Expand Down Expand Up @@ -27,6 +30,14 @@ type WsTransportTypes = BaseEndpointTypes & {
WsMessage: Message
}
}
/*
Tradingeconomics EA currently does not receive asset prices during off-market hours. When a heartbeat message is received during these hours,
we update the TTL of cache entries that EA is requested to provide a price during off-market hours.
*/
const updateTTL = async (transport: WebSocketTransport<WsTransportTypes>, ttl: number) => {
const params = await transport.subscriptionSet.getAll()
transport.responseCache.writeTTL(transport.name, params, ttl)
}

export const wsTransport: WebsocketReverseMappingTransport<WsTransportTypes, string> =
new WebsocketReverseMappingTransport<WsTransportTypes, string>({
Expand All @@ -35,10 +46,17 @@ export const wsTransport: WebsocketReverseMappingTransport<WsTransportTypes, str
return `${WS_API_ENDPOINT}?client=${API_CLIENT_KEY}:${API_CLIENT_SECRET}`
},
handlers: {
message: (message) => {
if (!message.topic || message.topic === 'keepalive') {
message: (message, context) => {
if (!message.topic) {
return []
}
// Check for a heartbeat message, refresh the TTLs of all requested entries in the cache
if (message.topic === 'keepalive') {
wsTransport.lastMessageReceivedAt = Date.now()
updateTTL(wsTransport, context.adapterSettings.CACHE_MAX_AGE)
return []
}

const pair = wsTransport.getReverseMapping(message.s)
if (!pair) {
logger.error(`Pair not found in websocket reverse map for message symbol - ${message.s}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ exports[`websocket price endpoint should return success 1`] = `
}
`;

exports[`websocket price endpoint should update the ttl after heartbeat is received 1`] = `
{
"data": {
"result": 0.776530152665828,
},
"result": 0.776530152665828,
"statusCode": 200,
"timestamps": {
"providerDataReceivedUnixMs": 1018,
"providerDataStreamEstablishedUnixMs": 1010,
"providerIndicatedTimeUnixMs": 1659472542655,
},
}
`;

exports[`websocket stock endpoint should return success 1`] = `
{
"data": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
setEnvVariables,
mockWebSocketProvider,
MockWebsocketServer,
runAllUntilTime,
} from '@chainlink/external-adapter-framework/util/testing-utils'
import FakeTimers from '@sinonjs/fake-timers'
import { WebSocketClassProvider } from '@chainlink/external-adapter-framework/transports'
Expand Down Expand Up @@ -52,16 +53,25 @@ describe('websocket', () => {
await testAdapter.api.close()
})

describe('price endpoint', () => {
describe('stock endpoint', () => {
it('should return success', async () => {
const response = await testAdapter.request(dataPrice)
const response = await testAdapter.request(dataStock)
expect(response.json()).toMatchSnapshot()
})
})

describe('stock endpoint', () => {
describe('price endpoint', () => {
it('should return success', async () => {
const response = await testAdapter.request(dataStock)
const response = await testAdapter.request(dataPrice)
expect(response.json()).toMatchSnapshot()
})

it('should update the ttl after heartbeat is received', async () => {
// The cache ttl is 90 seconds. Mocked heartbeat message is sent after 10s after connection which should
// update the ttl and therefore after 93 seconds (from the initial message) we can access the asset
await runAllUntilTime(testAdapter.clock, 93000)
const response = await testAdapter.request(dataPrice)
expect(response.statusCode).toBe(200)
expect(response.json()).toMatchSnapshot()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export const mockWebSocketServer = (url: string) => {
topic: 'USDCAD',
}),
)
setTimeout(() => {
socket.send(JSON.stringify({ topic: 'keepalive' }))
}, 10000)
} else {
// stock endpoint
socket.send(
Expand Down

0 comments on commit 67d846e

Please sign in to comment.