Code files
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
.git
|
||||
.gitignore
|
||||
node_modules
|
||||
npm-debug.log
|
||||
@@ -0,0 +1,7 @@
|
||||
FROM node:slim
|
||||
RUN mkdir -p /home/node/service
|
||||
WORKDIR /home/node/service
|
||||
COPY package.json /home/node/service
|
||||
RUN npm install
|
||||
COPY . /home/node/service
|
||||
CMD [ "node", "index.js" ]
|
||||
@@ -0,0 +1,17 @@
|
||||
'use strict'
|
||||
|
||||
// provides environment variable setup for concordant
|
||||
|
||||
const env = {
|
||||
DNS_NAMESPACE: 'micro',
|
||||
DNS_SUFFIX: 'svc.cluster.local'
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Object.assign(env, {
|
||||
DNS_HOST: '127.0.0.1',
|
||||
DNS_PORT: '53053'
|
||||
})
|
||||
}
|
||||
|
||||
Object.assign(process.env, env)
|
||||
@@ -0,0 +1,43 @@
|
||||
'use strict'
|
||||
require('./env')
|
||||
const { dns } = require('concordant')()
|
||||
const redis = require('redis')
|
||||
const CliTable = require('cli-table')
|
||||
const QNAME = 'eventservice'
|
||||
const RESPONSE_QUEUE = 'summary'
|
||||
const ENDPOINT = '_main._tcp.redis.micro.svc.cluster.local'
|
||||
|
||||
dns.resolve(ENDPOINT, report)
|
||||
|
||||
function report (err, locs) {
|
||||
if (err) { return console.log(err) }
|
||||
const { port, host } = locs[0]
|
||||
const client = redis.createClient(port, host)
|
||||
const event = JSON.stringify({
|
||||
action: 'summary',
|
||||
returnPath: RESPONSE_QUEUE
|
||||
})
|
||||
|
||||
client.lpush(QNAME, event, (err) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
client.brpop(RESPONSE_QUEUE, 5, (err, data) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
const summary = JSON.parse(data[1])
|
||||
const cols = Object.keys(summary).map((url) => [url, summary[url]])
|
||||
const table = new CliTable({
|
||||
head: ['url', 'count'],
|
||||
colWidths: [50, 10]
|
||||
})
|
||||
table.push(...cols)
|
||||
console.log(table.toString())
|
||||
client.quit()
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "report",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"no test specified\" && exit 0"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Peter Elger <peter.elger@nearform.com>",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"cli-table": "^0.3.1",
|
||||
"concordant": "^0.2.1",
|
||||
"redis": "^2.6.5"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user