mirror of
https://github.com/Xahau/Validation-Ledger-Tx-Store-to-xPOP.git
synced 2025-11-27 23:25:52 +00:00
Add opt-in telemetry & docker compose vars & build
This commit is contained in:
@@ -13,11 +13,16 @@ Based on the work by @RichardAH: https://github.com/RichardAH/xpop-generator
|
||||
To run this service & nginx in two separate preconfigured containers, simply run:
|
||||
|
||||
```bash
|
||||
docker-compose up
|
||||
TELEMETRY=YES URL_PREFIX=https://xpop.my-site.com docker-compose up --build
|
||||
```
|
||||
|
||||
Unless specified otherwise (with environment variables) a connection to XRPL Testnet will be made.
|
||||
|
||||
The above command explained:
|
||||
- `TELEMETRY=YES` sends the `URL_PREFIX` and request hostname to XRPL Labs to build an xPOP serving directory. Default: `NO`, change to `YES` to enable (much appreciated) if you want to run this service publicly for others to fetch xPOPs from (really really appreciate it 💕!)
|
||||
- `URL_PREFIX` specifies a public URL (if applicable) you are serving your xPOPs on (mapped to this service)
|
||||
- `--build` at the end makes sure you rebuild your service container, to make sure you're running the latest version of this code
|
||||
|
||||
##### Cleanup
|
||||
|
||||
The `docker-compose` machines also contain a clean up machine.
|
||||
|
||||
@@ -11,6 +11,32 @@ import 'wtfnode'
|
||||
import { lastLedger } from '../lib/onLedger.mjs'
|
||||
import { txCount } from '../lib/onTransaction.mjs'
|
||||
|
||||
const telemetry = {
|
||||
host: null,
|
||||
proto: null,
|
||||
url: process.env?.URL_PREFIX,
|
||||
collected: false,
|
||||
sent: false,
|
||||
}
|
||||
|
||||
const sendTelemetry = async () => {
|
||||
if (process.env?.TELEMETRY === 'YES') {
|
||||
try {
|
||||
console.log('Sending telemetry...', telemetry)
|
||||
telemetry.sent = new Date()
|
||||
const tcall = await fetch('https://xrpl.ws-stats.com/xpop/telemetry', {
|
||||
body: JSON.stringify(telemetry),
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
})
|
||||
const tbody = await tcall.text()
|
||||
console.log('Telemetry response', tbody)
|
||||
} catch (e) {
|
||||
console.log('Error sending telemetry', e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const startDate = new Date()
|
||||
let lastWsPushedLedger
|
||||
|
||||
@@ -25,7 +51,7 @@ if (!wss) {
|
||||
|
||||
nunjucks.configure(new URL('../', import.meta.url).pathname, { autoescape: true, express: app })
|
||||
|
||||
app.enable('trust proxy')
|
||||
app.enable('trust proxy') // , ['loopback', 'linklocal', 'uniquelocal']) - Needs more for Cloudflare etc.
|
||||
app.disable('x-powered-by')
|
||||
app.use(express.json())
|
||||
app.use(morgan('combined', { }))
|
||||
@@ -39,6 +65,19 @@ if (!wss) {
|
||||
app.use('/',
|
||||
cors(),
|
||||
(req, res, next) => {
|
||||
if (process.env?.TELEMETRY === 'YES' && !req.url.match(/health/)) {
|
||||
const telemetryData = {
|
||||
host: req.headers?.['host'] || 'localhost',
|
||||
proto: (req.headers?.['x-forwarded-proto'] || 'http').split(',')[0],
|
||||
collected: new Date(),
|
||||
}
|
||||
|
||||
if (!telemetry.collected || telemetryData.host !== telemetry.host) {
|
||||
Object.assign(telemetry, telemetryData)
|
||||
sendTelemetry()
|
||||
}
|
||||
}
|
||||
|
||||
if (req.url.split('?')?.[0].match(/\.json$/i)) {
|
||||
res.setHeader('content-type', 'application/json')
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ services:
|
||||
- NOVALIDATIONLOG=${NOVALIDATIONLOG:-}
|
||||
- NOELIGIBLEFULLTXLOG=${NOELIGIBLEFULLTXLOG:-}
|
||||
- DEBUG=${DEBUG:-}
|
||||
- TELEMETRY=${TELEMETRY:-NO}
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: wget --spider -q http://localhost:3000/health || exit 1
|
||||
|
||||
Reference in New Issue
Block a user