UBERF-8553: Stats as separate service (#7054)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2024-10-29 12:57:28 +07:00
committed by GitHub
parent 3a37a16fc8
commit 7c69f6f35a
59 changed files with 1204 additions and 683 deletions
+15 -26
View File
@@ -4,41 +4,31 @@
import { Analytics } from '@hcengineering/analytics'
import { SplitLogger, configureAnalytics } from '@hcengineering/analytics-service'
import { MeasureMetricsContext, metricsToString, newMetrics } from '@hcengineering/core'
import { loadBrandingMap } from '@hcengineering/server-core'
import { writeFile } from 'fs/promises'
import { MeasureMetricsContext, newMetrics } from '@hcengineering/core'
import { initStatisticsContext, loadBrandingMap } from '@hcengineering/server-core'
import { join } from 'path'
import config from './config'
import { start } from './server'
// Load and inc startID, to have easy logs.
const metricsContext = new MeasureMetricsContext(
'github',
{},
{},
newMetrics(),
new SplitLogger('github-service', {
root: join(process.cwd(), 'logs'),
enableConsole: (process.env.ENABLE_CONSOLE ?? 'true') === 'true'
})
)
const metricsContext = initStatisticsContext('github', {
factory: () =>
new MeasureMetricsContext(
'github',
{},
{},
newMetrics(),
new SplitLogger('github-service', {
root: join(process.cwd(), 'logs'),
enableConsole: (process.env.ENABLE_CONSOLE ?? 'true') === 'true'
})
)
})
configureAnalytics(config.SentryDSN, config)
Analytics.setTag('application', 'github-service')
let oldMetricsValue = ''
const intTimer = setInterval(() => {
const val = metricsToString(metricsContext.metrics, 'Github', 140)
if (val !== oldMetricsValue) {
oldMetricsValue = val
void writeFile('metrics.txt', val).catch((err) => {
console.error(err)
})
}
}, 30000)
let doOnClose: () => Promise<void> = async () => {}
void start(metricsContext, loadBrandingMap(config.BrandingPath)).then((r) => {
@@ -46,7 +36,6 @@ void start(metricsContext, loadBrandingMap(config.BrandingPath)).then((r) => {
})
const onClose = (): void => {
clearInterval(intTimer)
metricsContext.info('Closed')
void doOnClose().then((r) => {
process.exit(0)