mirror of
https://github.com/tale/headplane.git
synced 2026-08-21 02:06:37 +00:00
feat(TALE-7): add proper integration logging
This commit is contained in:
@@ -4,6 +4,7 @@ import { setTimeout } from 'node:timers/promises'
|
||||
import { Client } from 'undici'
|
||||
|
||||
import { HeadscaleError, pull } from '~/utils/headscale'
|
||||
import log from '~/utils/log'
|
||||
|
||||
import { createIntegration } from './integration'
|
||||
|
||||
@@ -28,19 +29,25 @@ export default createIntegration<Context>({
|
||||
.toLowerCase()
|
||||
|
||||
if (!container || container.length === 0) {
|
||||
log.error('INTG', 'Missing HEADSCALE_CONTAINER variable')
|
||||
return false
|
||||
}
|
||||
|
||||
log.info('INTG', 'Using container: %s', container)
|
||||
const path = process.env.DOCKER_SOCK ?? 'unix:///var/run/docker.sock'
|
||||
let url: URL | undefined
|
||||
|
||||
try {
|
||||
url = new URL(path)
|
||||
} catch {
|
||||
log.error('INTG', 'Invalid Docker socket path: %s', path)
|
||||
return false
|
||||
}
|
||||
|
||||
if (url.protocol !== 'tcp:' && url.protocol !== 'unix:') {
|
||||
log.error('INTG', 'Invalid Docker socket protocol: %s',
|
||||
url.protocol,
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -49,8 +56,10 @@ export default createIntegration<Context>({
|
||||
if (url.protocol === 'tcp:') {
|
||||
url.protocol = 'http:'
|
||||
try {
|
||||
log.info('INTG', 'Checking API: %s', url.href)
|
||||
await fetch(new URL('/v1.30/version', url).href)
|
||||
} catch {
|
||||
log.error('INTG', 'Failed to connect to Docker API')
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -60,8 +69,14 @@ export default createIntegration<Context>({
|
||||
// Check if the socket is accessible
|
||||
if (url.protocol === 'unix:') {
|
||||
try {
|
||||
await access(path, constants.R_OK)
|
||||
log.info('INTG', 'Checking socket: %s',
|
||||
url.pathname,
|
||||
)
|
||||
await access(url.pathname, constants.R_OK)
|
||||
} catch {
|
||||
log.error('INTG', 'Failed to access Docker socket: %s',
|
||||
path,
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -70,7 +85,7 @@ export default createIntegration<Context>({
|
||||
})
|
||||
}
|
||||
|
||||
return client === undefined
|
||||
return client !== undefined
|
||||
},
|
||||
|
||||
onAclChange: async ({ client, container, maxAttempts }) => {
|
||||
@@ -78,6 +93,8 @@ export default createIntegration<Context>({
|
||||
return
|
||||
}
|
||||
|
||||
log.info('INTG', 'Sending SIGHUP to Headscale via Docker')
|
||||
|
||||
let attempts = 0
|
||||
while (attempts <= maxAttempts) {
|
||||
const response = await client.request({
|
||||
@@ -104,6 +121,8 @@ export default createIntegration<Context>({
|
||||
return
|
||||
}
|
||||
|
||||
log.info('INTG', 'Restarting Headscale via Docker')
|
||||
|
||||
let attempts = 0
|
||||
while (attempts <= maxAttempts) {
|
||||
const response = await client.request({
|
||||
|
||||
Reference in New Issue
Block a user