Azure Cosmos DB for Apache Cassandra를 사용하여 고급 진단 쿼리 문제 해결

적용 대상: NoSQL MongoDB Cassandra Gremlin

이 문서에서는 리소스 관련 테이블로 전송된 진단 로그를 사용하여 Azure Cosmos DB for Cassandra 계정 관련 문제 해결에 도움이 되는 고급 쿼리를 작성하는 방법을 설명합니다.

Azure Diagnostics 테이블의 경우 모든 데이터가 하나의 단일 테이블에 기록됩니다. 사용자는 쿼리할 범주를 지정합니다. 요청의 전체 텍스트 쿼리를 보려면 Azure에서 진단 설정을 사용하여 Azure Cosmos DB 데이터 모니터링을 참조하여 이 기능을 사용하는 방법을 알아봅니다.

리소스별 테이블의 경우 데이터는 리소스의 각 범주에 대한 개별 테이블에 기록됩니다. 다음과 같은 이유로 이 모드를 권장합니다.

  • 데이터 작업을 훨씬 쉽게 만듭니다.
  • 스키마의 더 나은 검색 가능성을 제공합니다.
  • 수집 대기 시간과 쿼리 시간 모두에서 성능이 향상됩니다.

필수 조건

Warning

API for Cassandra 계정에 대한 진단 설정을 만들 때 "DataPlaneRequests"가 선택되지 않은 상태로 유지되는지 확인합니다. 또한 대상 테이블의 경우 "Azure 진단"에 비해 상당한 비용 절감을 제공하므로 "리소스별"이 선택되었는지 확인합니다.

참고 항목

전체 텍스트 진단을 사용하도록 설정하면 반환된 쿼리에 PII 데이터가 포함됩니다. 이 기능은 난독 처리된 매개 변수를 사용하여 쿼리의 기본 구조를 기록할 뿐만 아니라 매개 변수 자체의 값도 기록합니다. 이는 특정 기본 키(또는 기본 키 세트)의 쿼리가 다른 기본 키에 대한 쿼리보다 훨씬 더 많은 RU를 사용하는지 여부를 진단하는 데 도움이 될 수 있습니다.

다양한 시나리오를 사용하는 Log Analytics 쿼리

Image of a bubble word map with possible questions on how to leverage Log Analytics within Azure Cosmos DB

RU 사용량

  • 높은 RU/s를 사용하는 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;
    

제한

  • 애플리케이션에 제한이 있나요?

    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;
    

다음 단계