* [WEB-7447] feat: migrate CE telemetry from OTLP traces to OTLP metrics Replace span-based tracing (tracer.py) with OTLP observable gauges, mirroring the approach already used in plane-ee. Key changes: - Add otlp_endpoints.py — shared gRPC/HTTP endpoint helpers - Add telemetry_metrics.py — push_instance_metrics task using MeterProvider + observable gauges (service name: plane-ce-api) - User count excludes bots (is_bot=False) - Page count excludes bot-owned private pages only - Domain derived from WEB_URL env var - Celery beat entry replaced with timedelta schedule + configurable METRICS_PUSH_INTERVAL_MINUTES (default 360 min) - Add explicit opentelemetry-exporter-otlp-proto-grpc dep - Delete tracer.py and telemetry.py (no longer needed) Co-authored-by: Plane AI <noreply@plane.so> * fix: address review comments on CE telemetry metrics - harden grpc_endpoint_from_url for scheme-less OTLP_ENDPOINT values (e.g. "telemetry.plane.so:4317") by prepending "//" before urlparse - fix WEB_URL domain extraction for scheme-less values with same approach - replace N+1 workspace count queries (6×N) with 6 batched annotate(Count) aggregation queries — reduces DB load significantly at WORKSPACE_METRICS_LIMIT - add deterministic ordering (order_by created_at) to workspace slice - harden METRICS_PUSH_INTERVAL_MINUTES env parsing with try/except guard and positive-value validation to avoid crash on malformed input Co-authored-by: Plane AI <noreply@plane.so> * fix: cap METRICS_PUSH_INTERVAL_MINUTES to prevent timedelta overflow Add upper-bound check (10_000_000 minutes) and catch OverflowError alongside ValueError so an arbitrarily large env value cannot crash worker startup via timedelta(minutes=...) OverflowError. Co-authored-by: Plane AI <noreply@plane.so> --------- Co-authored-by: Plane AI <noreply@plane.so>
118 lines
4.5 KiB
Python
118 lines
4.5 KiB
Python
# Copyright (c) 2023-present Plane Software, Inc. and contributors
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
# See the LICENSE file for details.
|
|
|
|
# Python imports
|
|
import os
|
|
import logging
|
|
from datetime import timedelta
|
|
|
|
# Third party imports
|
|
from celery import Celery
|
|
from pythonjsonlogger.json import JsonFormatter
|
|
from celery.signals import after_setup_logger, after_setup_task_logger
|
|
from celery.schedules import crontab, schedule
|
|
|
|
# Module imports
|
|
from plane.settings.redis import redis_instance
|
|
|
|
# Set the default Django settings module for the 'celery' program.
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plane.settings.production")
|
|
|
|
ri = redis_instance()
|
|
|
|
# Configurable metrics push interval (in minutes)
|
|
# Default: 360 (6 hours), set to 5 for development/testing
|
|
def _get_metrics_push_interval_minutes() -> int:
|
|
raw = os.environ.get("METRICS_PUSH_INTERVAL_MINUTES", "360")
|
|
try:
|
|
value = int(raw)
|
|
# Cap at 10,000,000 minutes to prevent timedelta(minutes=...) OverflowError
|
|
# on arbitrarily large inputs while still allowing multi-year intervals.
|
|
return value if 0 < value <= 10_000_000 else 360
|
|
except (ValueError, OverflowError):
|
|
return 360
|
|
|
|
METRICS_PUSH_INTERVAL_MINUTES = _get_metrics_push_interval_minutes()
|
|
|
|
app = Celery("plane")
|
|
|
|
# Using a string here means the worker will not have to
|
|
# pickle the object when using Windows.
|
|
app.config_from_object("django.conf:settings", namespace="CELERY")
|
|
|
|
app.conf.beat_schedule = {
|
|
# Intra day recurring jobs
|
|
"check-every-five-minutes-to-send-email-notifications": {
|
|
"task": "plane.bgtasks.email_notification_task.stack_email_notification",
|
|
"schedule": crontab(minute="*/5"), # Every 5 minutes
|
|
},
|
|
"push-instance-metrics": {
|
|
"task": "plane.license.bgtasks.telemetry_metrics.push_instance_metrics",
|
|
"schedule": schedule(run_every=timedelta(minutes=METRICS_PUSH_INTERVAL_MINUTES)),
|
|
},
|
|
# Occurs once every day
|
|
"check-every-day-to-delete-hard-delete": {
|
|
"task": "plane.bgtasks.deletion_task.hard_delete",
|
|
"schedule": crontab(hour=0, minute=0), # UTC 00:00
|
|
},
|
|
"check-every-day-to-archive-and-close": {
|
|
"task": "plane.bgtasks.issue_automation_task.archive_and_close_old_issues",
|
|
"schedule": crontab(hour=1, minute=0), # UTC 01:00
|
|
},
|
|
"check-every-day-to-delete_exporter_history": {
|
|
"task": "plane.bgtasks.exporter_expired_task.delete_old_s3_link",
|
|
"schedule": crontab(hour=1, minute=30), # UTC 01:30
|
|
},
|
|
"check-every-day-to-delete-file-asset": {
|
|
"task": "plane.bgtasks.file_asset_task.delete_unuploaded_file_asset",
|
|
"schedule": crontab(hour=2, minute=0), # UTC 02:00
|
|
},
|
|
"check-every-day-to-delete-api-logs": {
|
|
"task": "plane.bgtasks.cleanup_task.delete_api_logs",
|
|
"schedule": crontab(hour=2, minute=30), # UTC 02:30
|
|
},
|
|
"check-every-day-to-delete-email-notification-logs": {
|
|
"task": "plane.bgtasks.cleanup_task.delete_email_notification_logs",
|
|
"schedule": crontab(hour=2, minute=45), # UTC 02:45
|
|
},
|
|
"check-every-day-to-delete-page-versions": {
|
|
"task": "plane.bgtasks.cleanup_task.delete_page_versions",
|
|
"schedule": crontab(hour=3, minute=0), # UTC 03:00
|
|
},
|
|
"check-every-day-to-delete-issue-description-versions": {
|
|
"task": "plane.bgtasks.cleanup_task.delete_issue_description_versions",
|
|
"schedule": crontab(hour=3, minute=15), # UTC 03:15
|
|
},
|
|
"check-every-day-to-delete-webhook-logs": {
|
|
"task": "plane.bgtasks.cleanup_task.delete_webhook_logs",
|
|
"schedule": crontab(hour=3, minute=30), # UTC 03:30
|
|
},
|
|
"check-every-day-to-delete-exporter-history": {
|
|
"task": "plane.bgtasks.exporter_expired_task.delete_old_s3_link",
|
|
"schedule": crontab(hour=3, minute=45), # UTC 03:45
|
|
},
|
|
}
|
|
|
|
|
|
# Setup logging
|
|
@after_setup_logger.connect
|
|
def setup_loggers(logger, *args, **kwargs):
|
|
formatter = JsonFormatter('"%(levelname)s %(asctime)s %(module)s %(name)s %(message)s')
|
|
handler = logging.StreamHandler()
|
|
handler.setFormatter(fmt=formatter)
|
|
logger.addHandler(handler)
|
|
|
|
|
|
@after_setup_task_logger.connect
|
|
def setup_task_loggers(logger, *args, **kwargs):
|
|
formatter = JsonFormatter('"%(levelname)s %(asctime)s %(module)s %(name)s %(message)s')
|
|
handler = logging.StreamHandler()
|
|
handler.setFormatter(fmt=formatter)
|
|
logger.addHandler(handler)
|
|
|
|
|
|
# Load task modules from all registered Django app configs.
|
|
app.autodiscover_tasks()
|
|
|
|
app.conf.beat_scheduler = "django_celery_beat.schedulers.DatabaseScheduler"
|