8000 Monitoring otel by infinitelos · Pull Request #1975 · ir-engine/ir-engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Monitoring otel #1975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.local.default
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ BQ_PROJECT_ID=
BQ_DATASET_ID=
BQ_TABLE_ID=

# Prometheus Metrics Settings
PROMETHEUS_METRICS_ENABLED=false
METRICS_ENDPOINT=/metrics
METRICS_UPDATE_INTERVAL_SECONDS=300

# Docker controls. Please know what you are disabling
DC_minio=true
DC_test=true
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@
"@google-cloud/compute": "^4.11.0",
"@google-cloud/networkservices": "^0.7.0",
"@google-cloud/storage": "^7.15.0",
"@opentelemetry/auto-instrumentations-node": "^0.58.1",
"@opentelemetry/exporter-trace-otlp-http": "^0.200.0",
"@opentelemetry/resources": "^2.0.0",
"@opentelemetry/sdk-node": "^0.200.0",
"@opentelemetry/semantic-conventions": "^1.33.0",
"@swc/core": "1.7.35",
"app-root-path": "3.1.0",
"cli": "1.0.1",
Expand All @@ -167,6 +172,7 @@
"jsdom-global": "3.0.2",
"minio": "7.1.3",
"patch-package": "^6.5.1",
"prom-client": "^15.1.3",
"ts-node": "10.9.2",
"typescript": "5.6.3"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/ir-engine/ir-engine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.

Software distributed under the License is distributed on an "AS IS" basis,
Expand All @@ -19,6 +19,7 @@ The Original Code is Infinite Reality Engine.
The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Infinite Reality Engine team.


All portions of the code written by the Infinite Reality Engine team are Copyright © 2021-2025
Infinite Reality Engine. All Rights Reserved.
*/
Expand Down
5 changes: 3 additions & 2 deletions packages/common/src/constants/FeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/ir-engine/ir-engine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.

Software distributed under the License is distributed on an "AS IS" basis,
Expand All @@ -19,6 +19,7 @@ The Original Code is Infinite Reality Engine.
The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Infinite Reality Engine team.


All portions of the code written by the Infinite Reality Engine team are Copyright © 2021-2025
Infinite Reality Engine. All Rights Reserved.
*/
Expand Down
28 changes: 26 additions & 2 deletions packages/server-core/src/appconfig.ts
67E6
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/ir-engine/ir-engine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.

Software distributed under the License is distributed on an "AS IS" basis,
Expand Down Expand Up @@ -439,6 +439,29 @@ const redis = {
password: process.env.REDIS_PASSWORD == '' || process.env.REDIS_PASSWORD == null ? null! : process.env.REDIS_PASSWORD!
}

/**
* Monitoring
*/
const monitoring = {
metrics: {
enabled: process.env.PROMETHEUS_METRICS_ENABLED === 'true',
endpoint: process.env.METRICS_ENDPOINT || '/metrics',
// For GCP Cloud Monitoring integration
gcpProject: process.env.GCP_PROJECT,
useCloudMonitoring: process.env.USE_CLOUD_MONITORING === 'true'
},
tracing: {
enabled: process.env.TRACING_ENABLED === 'true',
endpoint: process.env.TRACING_ENDPOINT || 'http://localhost:4318/v1/traces',
samplingRatio: parseFloat(process.env.TRACING_SAMPLING_RATIO || '0.1'), // 10% sampling by default
serviceName: process.env.TRACING_SERVICE_NAME || 'ir-engine-api',
// For GCP Cloud Trace integration
useCloudTrace: process.env.USE_CLOUD_TRACE === 'true'
},
// Environment type to determine which monitoring infrastructure to use
environment: process.env.MONITORING_ENVIRONMENT || 'local' // 'local', 'docker', 'gcp'
}

const scopes = {
guest: process.env.DEFAULT_GUEST_SCOPES?.split(',') || [],
user: process.env.DEFAULT_USER_SCOPES?.split(',') || []
Expand Down Expand Up @@ -482,6 +505,7 @@ const config = {
redis,
scopes,
blockchain,
monitoring,
kubernetes: {
enabled: kubernetesEnabled,
serviceHost: process.env.KUBERNETES_SERVICE_HOST!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/ir-engine/ir-engine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.

Software distributed under the License is distributed on an "AS IS" basis,
Expand All @@ -23,16 +23,19 @@ All portions of the code written by the Infinite Reality Engine team are Copyrig
Infinite Reality Engine. All Rights Reserved.
*/

import { HookContext } from '@feathersjs/feathers'
import { hooks as schemaHooks } from '@feathersjs/schema'
import { disallow, iff, isProvider } from 'feathers-hooks-common'

import {
buildStatusDataValidator,
buildStatusPatchValidator,
buildSta F438 tusQueryValidator
buildStatusQueryValidator,
BuildStatusType
} from '@ir-engine/common/src/schemas/cluster/build-status.schema'

import verifyScope from '../../hooks/verify-scope'
import { BuildStatusService } from './build-status.class'
import {
buildStatusDataResolver,
buildStatusExternalResolver,
Expand Down Expand Up @@ -68,9 +71,44 @@ export default {
all: [],
find: [],
get: [],
create: [],
create: [
(context: HookContext<BuildStatusService>) => {
// Track build start in metrics
const metricsService = context.app.get('metricsService') as any
if (metricsService && typeof metricsService.trackBuildStart === 'function') {
metricsService.trackBuildStart()
}
return context
}
],
update: [],
patch: [],
patch: [
(context: HookContext<BuildStatusService>) => {
// Track build completion in metrics if status is changed from pending
const metricsService = context.app.get('metricsService') as any
if (!metricsService || typeof metricsService.trackBuildCompletion !== 'function') return context

const data = context.data as Partial<BuildStatusType>
const buildStatus = context.result as BuildStatusType

// Only track completion if status is being updated and it's not 'pending'
if (data.status && data.status !== 'pending') {
// Calculate duration if both dateStarted and dateEnded are available
if (buildStatus.dateStarted && buildStatus.dateEnded) {
const startDate = new Date(buildStatus.dateStarted)
const endDate = new Date(buildStatus.dateEnded)
const durationSeconds = (endDate.getTime() - startDate.getTime()) / 1000

metricsService.trackBuildCompletion(data.status, durationSeconds)
} else {
// If we can't calculate duration, still track the status change
metricsService.trackBuildCompletion(data.status, 0)
}
}

return context
}
],
remove: []
},

Expand Down
56 changes: 53 additions & 3 deletions packages/server-core/src/createApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import authenticate from './hooks/authenticate'
import { logError } from './hooks/log-error'
import persistHeaders from './hooks/persist-headers'
import { createDefaultStorageProvider } from './media/storageprovider/storageprovider'
import monitoringServices from './monitoring'
import mysql from './mysql'
import services from './services'
import authentication from './user/authentication'
Expand Down Expand Up @@ -101,6 +102,11 @@ export const configurePrimus =
'ionic://' + appConfig.server.clientHost
]
if (!instanceserver) origin.push('https://localhost:3001')

// Get metrics service if it exists
const metricsService = app.get('metricsService')
const metricsEnabled = process.env.PROMETHEUS_METRICS_ENABLED === 'true'

app.configure(
primus(
{
Expand All @@ -119,6 +125,35 @@ export const configurePrimus =
;(message as any).feathers.forwarded = message.forwarded
next()
})

// Add event handlers for tracking WebSocket connections and messages if metrics service exists
if (metricsService && metricsEnabled) {
primus.on('connection', (spark) => {
metricsService.trackWebSocketConnection('connected')

// Track WebSocket messages
spark.on('data', (data) => {
metricsService.trackWebSocketMessage(
'incoming',
typeof data === 'object' ? data.type || 'unknown' : 'unknown'
)
})

// Track outgoing messages
spark.on('outgoing::data', (data) => {
metricsService.trackWebSocketMessage(
'outgoing',
typeof data === 'object' ? data.type || 'unknown' : 'unknown'
)
})
})

primus.on('disconnection', () => {
metricsService.trackWebSocketConnection('disconnected')
})

logger.info('WebSocket metrics tracking enabled for Primus')
}
}
)
)
Expand Down Expand Up @@ -165,9 +200,24 @@ export const configureK8s = () => (app: Application) => {
return app
}

export const serverPipe = pipe(configureOpenAPI(), configurePrimus(), configureRedis(), configureK8s()) as (
app: Application
) => Application
export const configureMonitoring = () => (app: Application) => {
// Set app name for tracing
const serviceName = appConfig.monitoring?.tracing?.serviceName || 'ir-engine-api'
app.set('name', serviceName)

// Configure monitoring services
monitoringServices.forEach((service) => app.configure(service()))

return app
}

export const serverPipe = pipe(
configureOpenAPI(),
configureMonitoring(),
configurePrimus(),
configureRedis(),
configureK8s()
) as (app: Application) => Application

export const serverJobPipe = pipe(configurePrimus(), configureK8s()) as (app: Application) => Application

Expand Down
29 changes: 29 additions & 0 deletions packages/server-core/src/monitoring/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
CPAL-1.0 License

The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/ir-engine/ir-engine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.

The Original Code is Infinite Reality Engine.

The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Infinite Reality Engine team.

All portions of the code written by the Infinite Reality Engine team are Copyright © 2021-2023
Infinite Reality Engine. All Rights Reserved.
*/

import configureMetrics from './metrics.service'
import configureTracing from './tracing.service'

export default [configureMetrics, configureTracing]
Loading
0