aidev-bkplugin 2.2.2rc50__tar.gz → 2.2.2rc51__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/PKG-INFO +2 -2
  2. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/apps.py +26 -0
  3. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/otel_metrics.py +23 -27
  4. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/pyproject.toml +2 -2
  5. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/test_otel_metrics.py +38 -19
  6. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/test_apps.py +35 -0
  7. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/test_management_metrics.py +1 -1
  8. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/__init__.py +0 -0
  9. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/constants.py +0 -0
  10. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/enums.py +0 -0
  11. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/management/__init__.py +0 -0
  12. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/management/commands/__init__.py +0 -0
  13. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/management/commands/upgrade_sessions.py +0 -0
  14. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/migrations/0001_initial.py +0 -0
  15. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/migrations/0002_event_delivery.py +0 -0
  16. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/migrations/__init__.py +0 -0
  17. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/models.py +0 -0
  18. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/openapi/__init__.py +0 -0
  19. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/openapi/urls.py +0 -0
  20. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/openapi/views.py +0 -0
  21. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/packages/__init__.py +0 -0
  22. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/packages/apigw/__init__.py +0 -0
  23. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/packages/apigw/permissions.py +0 -0
  24. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/packages/checkpoint/__init__.py +0 -0
  25. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/packages/checkpoint/bk_django_saver.py +0 -0
  26. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/packages/drf/__init__.py +0 -0
  27. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/packages/drf/authentication.py +0 -0
  28. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/packages/drf/decorators.py +0 -0
  29. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/packages/drf/exception.py +0 -0
  30. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/packages/drf/renderers.py +0 -0
  31. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/permissions.py +0 -0
  32. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/private/__init__.py +0 -0
  33. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/private/permissions.py +0 -0
  34. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/private/urls.py +0 -0
  35. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/private/views.py +0 -0
  36. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/serializers/__init__.py +0 -0
  37. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/serializers/agent.py +0 -0
  38. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/serializers/chat_completion.py +0 -0
  39. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/serializers/llm.py +0 -0
  40. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/serializers/user_operation.py +0 -0
  41. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/__init__.py +0 -0
  42. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/agent_bkplugin.py +0 -0
  43. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/agent_builder.py +0 -0
  44. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/agent_config.py +0 -0
  45. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/agent_execution.py +0 -0
  46. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/agent_helpers.py +0 -0
  47. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/agent_session.py +0 -0
  48. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/approval_resume.py +0 -0
  49. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/chat_tracing.py +0 -0
  50. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/database_event_bus.py +0 -0
  51. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/event_resource_manager.py +0 -0
  52. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/event_tracing.py +0 -0
  53. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/execution.py +0 -0
  54. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/llm.py +0 -0
  55. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/metric_runtime.py +0 -0
  56. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/services/user_operation.py +0 -0
  57. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/settings.py +0 -0
  58. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/tasks.py +0 -0
  59. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/urls.py +0 -0
  60. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/utils.py +0 -0
  61. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/views/__init__.py +0 -0
  62. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/views/agent.py +0 -0
  63. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/views/base.py +0 -0
  64. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/views/chat.py +0 -0
  65. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/views/chat_group.py +0 -0
  66. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/views/flow_agent.py +0 -0
  67. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/views/llm.py +0 -0
  68. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/views/session.py +0 -0
  69. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/aidev_bkplugin/views/user_operation.py +0 -0
  70. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/readme.md +0 -0
  71. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/__init__.py +0 -0
  72. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/apps.py +0 -0
  73. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/conftest.py +0 -0
  74. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/database_events/__init__.py +0 -0
  75. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/database_events/conftest.py +0 -0
  76. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/database_events/test_bus.py +0 -0
  77. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/database_events/test_resource_manager.py +0 -0
  78. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/database_events/test_tracing.py +0 -0
  79. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/packages/__init__.py +0 -0
  80. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/packages/drf/test_renderers_trace.py +0 -0
  81. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/packages/test_bk_django_saver.py +0 -0
  82. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/packages/test_bk_django_saver_async.py +0 -0
  83. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/private/__init__.py +0 -0
  84. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/private/test_private_views.py +0 -0
  85. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/__init__.py +0 -0
  86. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/agent/__init__.py +0 -0
  87. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/agent/conftest.py +0 -0
  88. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/agent/test_agent_config_fetcher.py +0 -0
  89. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/agent/test_builder.py +0 -0
  90. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/agent/test_session_manager.py +0 -0
  91. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/test_agent_completion.py +0 -0
  92. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/test_agui_handler.py +0 -0
  93. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/test_approval_resume.py +0 -0
  94. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/test_approval_resume_tracing.py +0 -0
  95. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/test_bkplugin.py +0 -0
  96. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/test_execution.py +0 -0
  97. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/test_llm.py +0 -0
  98. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/test_resume_consumer.py +0 -0
  99. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/test_thread_chat_completion.py +0 -0
  100. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/services/test_user_operation.py +0 -0
  101. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/settings.py +0 -0
  102. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/test_constants.py +0 -0
  103. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/views/__init__.py +0 -0
  104. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/views/test_agent_view.py +0 -0
  105. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/views/test_chat_agent_code_propagation.py +0 -0
  106. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/views/test_chat_completion_serializer.py +0 -0
  107. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/views/test_chat_flow_agent.py +0 -0
  108. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/views/test_chat_stream_status.py +0 -0
  109. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/views/test_session_pv_files_views.py +0 -0
  110. {aidev_bkplugin-2.2.2rc50 → aidev_bkplugin-2.2.2rc51}/tests/views/test_session_view.py +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aidev-bkplugin
3
- Version: 2.2.2rc50
3
+ Version: 2.2.2rc51
4
4
  Summary: AiDev Agent Bkplugin builtin functions
5
5
  Requires-Python: <3.12,>=3.11
6
- Requires-Dist: aidev-agent>=2.2.2rc50
6
+ Requires-Dist: aidev-agent>=2.2.2rc51
7
7
  Requires-Dist: blueapps<5.0,>=4.15.1
8
8
  Requires-Dist: django<5.0,>=4.2.28
9
9
  Provides-Extra: opentelemetry
@@ -62,6 +62,25 @@ except ImportError:
62
62
  logger = logging.getLogger(__name__)
63
63
 
64
64
 
65
+ def _deduplicate_otel_endpoints(endpoints: list[dict]) -> list[dict]:
66
+ """Keep the highest-priority config for each effective OTLP destination."""
67
+ deduplicated = []
68
+ seen = set()
69
+ for endpoint in endpoints:
70
+ exporter_type = endpoint.get("exporter_type")
71
+ exporter_type = getattr(exporter_type, "value", exporter_type)
72
+ identity = (
73
+ str(endpoint.get("url", "")).rstrip("/"),
74
+ str(exporter_type),
75
+ str(endpoint.get("token", "")),
76
+ )
77
+ if identity in seen:
78
+ continue
79
+ seen.add(identity)
80
+ deduplicated.append(endpoint)
81
+ return deduplicated
82
+
83
+
65
84
  def _is_one_off_management_command() -> bool:
66
85
  if not sys.argv or Path(sys.argv[0]).name not in {"manage.py", "django-admin", "django-admin.py"}:
67
86
  return False
@@ -129,6 +148,13 @@ def init_bk_aidev_agent_otel() -> None:
129
148
  endpoints.extend(get_otel_endpoint_by_agent_info(agent_info=agent_info))
130
149
  # 3. 从 OTEL_GRPC_URL 和 OTEL_BK_DATA_TOKEN 获取单地址
131
150
  endpoints.extend(get_otel_endpoint_by_env())
151
+ deduplicated_endpoints = _deduplicate_otel_endpoints(endpoints)
152
+ if len(deduplicated_endpoints) != len(endpoints):
153
+ logger.info(
154
+ "[aidev_bkplugin] removed %d duplicate OpenTelemetry endpoint(s)",
155
+ len(endpoints) - len(deduplicated_endpoints),
156
+ )
157
+ endpoints = deduplicated_endpoints
132
158
 
133
159
  otel_config.otel_endpoints = endpoints
134
160
  if configure_metric_identity is None or BkPluginMetricService is None or MetricExportSettings is None:
@@ -46,6 +46,7 @@ from .metric_runtime import RetryableMetricPushError
46
46
  logger = logging.getLogger(__name__)
47
47
 
48
48
  DEFAULT_METRIC_EXPORT_INTERVAL_MILLIS = 10_000
49
+ DEFAULT_METRIC_TASK_TTL_SECONDS = 3600
49
50
  BKM_PUSH_MODE_CELERY = "celery"
50
51
  BKM_PUSH_MODE_DIRECT = "direct"
51
52
  BKM_PUSH_MODES = frozenset({BKM_PUSH_MODE_CELERY, BKM_PUSH_MODE_DIRECT})
@@ -85,50 +86,45 @@ class MetricExportSettings:
85
86
  bkm_access_token: str = ""
86
87
  bkm_push_url: str = ""
87
88
  bkm_target: str = ""
88
- task_ttl_seconds: int = agent_settings.BKAI_AGENT_METRICS_TASK_TTL_SECONDS
89
+ task_ttl_seconds: int = DEFAULT_METRIC_TASK_TTL_SECONDS
89
90
 
90
91
  @classmethod
91
92
  def from_agent_info(cls, agent_info: dict[str, Any] | None, *, default_enabled: bool) -> "MetricExportSettings":
92
93
  otel_info = (agent_info or {}).get("otel_info") or {}
93
94
  metrics_info = otel_info.get("metrics") or {}
94
- interval = metrics_info.get(
95
- "export_interval_millis",
96
- otel_info.get(
97
- "metric_export_interval_millis",
98
- agent_settings.BKAI_AGENT_METRICS_EXPORT_INTERVAL_MILLIS,
99
- ),
100
- )
95
+ interval = agent_settings.BKAI_AGENT_METRICS_EXPORT_INTERVAL_MILLIS
96
+ if interval is None:
97
+ interval = metrics_info.get(
98
+ "export_interval_millis",
99
+ otel_info.get("metric_export_interval_millis", DEFAULT_METRIC_EXPORT_INTERVAL_MILLIS),
100
+ )
101
101
  timeout = metrics_info.get(
102
102
  "export_timeout_millis",
103
103
  otel_info.get("metric_export_timeout_millis", 30000),
104
104
  )
105
- task_ttl_seconds = metrics_info.get(
106
- "task_ttl_seconds",
107
- agent_settings.BKAI_AGENT_METRICS_TASK_TTL_SECONDS,
108
- )
105
+ task_ttl_seconds = agent_settings.BKAI_AGENT_METRICS_TASK_TTL_SECONDS
106
+ if task_ttl_seconds is None:
107
+ task_ttl_seconds = metrics_info.get("task_ttl_seconds", DEFAULT_METRIC_TASK_TTL_SECONDS)
109
108
  export_via_celery = metrics_info.get(
110
109
  "export_via_celery",
111
110
  otel_info.get("metric_export_via_celery"),
112
111
  )
113
- bkm_push_mode = (
114
- str(
115
- metrics_info.get(
116
- "push_mode",
117
- otel_info.get("metric_push_mode", agent_settings.BKAI_AGENT_METRICS_PUSH_MODE),
118
- )
112
+ bkm_push_mode = agent_settings.BKAI_AGENT_METRICS_PUSH_MODE
113
+ if bkm_push_mode is None:
114
+ bkm_push_mode = metrics_info.get(
115
+ "push_mode",
116
+ otel_info.get("metric_push_mode", BKM_PUSH_MODE_CELERY),
119
117
  )
120
- .strip()
121
- .lower()
122
- )
118
+ bkm_push_mode = str(bkm_push_mode).strip().lower()
123
119
  if bkm_push_mode not in BKM_PUSH_MODES:
124
120
  raise ValueError(
125
121
  f"Unsupported metric push mode: {bkm_push_mode!r}; expected one of {sorted(BKM_PUSH_MODES)}"
126
122
  )
127
- data_id = metrics_info.get("agent_data_id", agent_settings.BKAI_AGENT_METRICS_DATA_ID)
128
- access_token = metrics_info.get("agent_access_token", agent_settings.BKAI_AGENT_METRICS_TOKEN)
129
- push_url = metrics_info.get("agent_push_url", agent_settings.BKAI_AGENT_METRICS_HOST)
123
+ data_id = agent_settings.BKAI_AGENT_METRICS_DATA_ID or metrics_info.get("agent_data_id")
124
+ access_token = agent_settings.BKAI_AGENT_METRICS_TOKEN or metrics_info.get("agent_access_token", "")
125
+ push_url = agent_settings.BKAI_AGENT_METRICS_HOST or metrics_info.get("agent_push_url", "")
130
126
  push_url = _normalize_bkm_push_url(push_url)
131
- target = metrics_info.get("agent_target", agent_settings.BKAI_AGENT_METRICS_TARGET)
127
+ target = agent_settings.BKAI_AGENT_METRICS_TARGET or metrics_info.get("agent_target", "")
132
128
  has_bkm_config = data_id not in (None, "") and bool(access_token and push_url)
133
129
  if export_via_celery is None:
134
130
  export_via_celery = has_bkm_config
@@ -140,7 +136,7 @@ class MetricExportSettings:
140
136
  )
141
137
  return cls(
142
138
  enabled=_as_bool(enabled),
143
- export_interval_millis=max(1000, int(interval)),
139
+ export_interval_millis=max(10_000, int(interval)),
144
140
  export_timeout_millis=max(1000, int(timeout)),
145
141
  task_ttl_seconds=max(1, int(task_ttl_seconds)),
146
142
  export_via_celery=_as_bool(export_via_celery),
@@ -328,7 +324,7 @@ class CeleryMetricExporter(BkmMetricExporter):
328
324
  endpoint_key: str,
329
325
  target: str,
330
326
  enqueue: Callable[[str, str, int, int], Any],
331
- task_ttl_seconds: int = agent_settings.BKAI_AGENT_METRICS_TASK_TTL_SECONDS,
327
+ task_ttl_seconds: int = DEFAULT_METRIC_TASK_TTL_SECONDS,
332
328
  ) -> None:
333
329
  super().__init__(endpoint_key, target)
334
330
  self.task_ttl_seconds = task_ttl_seconds
@@ -1,11 +1,11 @@
1
1
  [project]
2
2
  name = "aidev-bkplugin"
3
- version = "2.2.2rc50"
3
+ version = "2.2.2rc51"
4
4
  description = "AiDev Agent Bkplugin builtin functions"
5
5
  readme = "readme.md"
6
6
  requires-python = "<3.12,>=3.11"
7
7
  dependencies = [
8
- "aidev-agent>=2.2.2rc50",
8
+ "aidev-agent>=2.2.2rc51",
9
9
  "blueapps>=4.15.1, <5.0",
10
10
  "django>=4.2.28,<5.0",
11
11
  ]
@@ -50,13 +50,13 @@ def isolate_agent_metric_settings(monkeypatch):
50
50
 
51
51
  defaults = {
52
52
  "BKAI_AGENT_ENABLE_METRICS": None,
53
- "BKAI_AGENT_METRICS_EXPORT_INTERVAL_MILLIS": 10_000,
54
- "BKAI_AGENT_METRICS_PUSH_MODE": BKM_PUSH_MODE_CELERY,
53
+ "BKAI_AGENT_METRICS_EXPORT_INTERVAL_MILLIS": None,
54
+ "BKAI_AGENT_METRICS_PUSH_MODE": None,
55
55
  "BKAI_AGENT_METRICS_DATA_ID": "",
56
56
  "BKAI_AGENT_METRICS_TOKEN": "",
57
57
  "BKAI_AGENT_METRICS_HOST": "",
58
58
  "BKAI_AGENT_METRICS_TARGET": "",
59
- "BKAI_AGENT_METRICS_TASK_TTL_SECONDS": 3600,
59
+ "BKAI_AGENT_METRICS_TASK_TTL_SECONDS": None,
60
60
  }
61
61
  for name, value in defaults.items():
62
62
  monkeypatch.setattr(otel_metrics.agent_settings, name, value)
@@ -158,7 +158,7 @@ def test_metric_settings_parse_nested_otel_info():
158
158
  )
159
159
 
160
160
  assert settings.enabled is True
161
- assert settings.export_interval_millis == 1500
161
+ assert settings.export_interval_millis == 10_000
162
162
  assert settings.export_timeout_millis == 7000
163
163
  assert settings.task_ttl_seconds == 120
164
164
  assert settings.export_via_celery is True
@@ -168,18 +168,18 @@ def test_metric_settings_parse_nested_otel_info():
168
168
  assert settings.bkm_target == "127.0.0.1"
169
169
 
170
170
 
171
- def test_metric_settings_prefer_platform_interval_over_agent_setting(monkeypatch):
171
+ def test_metric_settings_prefer_agent_interval_over_platform_setting(monkeypatch):
172
172
  from aidev_bkplugin.services import otel_metrics
173
173
 
174
- monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_EXPORT_INTERVAL_MILLIS", 2500)
175
- agent_info = {"otel_info": {"metrics": {"export_interval_millis": 1500}}}
174
+ monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_EXPORT_INTERVAL_MILLIS", 25_000)
175
+ agent_info = {"otel_info": {"metrics": {"export_interval_millis": 15_000}}}
176
176
 
177
177
  settings = MetricExportSettings.from_agent_info(agent_info, default_enabled=False)
178
178
 
179
- assert settings.export_interval_millis == 1500
179
+ assert settings.export_interval_millis == 25_000
180
180
 
181
181
 
182
- def test_metric_settings_prefer_platform_push_mode_over_agent_setting(monkeypatch):
182
+ def test_metric_settings_prefer_agent_push_mode_over_platform_setting(monkeypatch):
183
183
  from aidev_bkplugin.services import otel_metrics
184
184
 
185
185
  monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_PUSH_MODE", BKM_PUSH_MODE_DIRECT)
@@ -187,7 +187,18 @@ def test_metric_settings_prefer_platform_push_mode_over_agent_setting(monkeypatc
187
187
 
188
188
  settings = MetricExportSettings.from_agent_info(agent_info, default_enabled=False)
189
189
 
190
- assert settings.bkm_push_mode == BKM_PUSH_MODE_CELERY
190
+ assert settings.bkm_push_mode == BKM_PUSH_MODE_DIRECT
191
+
192
+
193
+ def test_metric_settings_prefer_agent_task_ttl_over_platform_setting(monkeypatch):
194
+ from aidev_bkplugin.services import otel_metrics
195
+
196
+ monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_TASK_TTL_SECONDS", 1800)
197
+ agent_info = {"otel_info": {"metrics": {"task_ttl_seconds": 120}}}
198
+
199
+ settings = MetricExportSettings.from_agent_info(agent_info, default_enabled=False)
200
+
201
+ assert settings.task_ttl_seconds == 1800
191
202
 
192
203
 
193
204
  def test_metric_settings_reject_unknown_push_mode():
@@ -204,7 +215,7 @@ def test_metric_settings_use_local_environment_fallback(monkeypatch):
204
215
  monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_TOKEN", "local-secret")
205
216
  monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_HOST", "local-proxy")
206
217
  monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_TARGET", "local-target")
207
- monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_EXPORT_INTERVAL_MILLIS", 2500)
218
+ monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_EXPORT_INTERVAL_MILLIS", 25_000)
208
219
  monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_PUSH_MODE", BKM_PUSH_MODE_DIRECT)
209
220
  monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_TASK_TTL_SECONDS", 1800)
210
221
 
@@ -216,7 +227,7 @@ def test_metric_settings_use_local_environment_fallback(monkeypatch):
216
227
  assert settings.bkm_push_url == "http://local-proxy:10205/v2/push/"
217
228
  assert settings.bkm_target == "local-target"
218
229
  assert settings.export_via_celery is True
219
- assert settings.export_interval_millis == 2500
230
+ assert settings.export_interval_millis == 25_000
220
231
  assert settings.bkm_push_mode == BKM_PUSH_MODE_DIRECT
221
232
  assert settings.task_ttl_seconds == 1800
222
233
 
@@ -225,6 +236,9 @@ def test_metric_settings_keep_direct_otlp_transport_without_bkm_config():
225
236
  settings = MetricExportSettings.from_agent_info({}, default_enabled=True)
226
237
 
227
238
  assert settings.enabled is True
239
+ assert settings.export_interval_millis == 10_000
240
+ assert settings.bkm_push_mode == BKM_PUSH_MODE_CELERY
241
+ assert settings.task_ttl_seconds == 3600
228
242
  assert settings.export_via_celery is False
229
243
 
230
244
 
@@ -251,10 +265,13 @@ def test_normalize_bkm_push_url(configured, expected):
251
265
  assert _normalize_bkm_push_url(configured) == expected
252
266
 
253
267
 
254
- def test_metric_settings_prefer_agent_info_over_local_environment(monkeypatch):
255
- monkeypatch.setenv("BKAI_AGENT_METRICS_DATA_ID", "1002")
256
- monkeypatch.setenv("BKAI_AGENT_METRICS_TOKEN", "local-secret")
257
- monkeypatch.setenv("BKAI_AGENT_METRICS_HOST", "local-proxy")
268
+ def test_metric_settings_prefer_local_bkm_setting_over_agent_info(monkeypatch):
269
+ from aidev_bkplugin.services import otel_metrics
270
+
271
+ monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_DATA_ID", "1002")
272
+ monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_TOKEN", "local-secret")
273
+ monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_HOST", "local-proxy")
274
+ monkeypatch.setattr(otel_metrics.agent_settings, "BKAI_AGENT_METRICS_TARGET", "local-target")
258
275
 
259
276
  settings = MetricExportSettings.from_agent_info(
260
277
  {
@@ -263,15 +280,17 @@ def test_metric_settings_prefer_agent_info_over_local_environment(monkeypatch):
263
280
  "agent_data_id": 1003,
264
281
  "agent_access_token": "platform-secret",
265
282
  "agent_push_url": "http://platform-proxy:10205/v2/push/",
283
+ "agent_target": "platform-target",
266
284
  }
267
285
  }
268
286
  },
269
287
  default_enabled=False,
270
288
  )
271
289
 
272
- assert settings.bkm_data_id == 1003
273
- assert settings.bkm_access_token == "platform-secret"
274
- assert settings.bkm_push_url == "http://platform-proxy:10205/v2/push/"
290
+ assert settings.bkm_data_id == 1002
291
+ assert settings.bkm_access_token == "local-secret"
292
+ assert settings.bkm_push_url == "http://local-proxy:10205/v2/push/"
293
+ assert settings.bkm_target == "local-target"
275
294
 
276
295
 
277
296
  def test_metric_settings_parse_false_string_safely():
@@ -2,6 +2,7 @@ from types import SimpleNamespace
2
2
 
3
3
  import aidev_agent.packages as aidev_agent_packages
4
4
  import pytest
5
+ from aidev_agent.packages.opentelemetry.utils import ExporterType
5
6
  from aidev_bkplugin import apps
6
7
 
7
8
 
@@ -65,6 +66,40 @@ def _mock_otel_inputs(mocker, agent_info, metric_settings):
65
66
  return otel_config, instrumentor, get_agent_info
66
67
 
67
68
 
69
+ def test_deduplicate_otel_endpoints_keeps_first_effective_destination():
70
+ preferred = {"url": "https://collector.example/api", "token": "token", "exporter_type": ExporterType.GRPC}
71
+ duplicate = {"url": "https://collector.example/api/", "token": "token", "exporter_type": ExporterType.GRPC}
72
+ different_token = {"url": preferred["url"], "token": "other-token", "exporter_type": ExporterType.GRPC}
73
+ different_protocol = {"url": preferred["url"], "token": "token", "exporter_type": ExporterType.HTTP}
74
+
75
+ assert apps._deduplicate_otel_endpoints([preferred, duplicate, different_token, different_protocol]) == [
76
+ preferred,
77
+ different_token,
78
+ different_protocol,
79
+ ]
80
+
81
+
82
+ def test_init_otel_deduplicates_endpoint_sources_before_instrumenting(mocker):
83
+ endpoint = {"url": "https://collector.example/api", "token": "token", "exporter_type": ExporterType.GRPC}
84
+ metric_settings = SimpleNamespace(
85
+ enabled=False,
86
+ export_via_celery=False,
87
+ export_interval_millis=1500,
88
+ export_timeout_millis=7000,
89
+ )
90
+ otel_config, instrumentor, _ = _mock_otel_inputs(mocker, {}, metric_settings)
91
+ apps.get_otel_endpoint_by_json_str.return_value = [endpoint]
92
+ apps.get_otel_endpoint_by_agent_info.return_value = [{**endpoint}]
93
+ apps.get_otel_endpoint_by_env.return_value = [{**endpoint}]
94
+ mocker.patch.object(apps, "configure_metric_identity")
95
+ mocker.patch.object(apps, "set_metric_service")
96
+
97
+ apps.init_bk_aidev_agent_otel()
98
+
99
+ assert otel_config.otel_endpoints == [endpoint]
100
+ instrumentor.instrument.assert_called_once_with()
101
+
102
+
68
103
  @pytest.mark.parametrize(
69
104
  "argv",
70
105
  [
@@ -67,7 +67,7 @@ EXIT_PROBE = dedent("""
67
67
  patch.object(apps, "enqueue_bkm_metrics_task", lambda *args: None),
68
68
  patch.object(BkAgentOTelService, "_create_metric_exporter", side_effect=lambda *args: SlowExporter()),
69
69
  patch.object(BkAgentOTelService, "_create_trace_exporter", side_effect=lambda *args: SlowSpanExporter()),
70
- patch.object(BkPluginMetricService, "_create_celery_exporter", side_effect=lambda: SlowExporter()),
70
+ patch.object(BkPluginMetricService, "_create_bkm_exporter", side_effect=lambda: SlowExporter()),
71
71
  ):
72
72
  apps.init_bk_aidev_agent_otel()
73
73
  metrics.get_meter("exit-probe").create_counter("probe.count").add(1)