Azure Cosmos DB for Apache Cassandra で高度な診断クエリを使用して問題をトラブルシューティングする

適用対象: NoSQL MongoDB Cassandra Gremlin

この記事では、リソース固有のテーブルに送信された診断ログを使用して、Azure Cosmos DB for Cassandra アカウントに関する問題のトラブルシューティングに役立つ、より高度なクエリを記述する方法について説明します。

Azure Diagnostics テーブルの場合、すべてのデータが 1 つのテーブルに書き込まれます。 クエリを実行するカテゴリをユーザーが指定します。 要求のフルテキスト クエリを確認したい場合は、「Azure の診断設定を使用して Azure Cosmos DB データを監視する」で、この機能を有効にする方法を参照してください。

リソース固有テーブルの場合、データはリソースのカテゴリごとに個別のテーブルに書き込まれます。 次の理由から、このモードをお勧めします。

  • データの扱いがはるかに容易である。
  • スキーマが見つけやすい。
  • インジェストの待ち時間とクエリ時間の両方でパフォーマンスが向上する。

前提条件

警告

Cassandra 用 API アカウントの診断設定を作成するときには、[DataPlaneRequests] が未選択のままになっていることを確認してください。 さらに、[送信先] テーブルについては、[Azure 診断] よりもずっと多くのコストを節約できるため、[リソース固有] が選択されていることを確認してください。

注意

フルテキスト診断を有効にすると、返されるクエリには PII データが含められることに注意してください。 この機能では、難読化されたパラメーターのあるクエリのスケルトンをログに記録するだけでなく、パラメーター自体の値をログに記録します。 これは、特定の主キー (または主キーのセット) に対するクエリが、他の主キーに対するクエリよりもはるかに多くの RU を消費しているかどうかを診断するのに役立ちます。

さまざまなシナリオでの Log Analytics クエリ

Azure Cosmos DB 内で Log Analytics を利用する方法について考えられる質問が表示されたバブル ワード マップの画像

RU の消費量

  • 毎秒多くの RU を消費している Cassandra 操作。

    CDBCassandraRequests 
    | where DatabaseName=="azure_comos" and CollectionName=="user" 
    | project TimeGenerated, RequestCharge, OperationName,
    requestType=split(split(PIICommandText,'"')[3], ' ')[0]
    | summarize max(RequestCharge) by bin(TimeGenerated, 10m), tostring(requestType), OperationName;
    
  • 論理パーティション キーに対する操作あたりの RU 消費量の監視。

    CDBPartitionKeyRUConsumption
    | where DatabaseName=="azure_comos" and CollectionName=="user"
    | summarize TotalRequestCharge=sum(todouble(RequestCharge)) by PartitionKey, PartitionKeyRangeId
    | order by TotalRequestCharge;
    
    CDBPartitionKeyRUConsumption
    | where DatabaseName=="azure_comos" and CollectionName=="user"
    | summarize TotalRequestCharge=sum(todouble(RequestCharge)) by OperationName, PartitionKey
    | order by TotalRequestCharge;
    
    CDBPartitionKeyRUConsumption
    | where DatabaseName=="azure_comos" and CollectionName=="user"
    | summarize TotalRequestCharge=sum(todouble(RequestCharge)) by bin(TimeGenerated, 1m), PartitionKey
    | render timechart;
    
  • RU の消費量に影響を与えている上位のクエリはどれか。

    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | where TimeGenerated > ago(24h)
    | project ActivityId, DatabaseName, CollectionName, queryText=split(split(PIICommandText,'"')[3], ' ')[0], RequestCharge, TimeGenerated
    | order by RequestCharge desc;
    
  • 読み書き操作のペイロード サイズのバリエーションに基づく RU 消費量。

    // This query is looking at read operations
    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | project ResponseLength, TimeGenerated, RequestCharge, cassandraOperationName=split(split(PIICommandText,'"')[3], ' ')[0]
    | where cassandraOperationName =="SELECT"
    | summarize maxResponseLength=max(ResponseLength), maxRU=max(RequestCharge) by bin(TimeGenerated, 10m), tostring(cassandraOperationName)
    
    // This query is looking at write operations
    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | project ResponseLength, TimeGenerated, RequestCharge, cassandraOperationName=split(split(PIICommandText,'"')[3], ' ')[0]
    | where cassandraOperationName in ("CREATE", "UPDATE", "INSERT", "DELETE", "DROP")
    | summarize maxResponseLength=max(ResponseLength), maxRU=max(RequestCharge) by bin(TimeGenerated, 10m), tostring(cassandraOperationName)
    
    // Write operations over a time period.
    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | project ResponseLength, TimeGenerated, RequestCharge, cassandraOperationName=split(split(PIICommandText,'"')[3], ' ')[0]
    | where cassandraOperationName in ("CREATE", "UPDATE", "INSERT", "DELETE", "DROP")
    | summarize maxResponseLength=max(ResponseLength), maxRU=max(RequestCharge) by bin(TimeGenerated, 10m), tostring(cassandraOperationName)
    | render timechart;
    
    // Read operations over a time period.
    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | project ResponseLength, TimeGenerated, RequestCharge, cassandraOperationName=split(split(PIICommandText,'"')[3], ' ')[0]
    | where cassandraOperationName =="SELECT"
    | summarize maxResponseLength=max(ResponseLength), maxRU=max(RequestCharge) by bin(TimeGenerated, 10m), tostring(cassandraOperationName)
    | render timechart;
    
  • 論理パーティション別の読み書き操作に基づく RU 消費量。

    CDBPartitionKeyRUConsumption
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | where OperationName in ("Delete", "Read", "Upsert")
    | summarize totalRU=max(RequestCharge) by OperationName, PartitionKeyRangeId
    
  • 物理および論理パーティション別の RU 消費量。

    CDBPartitionKeyRUConsumption
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | summarize totalRequestCharge=sum(RequestCharge) by PartitionKey, PartitionKeyRangeId;
    
  • 高い RU 消費量に至るホット パーティションかどうか。

    CDBPartitionKeyStatistics
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | where  TimeGenerated > now(-8h)
    | summarize StorageUsed = sum(SizeKb) by PartitionKey
    | order by StorageUsed desc
    
  • パーティション キーは RU 消費量にどのように影響しているか。

    let storageUtilizationPerPartitionKey = 
    CDBPartitionKeyStatistics
    | project AccountName=tolower(AccountName), PartitionKey, SizeKb;
    CDBCassandraRequests
    | project AccountName=tolower(AccountName),RequestCharge, ErrorCode, OperationName, ActivityId, DatabaseName, CollectionName, PIICommandText, RegionName
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | join kind=inner storageUtilizationPerPartitionKey  on $left.AccountName==$right.AccountName
    | where ErrorCode != -1 //successful
    | project AccountName, PartitionKey,ErrorCode,RequestCharge,SizeKb, OperationName, ActivityId, DatabaseName, CollectionName, PIICommandText, RegionName;
    

待機時間

  • 時間枠の中で観察されたサーバー側タイムアウト (状態コード - 408) の数。

    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | where ErrorCode in (4608, 4352) //Corresponding code in Cassandra
    | summarize max(DurationMs) by bin(TimeGenerated, 10m), ErrorCode
    | render timechart;
    
  • 指定した時間枠の中でサーバー側の待機時間に急増が観察されるか。

    CDBCassandraRequests
    | where TimeGenerated > now(-6h)
    | DatabaseName=="azure_cosmos" and CollectionName=="user"
    | summarize max(DurationMs) by bin(TimeGenerated, 10m)
    | render timechart;
    
  • スロットリングの対象となっている操作。

    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | project RequestLength, ResponseLength,
    RequestCharge, DurationMs, TimeGenerated, OperationName,
    query=split(split(PIICommandText,'"')[3], ' ')[0]
    | summarize max(DurationMs) by bin(TimeGenerated, 10m), RequestCharge, tostring(query),
    RequestLength, OperationName
    | order by RequestLength, RequestCharge;
    

Throttling

  • アプリケーションで何らかのスロットリングが発生しているか。

    CDBCassandraRequests
    | where RetriedDueToRateLimiting != false and RateLimitingDelayMs > 0;
    
  • 特に 429 を調べて、どのクエリがアプリケーションで、指定された時間のスロットリングを発生させているか。

    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | where ErrorCode==4097 // Corresponding error code in Cassandra
    | project DatabaseName , CollectionName , CassandraCommands=split(split(PIICommandText,'"')[3], ' ')[0] , OperationName, TimeGenerated;
    

次の手順