Repository navigation
Conversation
…tity The usage report reads the AI Gateway usage of its cluster from the logs database. This adds the access and checks it; the usage API follows. - Cluster template: adxPortalUsage creates <clusterName>-portal-usage with a federated credential for the Portal's service account and the Viewer role on the logs database, only with adxMode create. Kusto grants a role on a whole database, and only a database that the template makes for this cluster holds its rows alone. Output adxPortalUsageClientId. - make deploy: the optional observability.portal block sets the Portal's usage values from the collection's cluster name, Kusto cluster and logs database. - Portal chart: usage.* values, checked; the identity's client ID on the ServiceAccount and the workload identity label on the Pod. The defaults render the same objects as before. - Portal: a token exchange of the projected service account token and a Kusto query client, without an Azure SDK. Queries take their values as query parameters. At start, the Portal looks for AI Gateway rows of another cluster in the database and turns the report off if it finds one; when it cannot read the database, it checks again after a growing delay. - Docs: observability, infrastructure, platform, Helm values, PRIVACY.md.
…s Viewer role Review of #690: adxMode create says who made the logs database, not who writes to it. Another installation can use the same database, and the Viewer role then reads its logs too, even when the Portal turns the report off. The docs, the template parameters, the chart values and the Portal's log now state that no other CetiRun cluster may write to the logs database while the identity has the role, and give the steps to remove the role before one does.
…fuse the portal block with a standalone Portal The workload identity webhook sets AZURE_CLIENT_ID only when it creates a Pod, so a new client ID on the ServiceAccount reached no running Portal: the Pod template now names the client ID. An infrastructure upgrade with a standalone Portal release set the usage values of the platform release's disabled Portal; it now refuses observability.portal there, and still sets the values of the Portal of the platform release.
| the `Viewer` role, the identity can read every table of the logs database. | ||
| These tables include the platform logs, the ingress access log, and the | ||
| inventory. So the role has a prerequisite: no other CetiRun cluster writes to | ||
| the logs database while the identity has the role. `adxMode: create` makes the |
There was a problem hiding this comment.
Please make the prerequisite about retained data as well as active writers. Daily usage can outlive the raw Gateway rows, so a database that no other cluster writes to today can still contain its usage. Use a fresh dedicated database if its history is unknown.
There was a problem hiding this comment.
Thanks, agreed; fixed in 6e93e39. The prerequisite is now that the logs database holds the data of this CetiRun cluster alone: no other cluster writes to it while the identity has the role, and it keeps no data that another cluster wrote earlier. The docs name the daily usage views, which keep their rows for 400 days by default, longer than the request lines, and say to use a new logs database when its history is unknown. The same condition is in the template parameters, the chart value, the example environment file, and PRIVACY.md.
The Portal's start check now also reads GatewayDailyUsage and GatewayDailyUsageV2, in a fuzzy union, so a database without one of the views still gets checked. On the test cluster, this matters: the request lines of a second cluster were deleted from Gateway earlier, so the old check passed, but each daily view still holds 3 rows of that cluster. The new query finds that cluster there (a read-only run).
| database, run: | ||
|
|
||
| ```kusto | ||
| .drop database CetiRunLogs viewers ('aadapp=<portal-usage-client-id>;<tenant-id>') |
There was a problem hiding this comment.
This command targets CetiRunLogs even when observability.adx.databases.logs selects a different database. Use the configured logs database here and verify that the identity no longer has Viewer there before sharing it.
There was a problem hiding this comment.
Thanks, fixed in 6e93e39. The steps now use <logs-database>, the database of observability.adx.databases.logs (by default CetiRunLogs), and end with a check that must return no rows:
.show database <logs-database> principals
| where PrincipalFQN startswith "aadapp=<portal-usage-client-id>"On the test cluster, this command returned the identity's Viewer row, and no row for an unknown client ID.
| if not re.fullmatch(GUID, portal_client): | ||
| raise ValueError("observability.portal.clientId must be the client ID of the managed identity with which the " | ||
| "Portal reads the usage of this cluster") | ||
| values.update({"cetirun-portal.usage.enabled": True, "cetirun-portal.usage.clusterName": cluster, |
There was a problem hiding this comment.
On an infrastructure upgrade with the bundled Portal, this mapping silently overrides an explicit usage.enabled: false or a different client ID in platform.values. The complete deployer rejects the same conflict. Check the explicitly supplied values before applying this mapping so the two deployment paths agree.
There was a problem hiding this comment.
Thanks, fixed in 7cf650f. The infrastructure deployer now checks each usage value of observability.portal against platform.values before it applies it, like the complete deployer: an explicit usage.enabled: false or another client ID fails with "platform.values.cetirun-portal.usage. conflicts with observability.portal". Unset values and values that agree pass.
test_infrastructure_configuration covers both conflicts and both passing cases. Mutations that drop the check, compare with the chart defaults, or check every value of the block fail it. I kept the check to the usage values: the collection, alerter and content values keep their current behavior in this path, because an existing environment may set them in both places today.
Withdraw approval pending repair of the deployment-input conflict in discussion_r4716198773.
…e with data of another cluster Review of #690: the daily usage views keep their rows longer than the raw Gateway rows, so a logs database that no other cluster writes to today can still hold the usage of one, and the removal command named CetiRunLogs although observability.adx.databases.logs can select another database. The prerequisite now covers retained data (use a new logs database when its history is unknown), the removal names the configured database and ends with a check that the identity has no role left, and the Portal's start check also reads GatewayDailyUsage and GatewayDailyUsageV2 (a union that leaves out a missing view).
…nst platform.values Review of #690: with the Portal of the platform release, an infrastructure upgrade let observability.portal override an explicit usage value under platform.values, such as usage.enabled false or another client ID, which a complete deployment refuses. It now refuses such a conflict the same way. The other blocks keep their current behavior in this path.
Summary
The usage report of the Portal reads the AI Gateway usage of its cluster from the logs database in Azure Data Explorer (the proposal's phase 2). This pull request gives the Portal that access and checks it. The usage API and the pages follow in their own pull requests.
adxPortalUsagecreates the managed identity<clusterName>-portal-usage. It has a federated credential for the Portal's service accountcetirun-portalinplatformNamespace, and theViewerrole on the logs database only. The new outputadxPortalUsageClientIdgives it tomake deploy. The template creates it only withadxMode: create, and only while the logs database holds the data of this CetiRun cluster alone: Kusto grants a role on a whole database, and the daily usage views keep their rows longer than the request lines. Another installation can still use a database ofadxMode: create, so the docs give the steps to remove the role before it does;adxPortalUsage: falsedoes not remove it.adxPortalUsageis off by default, likeadxAlerterandadxContent.observability.portalblock, withclientId, sets the Portal'susagevalues from the collection'sclusterName, Kusto cluster and logs database. A value that it sets conflicts with the same value underplatform.values, as for the other blocks. An infrastructure upgrade with a standalone Portal release refuses the block, which would set the values of the platform release's disabled Portal. With the Portal of the platform release, an infrastructure upgrade refuses a usage value underplatform.valuesthat differs from the block, like a complete deployment.usage.enabled,usage.clusterName,usage.adx.endpoint,usage.adx.database(CetiRunLogs) andusage.adx.clientId. Withusage.enabled, the chart checks them, names the identity on the ServiceAccount (azure.workload.identity/client-id), labels the Pod for the workload identity webhook, and passes the settings asUSAGE_*variables. The webhook setsAZURE_CLIENT_IDonly when it creates a Pod, so the Pod template also names the client ID (cetirun.microsoft.com/usage-client-id): a new client ID rolls the Portal. With the defaults, the chart renders the same objects as before, so an upgrade without the block restarts no Portal Pod.internal/usage, without an Azure SDK:AZURE_*variables. It keeps a token until 5 minutes before it expires. An Entra error names its code, such asAADSTS700213, without the trace and correlation IDs.declare query_parameters), never as text in the query. Each request is read only (request_readonly), has a server timeout of 30 seconds, and a response limit of 16 MiB. It reports the errors of a refused request, of a row, and of the end of a result.Gatewaytable or in the daily usage viewsGatewayDailyUsageandGatewayDailyUsageV2, which keep their rows longer. A fuzzy union leaves out a view that the database lacks. If the database holds AI Gateway rows of another cluster, the Portal turns the report off and logs why, with the advice to remove the identity's role. The check does not limit the identity. If it cannot read the database, it logs the cause and checks again after 30 seconds, then after a doubled wait, up to 10 minutes. An incomplete configuration turns the report off, not the Portal.make deploy, a new section "The Portal's usage identity" with the log messages), infrastructure, platform, Helm values and the generated chart values, the platform README, the example environment file, andPRIVACY.md: the role covers every table of the logs database, so the database must hold the data of this cluster alone, also no older data of another cluster. "The Portal's usage identity" gives the steps to remove the role from the configured logs database before another cluster writes to it, and a command that shows that no role is left.Related issue
Part of the usage report proposal (phase 2: "the identity, the template output and the
make deployinput"). There is no issue.Validation
Offline:
gofmt,go vet ./...andgo test ./... -count=1(Windows, Go 1.27.4, with theweb/distplaceholder ofportal-ci.yml);go test -race ./internal/usage/. The chart tests ofinternal/config, with Helm 3.22, in a Linux container (Go 1.27.4). New tests: the token exchange and its cache, the query client against recorded frames of a Kusto cluster, the check, its retries, and the wiring from the chart to the configuration.scripts/testsin a Linux container with Helm 3.22 and Bicep 0.47.16:test_portal_usage_chart(new, 4),test_cluster_deploy(41),test_full_deployment(120),test_portal_chat_chart,test_portal_ownership_chart,test_portal_sandbox_storage,test_public_ingress_chart,test_skill_marketplace_platform: OK.test_infrastructure_configuration(37) with Python 3.12, which its tar filters need: OK.main; withusage.enabled, only the ServiceAccount annotation, the Pod label and annotation, and the four variables change.make deployand the template fail a test.scripts/ci/validate.py python-check, license headers,site/tests(157), the generated reference tables, source-level site checks (0 content errors, no new findings in the changed lines), andbicep buildofinfra/cluster/main.bicep: OK.Live, on a test cluster with CetiRun v0.2.2 and its ADX database. The Portal ran an image of this branch merged with #689 and #681, set with
kubectltogether with the values that the chart renders:main.bicepgives it, made the identity and its federated credential. The workload identity webhook gave the Portal Pods theirAZURE_*variables, and the token exchange worked.Usage report: cannot check the logs database yetwith Kusto's HTTP 403 ("not authorized to read database"). It checked again after 30 seconds and after 1 minute.Viewerrole on the logs database, and no role on the other databases. Kusto lists the role with the principalaadapp=<client ID>;<tenant ID>, the form of the.dropcommand in the docs. The check command of the docs returned that role, and no row for an unknown client ID.Gatewaytable only, found none, because the rows of that cluster had been deleted there.Usage report is off, with the name of that cluster.Gatewaytable, the restarted Pods loggedUsage report reads the AI Gateway usage from Azure Data Explorerwithin a second of their start.Not run:
make docs-check(Hugo), the image scans of CI, and a cluster template deployment withadxMode: create.Compatibility and operational impact
make deployand in the chart. Without theobservability.portalblock, the Portal renders and runs as before.Checklist