Skip to content

Commit

Permalink
Merge pull request #60 from smartcontractkit/BCF-2672-cleanup-job-orm…
Browse files Browse the repository at this point in the history
…-env-var-loading

BCF-2672 Update job gql to reflect core node changes
  • Loading branch information
ilija42 authored Oct 31, 2023
2 parents e10948a + 4c5ad83 commit 2f868c3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
import { prism } from 'react-syntax-highlighter/dist/esm/styles/prism'
import ExpandMoreIcon from '@material-ui/icons/ExpandMore'
import Typography from '@material-ui/core/Typography'
import List from "@material-ui/core/List";
import ListItem from "@material-ui/core/ListItem";
import ListItemIcon from "@material-ui/core/ListItemIcon";
import RemoveCircleOutline from "@material-ui/icons/RemoveCircleOutline";
import List from '@material-ui/core/List'
import ListItem from '@material-ui/core/ListItem'
import ListItemIcon from '@material-ui/core/ListItemIcon'
import RemoveCircleOutline from '@material-ui/icons/RemoveCircleOutline'

const DeprecationWarning = () => {
const newTelemConfig =
Expand All @@ -37,22 +37,27 @@ const DeprecationWarning = () => {
</Typography>
<List dense>
<ListItem>
<ListItemIcon><RemoveCircleOutline /></ListItemIcon>
<ListItemIcon>
<RemoveCircleOutline />
</ListItemIcon>
<Typography variant="subtitle2" gutterBottom>
<code>TelemetryIngress.URL</code> and{' '}
<code>TelemetryIngress.ServerPubKey</code> will no longer be allowed.
Please switch to <code>TelemetryIngress.Endpoints</code>:
<code>TelemetryIngress.ServerPubKey</code> will no longer be
allowed. Please switch to <code>TelemetryIngress.Endpoints</code>:
<SyntaxHighlighter language="toml" style={prism}>
{newTelemConfig}
</SyntaxHighlighter>
</Typography>
</ListItem>
<ListItem>
<ListItemIcon><RemoveCircleOutline /></ListItemIcon>
<ListItemIcon>
<RemoveCircleOutline />
</ListItemIcon>
<Typography variant="subtitle2" gutterBottom>
<code>P2P.V1</code> will no longer be supported and must not be set in TOML
configuration in order to boot. Use <code>P2P.V2</code> instead. If you are
using both, <code>V1</code> can simply be removed.
<code>P2P.V1</code> will no longer be supported and must not be
set in TOML configuration in order to boot. Use{' '}
<code>P2P.V2</code> instead. If you are using both,{' '}
<code>V1</code> can simply be removed.
</Typography>
</ListItem>
</List>
Expand Down
7 changes: 0 additions & 7 deletions src/screens/Job/JobView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const JOB_PAYLOAD__SPEC = gql`
contractAddress
evmChainID
minIncomingConfirmations
minIncomingConfirmationsEnv
minContractPaymentLinkJuels
requesters
}
Expand All @@ -47,19 +46,14 @@ const JOB_PAYLOAD__SPEC = gql`
}
... on OCRSpec {
blockchainTimeout
blockchainTimeoutEnv
contractAddress
contractConfigConfirmations
contractConfigConfirmationsEnv
contractConfigTrackerPollInterval
contractConfigTrackerPollIntervalEnv
contractConfigTrackerSubscribeInterval
contractConfigTrackerSubscribeIntervalEnv
evmChainID
isBootstrapPeer
keyBundleID
observationTimeout
observationTimeoutEnv
p2pBootstrapPeers
p2pv2Bootstrappers
transmitterAddress
Expand All @@ -85,7 +79,6 @@ const JOB_PAYLOAD__SPEC = gql`
coordinatorAddress
fromAddresses
minIncomingConfirmations
minIncomingConfirmationsEnv
pollPeriod
publicKey
requestedConfsDelay
Expand Down
16 changes: 1 addition & 15 deletions src/screens/Job/TabDefinition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface Props {
}

export const TabDefinition = ({ job }: Props) => {
const { definition, envDefinition } = generateJobDefinition(job)
const { definition } = generateJobDefinition(job)

return (
<Card>
Expand All @@ -33,20 +33,6 @@ export const TabDefinition = ({ job }: Props) => {
{definition}
</SyntaxHighlighter>
</Typography>

{envDefinition.trim() && (
<>
<Typography variant="h5" color="secondary">
Job attributes set by environment variables
</Typography>

<Typography style={{ margin: 0 }} variant="body1" component="pre">
<SyntaxHighlighter language="toml" style={prism}>
{envDefinition}
</SyntaxHighlighter>
</Typography>
</>
)}
</CardContent>
</Card>
)
Expand Down
38 changes: 6 additions & 32 deletions src/screens/Job/generateJobDefinition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ observationSource = """

const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual('')
})

it('generates a valid Direct Request definition', () => {
Expand All @@ -63,7 +62,6 @@ observationSource = """
contractAddress: '0x0000000000000000000000000000000000000000',
evmChainID: '42',
minIncomingConfirmations: 3,
minIncomingConfirmationsEnv: false,
minContractPaymentLinkJuels: '100000000000000',
requesters: ['0x59bbE8CFC79c76857fE0eC27e67E4957370d72B5'],
},
Expand Down Expand Up @@ -92,7 +90,6 @@ observationSource = """

const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual('')
})

it('generates a valid Keeper definition', () => {
Expand Down Expand Up @@ -135,7 +132,6 @@ observationSource = """

const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual('')
})

it('generates a valid Flux Monitor definition', () => {
Expand Down Expand Up @@ -195,7 +191,6 @@ observationSource = """

const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual('')
})

it('generates a valid OCR definition', () => {
Expand All @@ -210,20 +205,15 @@ observationSource = """
spec: {
__typename: 'OCRSpec',
blockchainTimeout: '20s',
blockchainTimeoutEnv: true,
contractAddress: '0x1469877c88F19E273EFC7Ef3C9D944574583B8a0',
contractConfigConfirmations: 3,
contractConfigConfirmationsEnv: false,
contractConfigTrackerPollInterval: '1m0s',
contractConfigTrackerPollIntervalEnv: false,
contractConfigTrackerSubscribeInterval: '2m0s',
contractConfigTrackerSubscribeIntervalEnv: false,
evmChainID: '42',
keyBundleID:
'4ee612467c3caea7bdab57ab62937adfc4d195516c30139a737f85098b35d9af',
isBootstrapPeer: false,
observationTimeout: '10s',
observationTimeoutEnv: false,
p2pBootstrapPeers: [
'/ip4/139.59.41.32/tcp/12000/p2p/12D3KooWGKhStcrvCr5RBYKaSRNX4ojrxHcmpJuFmHWenT6aAQAY',
],
Expand All @@ -248,6 +238,7 @@ name = "ocr job"
externalJobID = "00000000-0000-0000-0000-0000000000001"
gasLimit = 1_000
maxTaskDuration = "10s"
blockchainTimeout = "20s"
contractAddress = "0x1469877c88F19E273EFC7Ef3C9D944574583B8a0"
contractConfigConfirmations = 3
contractConfigTrackerPollInterval = "1m0s"
Expand All @@ -273,7 +264,6 @@ observationSource = """

const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual('blockchainTimeout = "20s"\n')
})

it('generates a valid OCR Bootstrap definition', () => {
Expand All @@ -288,20 +278,15 @@ observationSource = """
spec: {
__typename: 'OCRSpec',
blockchainTimeout: '20s',
blockchainTimeoutEnv: true,
contractAddress: '0x1469877c88F19E273EFC7Ef3C9D944574583B8a0',
contractConfigConfirmations: 3,
contractConfigConfirmationsEnv: true,
contractConfigTrackerPollInterval: '1m0s',
contractConfigTrackerPollIntervalEnv: true,
contractConfigTrackerSubscribeInterval: '2m0s',
contractConfigTrackerSubscribeIntervalEnv: true,
evmChainID: '42',
isBootstrapPeer: true,
keyBundleID:
'4ee612467c3caea7bdab57ab62937adfc4d195516c30139a737f85098b35d9af',
observationTimeout: '10s',
observationTimeoutEnv: true,
p2pBootstrapPeers: [
'/ip4/139.59.41.32/tcp/12000/p2p/12D3KooWGKhStcrvCr5RBYKaSRNX4ojrxHcmpJuFmHWenT6aAQAY',
],
Expand All @@ -326,10 +311,15 @@ name = "ocr job"
externalJobID = "00000000-0000-0000-0000-0000000000001"
gasLimit = 1_000
maxTaskDuration = "10s"
blockchainTimeout = "20s"
contractAddress = "0x1469877c88F19E273EFC7Ef3C9D944574583B8a0"
contractConfigConfirmations = 3
contractConfigTrackerPollInterval = "1m0s"
contractConfigTrackerSubscribeInterval = "2m0s"
evmChainID = "42"
isBootstrapPeer = true
keyBundleID = "4ee612467c3caea7bdab57ab62937adfc4d195516c30139a737f85098b35d9af"
observationTimeout = "10s"
p2pBootstrapPeers = [
"/ip4/139.59.41.32/tcp/12000/p2p/12D3KooWGKhStcrvCr5RBYKaSRNX4ojrxHcmpJuFmHWenT6aAQAY"
]
Expand All @@ -343,17 +333,8 @@ observationSource = """
fetch -> parse -> multiply;
"""
`

const expectedEnvDefinition = `blockchainTimeout = "20s"
contractConfigConfirmations = 3
contractConfigTrackerPollInterval = "1m0s"
contractConfigTrackerSubscribeInterval = "2m0s"
observationTimeout = "10s"
`

const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual(expectedEnvDefinition)
})

it('generates a valid OCR 2 definition', () => {
Expand Down Expand Up @@ -433,7 +414,6 @@ juelsPerFeeCoinSource = "1000000000"

const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual('')
})

it('generates a valid VRF definition', () => {
Expand All @@ -451,7 +431,6 @@ juelsPerFeeCoinSource = "1000000000"
evmChainID: '42',
fromAddresses: ['0x3cCad4715152693fE3BC4460591e3D3Fbd071b42'],
minIncomingConfirmations: 6,
minIncomingConfirmationsEnv: false,
pollPeriod: '10s',
publicKey:
'0x92594ee04c179eb7d439ff1baacd98b81a7d7a6ed55c86ca428fa025bd9c914301',
Expand Down Expand Up @@ -501,7 +480,6 @@ observationSource = """
`
const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual('')
})

it('generates a valid Webhook definition', () => {
Expand Down Expand Up @@ -535,7 +513,6 @@ observationSource = """
`
const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual('')
})

it('generates a valid Bootstrap definition', () => {
Expand Down Expand Up @@ -581,7 +558,6 @@ chainID = 1_337
`
const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual('')
})

it('generates a valid blockhashstore definition', () => {
Expand Down Expand Up @@ -633,7 +609,6 @@ fromAddresses = [ "0x52926EF10c19E810a52f11e942E502B15c7E2fEE" ]
`
const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual('')
})

it('generates a valid Gateway definition', () => {
Expand Down Expand Up @@ -665,6 +640,5 @@ Port = 8_080
`
const output = generateJobDefinition(job)
expect(output.definition).toEqual(expectedOutput)
expect(output.envDefinition).toEqual('')
})
})
47 changes: 3 additions & 44 deletions src/screens/Job/generateJobDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import pick from 'lodash/pick'

export interface JobDefinition {
definition: string
envDefinition: string
}

// Extracts fields from the job that are common to all specs.
Expand All @@ -29,51 +28,12 @@ const extractObservationSourceField = ({
}
}

// Extracts the fields matching the keys from the spec. If another field of of
// the same name with an 'Env' suffix exists, we remove it from the returned
// object.
// Extracts the fields matching the keys from the spec.
const extractSpecFields = <T extends object, K extends keyof T>(
spec: T,
...keys: K[]
) => {
// For every key, check for the existence of an another field of the same name
// with an 'Env' suffix
const scopedKeys = keys.filter((key) => {
const envKey = `${key as string}Env` as K
if (Object.prototype.hasOwnProperty.call(spec, envKey)) {
// We are relying on this always being a boolean but we can't guarantee it
return !spec[envKey]
}

return true
})

return pick(spec, ...scopedKeys)
}

// Extracts the fields which have a field of the same name with an 'Env' suffix
// and the 'Env' field returns true.
const extractEnvValues = <T extends object, K extends keyof T>(spec: T) => {
// For every key with an 'Env' suffix, find a key of the same name without the
// suffix.
const regex = /(.+)Env$/
const envValueKeys: K[] = []
for (const key of Object.keys(spec)) {
const match = key.match(regex)

if (match) {
const envKey = key as K
// We are relying on this always being a boolean but we can't guarantee it
if (spec[envKey]) {
// Check that the key without the 'Env' suffix exists
if (Object.prototype.hasOwnProperty.call(spec, match[1])) {
envValueKeys.push(match[1] as K)
}
}
}
}

return pick(spec, ...envValueKeys)
return pick(spec, ...keys)
}

// Stringifies the job spec as TOML
Expand Down Expand Up @@ -294,7 +254,7 @@ export const generateJobDefinition = (

break
default:
return { definition: '', envDefinition: '' }
return { definition: '' }
case 'WebhookSpec':
values = {
...extractJobFields(job),
Expand All @@ -306,6 +266,5 @@ export const generateJobDefinition = (

return {
definition: toTOMLString(values),
envDefinition: toTOMLString(extractEnvValues(job.spec)),
}
}
1 change: 0 additions & 1 deletion support/factories/gql/fetchJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function buildJob(
contractAddress: '0x0000000000000000000000000000000000000000',
evmChainID: '42',
minIncomingConfirmations: 3,
minIncomingConfirmationsEnv: false,
minContractPaymentLinkJuels: '100000000000000',
requesters: ['0x59bbE8CFC79c76857fE0eC27e67E4957370d72B5'],
},
Expand Down

0 comments on commit 2f868c3

Please sign in to comment.