Skip to content

Commit

Permalink
HEAT-230 updating package and adding last updated date (#15)
Browse files Browse the repository at this point in the history
* HEAT-230 updating package and adding last updated date

* HEAT-230 Handle when cloud role name differs from component name
  • Loading branch information
andrewrlee authored May 2, 2024
1 parent c9eaa61 commit 48c36aa
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
concurrencyPolicy: Replace
failedJobsHistoryLimit: 5
startingDeadlineSeconds: 43200
successfulJobsHistoryLimit: 5
successfulJobsHistoryLimit: 1
jobTemplate:
spec:
template:
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dep-tree",
"name": "hmpps-component-dependencies",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand Down Expand Up @@ -69,36 +69,36 @@
]
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/jest": "^29.5.12",
"@types/superagent": "^8.1.6",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"audit-ci": "^6.6.1",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint": "^9.1.1",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"jest": "^27.5.1",
"jest": "^29.7.0",
"jest-html-reporter": "^3.10.2",
"jest-junit": "^16.0.0",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"ts-jest": "^27.1.3",
"typescript": "^4.9.5"
"ts-jest": "^29.1.2",
"typescript": "^5.4.5"
},
"dependencies": {
"@types/bunyan": "^1.8.11",
"@types/bunyan-format": "^0.2.9",
"applicationinsights": "^2.9.5",
"applicationinsights": "^3.0.1",
"bunyan": "^1.8.15",
"bunyan-format": "^0.2.1",
"connect-redis": "^7.1.1",
"redis": "^4.6.13",
"superagent": "^8.1.2",
"ts-node": "^10.9.1"
"superagent": "^9.0.2",
"ts-node": "^10.9.2"
}
}
47 changes: 47 additions & 0 deletions src/data/Components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,51 @@ describe('Components', () => {
expect(node.knownDependencies).toStrictEqual({})
}
})

test('map with one way dependency between one known components and one unknown component by cloud role name', () => {
const component1: Component = { name: 'comp-1', cloudRoleName: 'comp1', environments: [{ name: 'dev', url: 'http://component1' }] }

const components = new Components([component1])

const map = components.buildComponentMap([{ componentName: component1.cloudRoleName, type: 'http', dependencyHostname: 'http://some-unknown' }])

{
const node = map[component1.name]

expect(node.component).toStrictEqual(component1)
expect(node.unknownDependencies).toStrictEqual([{ componentName: 'comp1', dependencyHostname: 'http://some-unknown', type: 'http' }])
expect(node.reliedUponBy).toStrictEqual({})
expect(node.dependencyCategories).toStrictEqual(['HTTP'])
expect(node.knownDependencies).toStrictEqual({})
}
})

test('map with one way dependency between one known components when looking up based on cloud role name', () => {
const component1: Component = { name: 'comp-1', cloudRoleName: 'comp1', environments: [{ name: 'dev', url: 'http://component1' }] }
const component2: Component = { name: 'comp-2', cloudRoleName: 'comp2', environments: [{ name: 'dev', url: 'http://component2' }] }

const components = new Components([component1, component2])

const map = components.buildComponentMap([{ componentName: component2.cloudRoleName, type: 'http', dependencyHostname: 'http://component1' }])

{
const node = map[component1.name]

expect(node.component).toStrictEqual(component1)
expect(node.unknownDependencies).toStrictEqual([])
expect(node.reliedUponBy[component2.name].component).toStrictEqual(component2)
expect(node.dependencyCategories).toStrictEqual([])
expect(node.knownDependencies).toStrictEqual({})
}

{
const node = map[component2.name]

expect(node.component).toStrictEqual(component2)
expect(node.unknownDependencies).toStrictEqual([])
expect(node.reliedUponBy).toStrictEqual({})
expect(node.dependencyCategories).toStrictEqual(['HTTP'])
expect(node.knownDependencies[component1.name].component).toStrictEqual(component1)
}
})
})
11 changes: 10 additions & 1 deletion src/data/Components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ export class Components {
return acc
}, {} as ComponentMap)

const cloudRoleNameLookup = this.components.reduce((acc, component) => {
acc[component.cloudRoleName] = component.name
return acc
}, {} as Record<string, string>)

const lookUpComponentName = (name: string) => cloudRoleNameLookup[name] || name

dependencies.forEach(dependency => {
const { componentName, dependencyHostname } = dependency
const { componentName: cloudRoleName, dependencyHostname } = dependency
const componentName = lookUpComponentName(cloudRoleName)

const componentNode = componentMap[componentName] || new ComponentNode(componentName, undefined)
const dependentComponent = this.getComponentForHostname(dependencyHostname)
if (dependentComponent) {
Expand Down
1 change: 0 additions & 1 deletion src/data/appInsights/Client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import superagent from 'superagent'
import { type AppInsightsCreds } from '../../config'


type QueryResult = {
headers: string[]
rows: string[][]
Expand Down
5 changes: 4 additions & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const run = async () => {
const componentDependencies = await Promise.all(config.environments.map(environment => calculateDependencies(environment, components)))

logger.info(`Starting to publish dependency info`)
await redisService.write(Object.fromEntries(componentDependencies))

const data = Object.fromEntries(componentDependencies)
await redisService.write({ lastUpdated: new Date().toISOString(), ...data })

logger.info(`Finished publishing dependency info`)

await redisClient.quit()
Expand Down

0 comments on commit 48c36aa

Please sign in to comment.