ioc-scope-api 1.0.0__py3-none-any.whl
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.
- ioc_scope_api-1.0.0.dist-info/METADATA +306 -0
- ioc_scope_api-1.0.0.dist-info/RECORD +106 -0
- ioc_scope_api-1.0.0.dist-info/WHEEL +4 -0
- ioc_scope_api-1.0.0.dist-info/entry_points.txt +2 -0
- scope/__init__.py +27 -0
- scope/api/__init__.py +119 -0
- scope/api/api_v1/__init__.py +2 -0
- scope/api/api_v1/api.py +71 -0
- scope/api/api_v1/endpoints/__init__.py +2 -0
- scope/api/api_v1/endpoints/agentic_protocols_metrics.py +39 -0
- scope/api/api_v1/endpoints/applications.py +440 -0
- scope/api/api_v1/endpoints/cache.py +50 -0
- scope/api/api_v1/endpoints/concepts.py +123 -0
- scope/api/api_v1/endpoints/features.py +19 -0
- scope/api/api_v1/endpoints/helpers.py +65 -0
- scope/api/api_v1/endpoints/kg.py +195 -0
- scope/api/api_v1/endpoints/labels.py +71 -0
- scope/api/api_v1/endpoints/live_topology.py +89 -0
- scope/api/api_v1/endpoints/metrics.py +1014 -0
- scope/api/api_v1/endpoints/reasoning.py +62 -0
- scope/api/api_v1/endpoints/semanticgroups.py +144 -0
- scope/api/api_v1/endpoints/sessions.py +339 -0
- scope/api/api_v1/endpoints/spans.py +41 -0
- scope/api/api_v1/endpoints/symbolic.py +186 -0
- scope/api/api_v1/endpoints/ui.py +145 -0
- scope/api/api_v1/endpoints/waste_estimation.py +182 -0
- scope/api/api_v2/__init__.py +3 -0
- scope/api/api_v2/api.py +23 -0
- scope/api/api_v2/endpoints/__init__.py +3 -0
- scope/api/api_v2/endpoints/metrics.py +193 -0
- scope/app.py +30 -0
- scope/cache.py +64 -0
- scope/client/__init__.py +27 -0
- scope/client/_concepts.py +137 -0
- scope/client/_kg.py +64 -0
- scope/client/_labels.py +86 -0
- scope/client/_live_topology.py +912 -0
- scope/client/_metrics.py +561 -0
- scope/client/_semanticgroups.py +166 -0
- scope/client/_sessions.py +168 -0
- scope/client/_symbolic.py +1354 -0
- scope/client/_ui.py +599 -0
- scope/client/agentic_protocols.py +289 -0
- scope/client/application_charts.py +1786 -0
- scope/client/applications.py +2246 -0
- scope/client/base.py +49 -0
- scope/client/cognition_protocols.py +302 -0
- scope/client/constants.py +81 -0
- scope/client/dal.py +2382 -0
- scope/client/failures.py +70 -0
- scope/client/local.py +161 -0
- scope/client/mock/__init__.py +7 -0
- scope/client/mock/client.py +1034 -0
- scope/client/sessions.py +1688 -0
- scope/client/spans.py +95 -0
- scope/client/utils.py +392 -0
- scope/connectors/__init__.py +13 -0
- scope/connectors/base.py +52 -0
- scope/connectors/clickhouse.py +105 -0
- scope/connectors/neo4j.py +220 -0
- scope/connectors/sqlalchemy.py +131 -0
- scope/core/config.py +530 -0
- scope/core/exceptions.py +64 -0
- scope/dependencies.py +164 -0
- scope/health.py +10 -0
- scope/interfaces/__init__.py +33 -0
- scope/interfaces/data_provider.py +61 -0
- scope/interfaces/integration_example.py +310 -0
- scope/interfaces/kg_provider.py +91 -0
- scope/interfaces/metrics_provider.py +92 -0
- scope/interfaces/models.py +185 -0
- scope/models/kg.py +48 -0
- scope/models/live_topology.py +78 -0
- scope/models/otel_traces.py +1595 -0
- scope/providers/__init__.py +277 -0
- scope/providers/_graph.py +59 -0
- scope/providers/cognition_protocols.py +178 -0
- scope/providers/kg.py +702 -0
- scope/providers/kg_query_runner.py +109 -0
- scope/providers/neo4j_mce.py +18 -0
- scope/providers/scope_metrics.py +7 -0
- scope/query_builders/__init__.py +14 -0
- scope/query_builders/cognition_protocol_graph.py +191 -0
- scope/query_builders/concepts.py +112 -0
- scope/query_builders/dal.py +931 -0
- scope/query_builders/failure_graph.py +102 -0
- scope/query_builders/features.py +5 -0
- scope/query_builders/kg.py +416 -0
- scope/query_builders/labels.py +53 -0
- scope/query_builders/live_topology.py +503 -0
- scope/query_builders/metric_graph.py +196 -0
- scope/query_builders/metrics.py +354 -0
- scope/query_builders/semanticgroups.py +46 -0
- scope/query_builders/sessions.py +208 -0
- scope/query_builders/symbolic.py +615 -0
- scope/query_builders/trajectory.py +76 -0
- scope/query_builders/types.py +20 -0
- scope/query_builders/ui.py +3278 -0
- scope/query_builders/waste_estimation.py +221 -0
- scope/repositories/__init__.py +28 -0
- scope/repositories/clickhouse_otel_repository.py +135 -0
- scope/repositories/otel_repository.py +97 -0
- scope/repositories/sqlite_repository.py +215 -0
- scope/scripts/__init__.py +2 -0
- scope/scripts/seed.py +35 -0
- scope/workarounds.py +38 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""FastAPI router for the /agentic-protocols-metrics endpoint."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from fastapi import APIRouter, Depends, Query
|
|
10
|
+
|
|
11
|
+
from scope.api.api_v1.endpoints.helpers import get_client
|
|
12
|
+
from scope.connectors.base import Connector
|
|
13
|
+
from scope.dependencies import get_db
|
|
14
|
+
from scope.models.otel_traces import AgenticProtocolsMetricsResponse
|
|
15
|
+
|
|
16
|
+
router = APIRouter()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _client(db: Connector = Depends(get_db)): # noqa: B008
|
|
20
|
+
"""Lazily resolve the UI client from the current DB dependency."""
|
|
21
|
+
return get_client(api_client=db)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@router.get(
|
|
25
|
+
"/agentic-protocols-metrics",
|
|
26
|
+
response_model=AgenticProtocolsMetricsResponse,
|
|
27
|
+
)
|
|
28
|
+
def get_agentic_protocols_metrics(
|
|
29
|
+
application: str = Query(..., description="Application name"),
|
|
30
|
+
start_time: str = Query("", description="Start time as Unix epoch (seconds)"),
|
|
31
|
+
end_time: str = Query("", description="End time as Unix epoch (seconds)"),
|
|
32
|
+
ui_client=Depends(_client), # noqa: B008
|
|
33
|
+
) -> Any:
|
|
34
|
+
"""Return SLIM agentic-protocol metrics for an application."""
|
|
35
|
+
return ui_client.get_agentic_protocols_metrics(
|
|
36
|
+
application=application,
|
|
37
|
+
start_time=start_time or None,
|
|
38
|
+
end_time=end_time or None,
|
|
39
|
+
)
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""FastAPI router for the /applications endpoint."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import redis as redis_lib
|
|
10
|
+
from fastapi import APIRouter, Depends, Query
|
|
11
|
+
|
|
12
|
+
from scope.api.api_v1.endpoints.helpers import get_client
|
|
13
|
+
from scope.cache import cached, make_cache_key
|
|
14
|
+
from scope.connectors.base import Connector
|
|
15
|
+
from scope.core.config import settings
|
|
16
|
+
from scope.dependencies import get_db, get_neo4j_db, get_redis
|
|
17
|
+
from scope.models.otel_traces import (
|
|
18
|
+
ApplicationAgentToolsResponse,
|
|
19
|
+
CollectByApplicationResponse,
|
|
20
|
+
ImpactAssessmentResponse,
|
|
21
|
+
MonitorApplicationLevelData,
|
|
22
|
+
MonitorByApplicationResponse,
|
|
23
|
+
SemanticgroupsResponse,
|
|
24
|
+
SessionsWithCognitiveObservabilityResponse,
|
|
25
|
+
SessionsWithCognitionProtocolsResponse,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
router = APIRouter()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _client(db: Connector = Depends(get_db)): # noqa: B008
|
|
32
|
+
"""Lazily resolve the UI client from the current DB dependency."""
|
|
33
|
+
return get_client(api_client=db)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _kg_client(db: Connector = Depends(get_neo4j_db)): # noqa: B008
|
|
37
|
+
"""Resolve a client backed by Neo4j for KG-only endpoints."""
|
|
38
|
+
return get_client(api_client=db)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# ── Endpoints ─────────────────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@router.get("/{application_id}/agents", response_model=MonitorByApplicationResponse)
|
|
45
|
+
def application_agents(
|
|
46
|
+
application_id: str,
|
|
47
|
+
start_time: str = Query(""),
|
|
48
|
+
end_time: str = Query(""),
|
|
49
|
+
ui_client=Depends(_client), # noqa: B008
|
|
50
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
51
|
+
) -> Any:
|
|
52
|
+
"""Return per-agent monitoring data for an application."""
|
|
53
|
+
key = make_cache_key(
|
|
54
|
+
"applications:agents",
|
|
55
|
+
{"app": application_id, "start": start_time, "end": end_time},
|
|
56
|
+
)
|
|
57
|
+
return cached(
|
|
58
|
+
redis_client=redis_client,
|
|
59
|
+
key=key,
|
|
60
|
+
fetch=lambda: ui_client.get_application_agents(
|
|
61
|
+
application_id=application_id,
|
|
62
|
+
start_time=start_time,
|
|
63
|
+
end_time=end_time,
|
|
64
|
+
),
|
|
65
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
66
|
+
enabled=settings.CACHE_ENABLED,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@router.get("/{application_id}/sessions", response_model=CollectByApplicationResponse)
|
|
71
|
+
def application_sessions(
|
|
72
|
+
application_id: str,
|
|
73
|
+
start_time: str = Query(""),
|
|
74
|
+
end_time: str = Query(""),
|
|
75
|
+
ui_client=Depends(_kg_client), # noqa: B008
|
|
76
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
77
|
+
) -> Any:
|
|
78
|
+
"""Return session-level data for an application."""
|
|
79
|
+
key = make_cache_key(
|
|
80
|
+
"applications:sessions",
|
|
81
|
+
{"app": application_id, "start": start_time, "end": end_time},
|
|
82
|
+
)
|
|
83
|
+
return cached(
|
|
84
|
+
redis_client=redis_client,
|
|
85
|
+
key=key,
|
|
86
|
+
fetch=lambda: ui_client.get_application_sessions(
|
|
87
|
+
application_id=application_id,
|
|
88
|
+
start_time=start_time,
|
|
89
|
+
end_time=end_time,
|
|
90
|
+
),
|
|
91
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
92
|
+
enabled=settings.CACHE_ENABLED,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@router.get(
|
|
97
|
+
"/{application_id}/sessions_with_stateful_eval_multi_query",
|
|
98
|
+
response_model=CollectByApplicationResponse,
|
|
99
|
+
)
|
|
100
|
+
def application_sessions_with_stateful_eval_multi_query(
|
|
101
|
+
application_id: str,
|
|
102
|
+
start_time: str = Query(""),
|
|
103
|
+
end_time: str = Query(""),
|
|
104
|
+
ui_client=Depends(_kg_client), # noqa: B008
|
|
105
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
106
|
+
) -> Any:
|
|
107
|
+
"""Return session-level data for an application including statefulEval metric."""
|
|
108
|
+
key = make_cache_key(
|
|
109
|
+
"applications:sessions_with_stateful_eval_multi_query",
|
|
110
|
+
{"app": application_id, "start": start_time, "end": end_time},
|
|
111
|
+
)
|
|
112
|
+
return cached(
|
|
113
|
+
redis_client=redis_client,
|
|
114
|
+
key=key,
|
|
115
|
+
fetch=lambda: ui_client.get_application_sessions_with_stateful_eval_multi_query(
|
|
116
|
+
application_id=application_id,
|
|
117
|
+
start_time=start_time,
|
|
118
|
+
end_time=end_time,
|
|
119
|
+
),
|
|
120
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
121
|
+
enabled=settings.CACHE_ENABLED,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@router.get(
|
|
126
|
+
"/{application_id}/sessions_with_stateful_eval",
|
|
127
|
+
response_model=CollectByApplicationResponse,
|
|
128
|
+
)
|
|
129
|
+
def application_sessions_with_stateful_eval(
|
|
130
|
+
application_id: str,
|
|
131
|
+
start_time: str = Query(""),
|
|
132
|
+
end_time: str = Query(""),
|
|
133
|
+
semantic_group_id: str = Query(""),
|
|
134
|
+
ui_client=Depends(_kg_client), # noqa: B008
|
|
135
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
136
|
+
) -> Any:
|
|
137
|
+
"""Return session-level data using one query for statefulEval + metrics."""
|
|
138
|
+
key = make_cache_key(
|
|
139
|
+
"applications:sessions_with_stateful_eval",
|
|
140
|
+
{
|
|
141
|
+
"app": application_id,
|
|
142
|
+
"start": start_time,
|
|
143
|
+
"end": end_time,
|
|
144
|
+
"semantic_group": semantic_group_id,
|
|
145
|
+
},
|
|
146
|
+
)
|
|
147
|
+
return cached(
|
|
148
|
+
redis_client=redis_client,
|
|
149
|
+
key=key,
|
|
150
|
+
fetch=lambda: ui_client.get_application_sessions_with_stateful_eval(
|
|
151
|
+
application_id=application_id,
|
|
152
|
+
start_time=start_time,
|
|
153
|
+
end_time=end_time,
|
|
154
|
+
semantic_group_id=semantic_group_id,
|
|
155
|
+
),
|
|
156
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
157
|
+
enabled=settings.CACHE_ENABLED,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@router.get(
|
|
162
|
+
"/{application_id}/sessions-with-cognitive-observability",
|
|
163
|
+
response_model=SessionsWithCognitiveObservabilityResponse,
|
|
164
|
+
)
|
|
165
|
+
def application_sessions_with_cognitive_observability(
|
|
166
|
+
application_id: str,
|
|
167
|
+
start_time: str = Query(""),
|
|
168
|
+
end_time: str = Query(""),
|
|
169
|
+
session_id: str = Query(""),
|
|
170
|
+
ui_client=Depends(_kg_client), # noqa: B008
|
|
171
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
172
|
+
) -> Any:
|
|
173
|
+
"""Return sessions with their cognitive metrics and failures from the KG."""
|
|
174
|
+
key = make_cache_key(
|
|
175
|
+
"applications:sessions_with_cognitive_observability",
|
|
176
|
+
{
|
|
177
|
+
"app": application_id,
|
|
178
|
+
"start": start_time,
|
|
179
|
+
"end": end_time,
|
|
180
|
+
"session": session_id,
|
|
181
|
+
},
|
|
182
|
+
)
|
|
183
|
+
return cached(
|
|
184
|
+
redis_client=redis_client,
|
|
185
|
+
key=key,
|
|
186
|
+
fetch=lambda: ui_client.get_application_sessions_with_cognitive_observability(
|
|
187
|
+
application_id=application_id,
|
|
188
|
+
start_time=start_time,
|
|
189
|
+
end_time=end_time,
|
|
190
|
+
session_id=session_id,
|
|
191
|
+
),
|
|
192
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
193
|
+
enabled=settings.CACHE_ENABLED,
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
@router.get(
|
|
198
|
+
"/{application_id}/sessions-with-cognition-protocols",
|
|
199
|
+
response_model=SessionsWithCognitionProtocolsResponse,
|
|
200
|
+
)
|
|
201
|
+
def application_sessions_with_cognition_protocols(
|
|
202
|
+
application_id: str,
|
|
203
|
+
start_time: str = Query(""),
|
|
204
|
+
end_time: str = Query(""),
|
|
205
|
+
ui_client=Depends(_kg_client), # noqa: B008
|
|
206
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
207
|
+
) -> Any:
|
|
208
|
+
"""Return sessions with their Cognition protocol status from the KG."""
|
|
209
|
+
key = make_cache_key(
|
|
210
|
+
"applications:sessions_with_cognition_protocols",
|
|
211
|
+
{"app": application_id, "start": start_time, "end": end_time},
|
|
212
|
+
)
|
|
213
|
+
return cached(
|
|
214
|
+
redis_client=redis_client,
|
|
215
|
+
key=key,
|
|
216
|
+
fetch=lambda: ui_client.get_application_sessions_with_cognition_protocols(
|
|
217
|
+
application_id=application_id,
|
|
218
|
+
start_time=start_time,
|
|
219
|
+
end_time=end_time,
|
|
220
|
+
),
|
|
221
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
222
|
+
enabled=settings.CACHE_ENABLED,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@router.get("/{application_id}/agent/{agent_id}/charts")
|
|
227
|
+
def application_charts(
|
|
228
|
+
application_id: str,
|
|
229
|
+
agent_id: str,
|
|
230
|
+
chart_type: str = Query(...),
|
|
231
|
+
start_time: str = Query(""),
|
|
232
|
+
end_time: str = Query(""),
|
|
233
|
+
ui_client=Depends(_client), # noqa: B008
|
|
234
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
235
|
+
) -> Any:
|
|
236
|
+
"""Return chart data for an application by chart type."""
|
|
237
|
+
key = make_cache_key(
|
|
238
|
+
"applications:charts",
|
|
239
|
+
{
|
|
240
|
+
"app": application_id,
|
|
241
|
+
"agent": agent_id,
|
|
242
|
+
"chart": chart_type,
|
|
243
|
+
"start": start_time,
|
|
244
|
+
"end": end_time,
|
|
245
|
+
},
|
|
246
|
+
)
|
|
247
|
+
return cached(
|
|
248
|
+
redis_client=redis_client,
|
|
249
|
+
key=key,
|
|
250
|
+
fetch=lambda: ui_client.get_application_charts(
|
|
251
|
+
application_id=application_id,
|
|
252
|
+
agent_id=agent_id,
|
|
253
|
+
chart_type=chart_type,
|
|
254
|
+
start_time=start_time,
|
|
255
|
+
end_time=end_time,
|
|
256
|
+
),
|
|
257
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
258
|
+
enabled=settings.CACHE_ENABLED,
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
@router.get("/{application_id}/topology")
|
|
263
|
+
def application_topology(
|
|
264
|
+
application_id: str,
|
|
265
|
+
ui_client=Depends(_client), # noqa: B008
|
|
266
|
+
kg_client=Depends(_kg_client), # noqa: B008
|
|
267
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
268
|
+
) -> Any:
|
|
269
|
+
"""Return the topology for an application.
|
|
270
|
+
|
|
271
|
+
The graph the application declared (the ``gen_ai.ioa.graph`` attribute of its
|
|
272
|
+
graph span) when it has one, otherwise its structural agents from the
|
|
273
|
+
knowledge graph.
|
|
274
|
+
"""
|
|
275
|
+
key = make_cache_key(
|
|
276
|
+
"applications:topology",
|
|
277
|
+
{"app": application_id},
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
def fetch() -> Any:
|
|
281
|
+
declared = ui_client.get_application_topology(application_id=application_id)
|
|
282
|
+
if declared and declared.get("nodes"):
|
|
283
|
+
return declared
|
|
284
|
+
return kg_client.get_application_structural_topology(
|
|
285
|
+
application_id=application_id,
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
return cached(
|
|
289
|
+
redis_client=redis_client,
|
|
290
|
+
key=key,
|
|
291
|
+
fetch=fetch,
|
|
292
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
293
|
+
enabled=settings.CACHE_ENABLED,
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
@router.get(
|
|
298
|
+
"/{application_id}/agent-tools", response_model=ApplicationAgentToolsResponse
|
|
299
|
+
)
|
|
300
|
+
def application_agent_tools(
|
|
301
|
+
application_id: str,
|
|
302
|
+
ui_client=Depends(_kg_client), # noqa: B008
|
|
303
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
304
|
+
) -> Any:
|
|
305
|
+
"""Return each agent's tools for an application.
|
|
306
|
+
|
|
307
|
+
Sourced from the knowledge graph's structural ``Agent -[:usesTool]->
|
|
308
|
+
Tool`` edges rather than the topology endpoint's self-reported
|
|
309
|
+
``gen_ai.ioa.graph`` span attribute, which is not guaranteed to
|
|
310
|
+
include tool nodes.
|
|
311
|
+
"""
|
|
312
|
+
key = make_cache_key(
|
|
313
|
+
"applications:agent_tools",
|
|
314
|
+
{"app": application_id},
|
|
315
|
+
)
|
|
316
|
+
return cached(
|
|
317
|
+
redis_client=redis_client,
|
|
318
|
+
key=key,
|
|
319
|
+
fetch=lambda: ui_client.get_application_agent_tools(
|
|
320
|
+
application_id=application_id,
|
|
321
|
+
),
|
|
322
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
323
|
+
enabled=settings.CACHE_ENABLED,
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
@router.get(
|
|
328
|
+
"/{application_id}/semanticgroups/table", response_model=SemanticgroupsResponse
|
|
329
|
+
)
|
|
330
|
+
def get_application_semanticgroups_table(
|
|
331
|
+
application_id: str,
|
|
332
|
+
start_time: str = Query(""),
|
|
333
|
+
end_time: str = Query(""),
|
|
334
|
+
ui_client=Depends(_kg_client), # noqa: B008
|
|
335
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
336
|
+
) -> Any:
|
|
337
|
+
"""Return application-level monitoring data."""
|
|
338
|
+
key = make_cache_key(
|
|
339
|
+
"applications:semanticgroups:table",
|
|
340
|
+
{"app": application_id, "start": start_time, "end": end_time},
|
|
341
|
+
)
|
|
342
|
+
return cached(
|
|
343
|
+
redis_client=redis_client,
|
|
344
|
+
key=key,
|
|
345
|
+
fetch=lambda: ui_client.get_application_semanticgroups_table(
|
|
346
|
+
application_id=application_id,
|
|
347
|
+
start_time=start_time,
|
|
348
|
+
end_time=end_time,
|
|
349
|
+
),
|
|
350
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
351
|
+
enabled=settings.CACHE_ENABLED,
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
@router.get("/{application_id}/semanticgroups", response_model=SemanticgroupsResponse)
|
|
356
|
+
def get_application_semanticgroups(
|
|
357
|
+
application_id: str,
|
|
358
|
+
start_time: str = Query(""),
|
|
359
|
+
end_time: str = Query(""),
|
|
360
|
+
ui_client=Depends(_kg_client), # noqa: B008
|
|
361
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
362
|
+
) -> Any:
|
|
363
|
+
"""Return application-level monitoring data."""
|
|
364
|
+
key = make_cache_key(
|
|
365
|
+
"applications:semanticgroups",
|
|
366
|
+
{"app": application_id, "start": start_time, "end": end_time},
|
|
367
|
+
)
|
|
368
|
+
return cached(
|
|
369
|
+
redis_client=redis_client,
|
|
370
|
+
key=key,
|
|
371
|
+
fetch=lambda: ui_client.get_application_semanticgroups(
|
|
372
|
+
application_id=application_id,
|
|
373
|
+
start_time=start_time,
|
|
374
|
+
end_time=end_time,
|
|
375
|
+
),
|
|
376
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
377
|
+
enabled=settings.CACHE_ENABLED,
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
@router.get(
|
|
382
|
+
"/{application_id}/semanticgroups/{semanticgroup_id}/impact_assessment",
|
|
383
|
+
response_model=ImpactAssessmentResponse,
|
|
384
|
+
)
|
|
385
|
+
def get_application_semanticgroup_impact_assessment(
|
|
386
|
+
application_id: str,
|
|
387
|
+
semanticgroup_id: str,
|
|
388
|
+
start_time: str = Query(""),
|
|
389
|
+
end_time: str = Query(""),
|
|
390
|
+
ui_client=Depends(_kg_client), # noqa: B008
|
|
391
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
392
|
+
) -> Any:
|
|
393
|
+
"""Return impact assessment for a semantic group."""
|
|
394
|
+
key = make_cache_key(
|
|
395
|
+
"applications:semanticgroups:impact",
|
|
396
|
+
{
|
|
397
|
+
"app": application_id,
|
|
398
|
+
"sg": semanticgroup_id,
|
|
399
|
+
"start": start_time,
|
|
400
|
+
"end": end_time,
|
|
401
|
+
},
|
|
402
|
+
)
|
|
403
|
+
return cached(
|
|
404
|
+
redis_client=redis_client,
|
|
405
|
+
key=key,
|
|
406
|
+
fetch=lambda: ui_client.get_application_semanticgroup_impact_assessment(
|
|
407
|
+
application_id=application_id,
|
|
408
|
+
semanticgroup_id=semanticgroup_id,
|
|
409
|
+
start_time=start_time,
|
|
410
|
+
end_time=end_time,
|
|
411
|
+
),
|
|
412
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
413
|
+
enabled=settings.CACHE_ENABLED,
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
@router.get("/{application_id}", response_model=MonitorApplicationLevelData)
|
|
418
|
+
def application_details(
|
|
419
|
+
application_id: str,
|
|
420
|
+
start_time: str = Query(""),
|
|
421
|
+
end_time: str = Query(""),
|
|
422
|
+
ui_client=Depends(_client), # noqa: B008
|
|
423
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
424
|
+
) -> Any:
|
|
425
|
+
"""Return application-level monitoring data."""
|
|
426
|
+
key = make_cache_key(
|
|
427
|
+
"applications:details",
|
|
428
|
+
{"app": application_id, "start": start_time, "end": end_time},
|
|
429
|
+
)
|
|
430
|
+
return cached(
|
|
431
|
+
redis_client=redis_client,
|
|
432
|
+
key=key,
|
|
433
|
+
fetch=lambda: ui_client.get_application_details(
|
|
434
|
+
application_id=application_id,
|
|
435
|
+
start_time=start_time,
|
|
436
|
+
end_time=end_time,
|
|
437
|
+
),
|
|
438
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
439
|
+
enabled=settings.CACHE_ENABLED,
|
|
440
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""FastAPI router for cache management endpoints.
|
|
4
|
+
|
|
5
|
+
Endpoints
|
|
6
|
+
---------
|
|
7
|
+
DELETE /cache
|
|
8
|
+
Invalidate all Redis cache entries (keys matching ``cache:*``).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import logging
|
|
14
|
+
|
|
15
|
+
import redis
|
|
16
|
+
from fastapi import APIRouter, Depends, HTTPException
|
|
17
|
+
from pydantic import BaseModel
|
|
18
|
+
|
|
19
|
+
from scope.dependencies import get_redis
|
|
20
|
+
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
router = APIRouter()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class CacheInvalidationResponse(BaseModel):
|
|
27
|
+
deleted: int
|
|
28
|
+
message: str
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@router.delete("/", response_model=CacheInvalidationResponse)
|
|
32
|
+
def invalidate_cache(
|
|
33
|
+
redis_client: redis.Redis = Depends(get_redis),
|
|
34
|
+
) -> CacheInvalidationResponse:
|
|
35
|
+
"""Delete all Redis keys under the ``cache:*`` namespace."""
|
|
36
|
+
try:
|
|
37
|
+
keys = redis_client.keys("cache:*")
|
|
38
|
+
deleted = len(keys)
|
|
39
|
+
if keys:
|
|
40
|
+
redis_client.delete(*keys)
|
|
41
|
+
logger.info("Cache invalidated — %d key(s) deleted", deleted)
|
|
42
|
+
return CacheInvalidationResponse(
|
|
43
|
+
deleted=deleted,
|
|
44
|
+
message=f"Cache invalidated: {deleted} key(s) deleted.",
|
|
45
|
+
)
|
|
46
|
+
except Exception as exc:
|
|
47
|
+
logger.error("Cache invalidation failed: %s", exc)
|
|
48
|
+
raise HTTPException(
|
|
49
|
+
status_code=503, detail=f"Cache invalidation failed: {exc}"
|
|
50
|
+
) from exc
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""FastAPI router for the /concepts endpoint.
|
|
4
|
+
|
|
5
|
+
Endpoints
|
|
6
|
+
---------
|
|
7
|
+
GET /concepts/{app_id}
|
|
8
|
+
Read symbols / concepts for neurosymbolic analysis for an application.
|
|
9
|
+
POST /concepts/{app_id}
|
|
10
|
+
Write concepts to an application.
|
|
11
|
+
|
|
12
|
+
GET /concepts/{app_id}/sessions/{session_id}/spans/{span_id}
|
|
13
|
+
Read symbols / concepts for a specific span.
|
|
14
|
+
POST /concepts/{app_id}/sessions/{session_id}/spans/{span_id}
|
|
15
|
+
Write concepts to a span.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
import redis as redis_lib
|
|
23
|
+
from fastapi import APIRouter, Depends
|
|
24
|
+
|
|
25
|
+
from scope.api.api_v1.endpoints.helpers import get_client
|
|
26
|
+
from scope.cache import cached, make_cache_key
|
|
27
|
+
from scope.connectors.base import Connector
|
|
28
|
+
from scope.core.config import settings
|
|
29
|
+
from scope.dependencies import get_neo4j_db, get_redis
|
|
30
|
+
from scope.models.otel_traces import (
|
|
31
|
+
ConceptsResponse,
|
|
32
|
+
ConceptsWriteRequest,
|
|
33
|
+
ConceptsWriteResponse,
|
|
34
|
+
SpanConceptsResponse,
|
|
35
|
+
SpanConceptsWriteRequest,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
router = APIRouter()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _client(db: Connector = Depends(get_neo4j_db)): # noqa: B008
|
|
42
|
+
"""Lazily resolve the concepts client from the shared Neo4j dependency."""
|
|
43
|
+
return get_client(api_client=db)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# ── App-level concepts ────────────────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@router.get("/{app_id}", response_model=ConceptsResponse)
|
|
50
|
+
def get_app_concepts(
|
|
51
|
+
app_id: str,
|
|
52
|
+
concepts_client=Depends(_client), # noqa: B008
|
|
53
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
54
|
+
) -> Any:
|
|
55
|
+
"""Return all concepts for *app_id*."""
|
|
56
|
+
key = make_cache_key("concepts:app", {"app": app_id})
|
|
57
|
+
return cached(
|
|
58
|
+
redis_client=redis_client,
|
|
59
|
+
key=key,
|
|
60
|
+
fetch=lambda: concepts_client.get_app_concepts(app_id),
|
|
61
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
62
|
+
enabled=settings.CACHE_ENABLED,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@router.post("/{app_id}", response_model=ConceptsWriteResponse)
|
|
67
|
+
def post_app_concepts(
|
|
68
|
+
app_id: str, body: ConceptsWriteRequest, concepts_client=Depends(_client)
|
|
69
|
+
) -> Any: # noqa: B008
|
|
70
|
+
"""Write concepts to an application in the knowledge graph."""
|
|
71
|
+
result = concepts_client.write_app_concepts(
|
|
72
|
+
app_id,
|
|
73
|
+
concepts=[c.model_dump() for c in body.concepts],
|
|
74
|
+
)
|
|
75
|
+
return ConceptsWriteResponse(**result)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# ── Span-level concepts ──────────────────────────────────────────────────────
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@router.get(
|
|
82
|
+
"/{app_id}/sessions/{session_id}/spans/{span_id}",
|
|
83
|
+
response_model=SpanConceptsResponse,
|
|
84
|
+
)
|
|
85
|
+
def get_span_concepts(
|
|
86
|
+
app_id: str,
|
|
87
|
+
session_id: str,
|
|
88
|
+
span_id: str,
|
|
89
|
+
concepts_client=Depends(_client), # noqa: B008
|
|
90
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
91
|
+
) -> Any:
|
|
92
|
+
"""Return concepts for a specific span."""
|
|
93
|
+
key = make_cache_key(
|
|
94
|
+
"concepts:span", {"app": app_id, "session": session_id, "span": span_id}
|
|
95
|
+
)
|
|
96
|
+
return cached(
|
|
97
|
+
redis_client=redis_client,
|
|
98
|
+
key=key,
|
|
99
|
+
fetch=lambda: concepts_client.get_span_concepts(app_id, session_id, span_id),
|
|
100
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
101
|
+
enabled=settings.CACHE_ENABLED,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@router.post(
|
|
106
|
+
"/{app_id}/sessions/{session_id}/spans/{span_id}",
|
|
107
|
+
response_model=ConceptsWriteResponse,
|
|
108
|
+
)
|
|
109
|
+
def post_span_concepts(
|
|
110
|
+
app_id: str,
|
|
111
|
+
session_id: str,
|
|
112
|
+
span_id: str,
|
|
113
|
+
body: SpanConceptsWriteRequest,
|
|
114
|
+
concepts_client=Depends(_client), # noqa: B008
|
|
115
|
+
) -> Any:
|
|
116
|
+
"""Write concepts to a span in the knowledge graph."""
|
|
117
|
+
result = concepts_client.write_span_concepts(
|
|
118
|
+
app_id,
|
|
119
|
+
session_id,
|
|
120
|
+
span_id,
|
|
121
|
+
concepts=[c.model_dump() for c in body.concepts],
|
|
122
|
+
)
|
|
123
|
+
return ConceptsWriteResponse(**result)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""FastAPI router for the /features endpoint."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from fastapi import APIRouter, Request
|
|
10
|
+
|
|
11
|
+
from scope.api.api_v1.endpoints.helpers import get_client
|
|
12
|
+
|
|
13
|
+
router = APIRouter()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@router.get("/info")
|
|
17
|
+
def features_info(request: Request) -> Any:
|
|
18
|
+
"""Return descriptive information about this endpoint."""
|
|
19
|
+
return get_client().info(domain="features")
|