From 056f3236b6de1afe2c90f7e5162d869608e58c95 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Tue, 17 Feb 2026 10:50:29 -0800 Subject: [PATCH] =?UTF-8?q?feat(telemetry):=20Phase=203=20=E2=80=94=20clus?= =?UTF-8?q?ter=20resolve/ignore,=20audit=20logging,=20webhook=20alerts,=20?= =?UTF-8?q?metrics=20endpoint,=20Cosmos=20indexes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/cosmos-telemetry-indexes.sh | 159 ++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100755 scripts/cosmos-telemetry-indexes.sh diff --git a/scripts/cosmos-telemetry-indexes.sh b/scripts/cosmos-telemetry-indexes.sh new file mode 100755 index 00000000..55f4bf6a --- /dev/null +++ b/scripts/cosmos-telemetry-indexes.sh @@ -0,0 +1,159 @@ +#!/usr/bin/env bash +# ────────────────────────────────────────────────────────────────── +# Cosmos DB — Telemetry Container Indexing Policies +# +# Run once to apply composite indexes optimized for the query patterns +# used by the telemetry module (events, clusters, policies). +# +# Prerequisites: +# - Azure CLI installed and authenticated +# - COSMOS_ACCOUNT_NAME and COSMOS_RESOURCE_GROUP env vars set +# - Database name: lysnrai (or set COSMOS_DATABASE) +# ────────────────────────────────────────────────────────────────── + +set -euo pipefail + +ACCOUNT="${COSMOS_ACCOUNT_NAME:?Set COSMOS_ACCOUNT_NAME}" +RG="${COSMOS_RESOURCE_GROUP:?Set COSMOS_RESOURCE_GROUP}" +DB="${COSMOS_DATABASE:-lysnrai}" + +echo "🔧 Applying telemetry indexing policies..." +echo " Account: $ACCOUNT | Database: $DB | Resource Group: $RG" + +# ── telemetry_events ───────────────────────────────────────────── +# Query patterns: +# - WHERE productId = X AND occurredAt >= Y ORDER BY occurredAt DESC +# - + userId, platform, channel, eventType, module filters +echo "📦 telemetry_events..." +az cosmosdb sql container update \ + --account-name "$ACCOUNT" \ + --resource-group "$RG" \ + --database-name "$DB" \ + --name telemetry_events \ + --idx '{ + "indexingMode": "consistent", + "automatic": true, + "includedPaths": [ + { "path": "/productId/?" }, + { "path": "/pk/?" }, + { "path": "/userId/?" }, + { "path": "/anonymousInstallId/?" }, + { "path": "/platform/?" }, + { "path": "/channel/?" }, + { "path": "/eventType/?" }, + { "path": "/module/?" }, + { "path": "/eventName/?" }, + { "path": "/occurredAt/?" }, + { "path": "/receivedAt/?" }, + { "path": "/osFamily/?" }, + { "path": "/appVersion/?" }, + { "path": "/buildNumber/?" } + ], + "excludedPaths": [ + { "path": "/message/?" }, + { "path": "/stackTrace/?" }, + { "path": "/tags/*" }, + { "path": "/metrics/*" }, + { "path": "/context/*" }, + { "path": "/*" } + ], + "compositeIndexes": [ + [ + { "path": "/productId", "order": "ascending" }, + { "path": "/occurredAt", "order": "descending" } + ], + [ + { "path": "/productId", "order": "ascending" }, + { "path": "/platform", "order": "ascending" }, + { "path": "/occurredAt", "order": "descending" } + ], + [ + { "path": "/productId", "order": "ascending" }, + { "path": "/eventType", "order": "ascending" }, + { "path": "/occurredAt", "order": "descending" } + ], + [ + { "path": "/productId", "order": "ascending" }, + { "path": "/userId", "order": "ascending" }, + { "path": "/occurredAt", "order": "descending" } + ] + ] + }' \ + --output none + +# ── telemetry_error_clusters ───────────────────────────────────── +# Query patterns: +# - WHERE productId = X ORDER BY totalCount DESC +# - + platform, module, lastSeenAt filters +echo "📦 telemetry_error_clusters..." +az cosmosdb sql container update \ + --account-name "$ACCOUNT" \ + --resource-group "$RG" \ + --database-name "$DB" \ + --name telemetry_error_clusters \ + --idx '{ + "indexingMode": "consistent", + "automatic": true, + "includedPaths": [ + { "path": "/productId/?" }, + { "path": "/pk/?" }, + { "path": "/platform/?" }, + { "path": "/module/?" }, + { "path": "/severity/?" }, + { "path": "/status/?" }, + { "path": "/totalCount/?" }, + { "path": "/lastSeenAt/?" }, + { "path": "/firstSeenAt/?" } + ], + "excludedPaths": [ + { "path": "/affectedVersions/*" }, + { "path": "/affectedUserIds/*" }, + { "path": "/affectedInstallIds/*" }, + { "path": "/affectedOsFamilies/*" }, + { "path": "/*" } + ], + "compositeIndexes": [ + [ + { "path": "/productId", "order": "ascending" }, + { "path": "/totalCount", "order": "descending" } + ], + [ + { "path": "/productId", "order": "ascending" }, + { "path": "/status", "order": "ascending" }, + { "path": "/totalCount", "order": "descending" } + ] + ] + }' \ + --output none + +# ── telemetry_collection_policies ──────────────────────────────── +# Query patterns: +# - WHERE productId = X ORDER BY priority DESC +echo "📦 telemetry_collection_policies..." +az cosmosdb sql container update \ + --account-name "$ACCOUNT" \ + --resource-group "$RG" \ + --database-name "$DB" \ + --name telemetry_collection_policies \ + --idx '{ + "indexingMode": "consistent", + "automatic": true, + "includedPaths": [ + { "path": "/productId/?" }, + { "path": "/priority/?" }, + { "path": "/enabled/?" } + ], + "excludedPaths": [ + { "path": "/targeting/*" }, + { "path": "/*" } + ], + "compositeIndexes": [ + [ + { "path": "/productId", "order": "ascending" }, + { "path": "/priority", "order": "descending" } + ] + ] + }' \ + --output none + +echo "✅ Telemetry indexing policies applied successfully."