WHERE 명령어

WHERE 명령어

where 명령어는 검색 결과를 필터링해요. 지정한 조건에 맞는 결과만 반환해요.

출처: 문서

본문

where 명령어는 검색 결과를 필터링해요. 지정한 조건과 일치하는 결과만 반환해요.

구문 (Syntax)

where 명령어의 구문은 다음과 같아요:

where <boolean-expression>

매개변수 (Parameters)

where 명령어는 다음 매개변수를 지원해요.

매개변수 필수/선택 설명
<boolean-expression> 필수 결과를 필터링하는 데 사용하는 조건이에요. 이 조건이 true로 평가되는 행만 반환돼요.

예제 1: 심각도 수준으로 필터링하기

다음 쿼리는 INFO보다 높은 심각도 수준(severityNumber > 9)을 가진 모든 로그 항목을 찾아, 일상적인 로그를 걸러내고 경고와 오류에 집중해요:

source=otellogs
| where severityNumber > 9
| sort severityNumber, `resource.attributes.service.name`
| fields severityText, severityNumber, `resource.attributes.service.name`

쿼리는 다음과 같은 결과를 반환해요:

severityText | severityNumber | resource.attributes.service.name
WARN | 13 | frontend-proxy
WARN | 13 | frontend-proxy
WARN | 13 | product-catalog
WARN | 13 | product-catalog
ERROR | 17 | checkout
ERROR | 17 | checkout
ERROR | 17 | frontend-proxy
ERROR | 17 | payment
ERROR | 17 | payment
ERROR | 17 | product-catalog
ERROR | 17 | recommendation

예제 2: 결합 기준으로 필터링하기

다음 쿼리는 장애 조사 중에 심각도와 서비스 이름 조건을 AND로 결합해 특정 서비스의 오류로 범위를 좁혀요:

source=otellogs
| where severityNumber >= 17 AND `resource.attributes.service.name` = 'payment'
| fields severityText, severityNumber, `resource.attributes.service.name`

쿼리는 다음과 같은 결과를 반환해요:

severityText | severityNumber | resource.attributes.service.name
ERROR | 17 | payment
ERROR | 17 | payment

예제 3: 여러 가능한 값으로 필터링하기

다음 쿼리는 OR를 사용해 두 조건 중 하나라도 일치하는 모든 경고와 오류를 가져와요:

source=otellogs
| where severityText = 'WARN' or severityText = 'ERROR'
| fields severityText, `resource.attributes.service.name`, body
| head 5

쿼리는 다음과 같은 결과를 반환해요:

severityText | resource.attributes.service.name | body
WARN | product-catalog | Slow query detected: SELECT * FROM products WHERE category = 'electronics' took 3200ms
ERROR | payment | Payment failed: connection timeout to payment gateway after 30000ms
ERROR | checkout | NullPointerException in CheckoutService.placeOrder at line 142
ERROR | payment | Out of memory: Java heap space - shutting down pod payment-6f8d4b-ht7q3
WARN | product-catalog | Connection pool 80% utilized on database replica db-replica-02

예제 4: 텍스트 패턴으로 필터링하기

LIKE 연산자는 와일드카드를 사용해 문자열 필드에 대한 패턴 매칭을 가능하게 해요.

접두 패턴으로 매칭하기

다음 쿼리는 퍼센트 기호(%)를 사용해 frontend로 시작하는 모든 서비스를 찾아요:

source=otellogs
| where LIKE(`resource.attributes.service.name`, 'frontend%')
| fields severityText, `resource.attributes.service.name`, body
| head 3

와일드카드 패턴으로 매칭하기

다음 쿼리는 이름에 product를 포함하는 서비스의 모든 로그를 찾아요:

source=otellogs
| where LIKE(`resource.attributes.service.name`, '%product%')
| fields severityText, `resource.attributes.service.name`, body
| head 3

쿼리는 다음과 같은 결과를 반환해요:

severityText | resource.attributes.service.name | body
WARN | product-catalog | Slow query detected: SELECT * FROM products WHERE category = 'electronics' took 3200ms
WARN | product-catalog | Connection pool 80% utilized on database replica db-replica-02
DEBUG | product-catalog | gRPC call /ProductCatalogService/GetProduct completed in 12ms

예제 5: 특정 값을 제외해 필터링하기

다음 쿼리는 NOT 연산자를 사용해 일상적인 정보(informational) 및 디버그 로그를 제외하고, 주의가 필요한 경고와 오류에 집중해요:

source=otellogs
| where NOT severityText IN ('INFO', 'DEBUG')
| sort severityNumber, `resource.attributes.service.name`
| fields severityText, `resource.attributes.service.name`, body
| head 4

쿼리는 다음과 같은 결과를 반환해요:

severityText | resource.attributes.service.name | body
WARN | frontend-proxy | SSL certificate for api.example.com expires in 14 days
WARN | frontend-proxy | Rate limit threshold reached: 450/500 requests per minute for API key ending in ...abc789
WARN | product-catalog | Slow query detected: SELECT * FROM products WHERE category = 'electronics' took 3200ms
WARN | product-catalog | Connection pool 80% utilized on database replica db-replica-02

예제 6: 값 목록을 사용해 필터링하기

다음 쿼리는 IN 연산자를 사용해 여러 심각도 수준을 한 번에 매칭해, 장애 대응을 위해 모든 오류와 경고를 가져와요:

source=otellogs
| where severityText IN ('ERROR', 'WARN')
| sort severityNumber, `resource.attributes.service.name`
| fields severityText, `resource.attributes.service.name`, body

쿼리는 다음과 같은 결과를 반환해요:

severityText | resource.attributes.service.name | body
WARN | frontend-proxy | SSL certificate for api.example.com expires in 14 days
WARN | frontend-proxy | Rate limit threshold reached: 450/500 requests per minute for API key ending in ...abc789
WARN | product-catalog | Slow query detected: SELECT * FROM products WHERE category = 'electronics' took 3200ms
WARN | product-catalog | Connection pool 80% utilized on database replica db-replica-02
ERROR | checkout | NullPointerException in CheckoutService.placeOrder at line 142
ERROR | checkout | Kafka producer delivery failed: message too large for topic order-events (max 1048576 bytes)
ERROR | frontend-proxy | [2024-02-01T09:20:00.456Z] "POST /api/checkout HTTP/1.1" 503 - 0 30000 checkout-8d4f7b-mk2p9
ERROR | payment | Payment failed: connection timeout to payment gateway after 30000ms
ERROR | payment | Out of memory: Java heap space - shutting down pod payment-6f8d4b-ht7q3
ERROR | product-catalog | Database primary node unreachable: connection refused to db-primary-01:5432
ERROR | recommendation | Failed to process recommendation request: invalid product ID from 203.0.113.50

예제 7: 데이터가 누락된 레코드 필터링하기

다음 쿼리는 계측 스코프(scope) 메타데이터를 가진 로그를 찾아요:

source=otellogs
| where NOT ISNULL(instrumentationScope.name)
| fields severityText, instrumentationScope.name

쿼리는 다음과 같은 결과를 반환해요:

severityText | instrumentationScope.name
INFO | @opentelemetry/instrumentation-http
INFO | Microsoft.Extensions.Hosting
WARN | go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc
ERROR | @opentelemetry/instrumentation-http

예제 8: 그룹화된 조건으로 필터링하기

다음 쿼리는 괄호를 사용해 평가 순서를 제어하며 심각도 조건과 서비스 필터를 결합해 특정 서비스의 오류를 조사해요:

source=otellogs
| where (severityText = 'ERROR' OR severityText = 'WARN') AND `resource.attributes.service.name` = 'payment'
| sort severityNumber
| fields severityText, `resource.attributes.service.name`, body

쿼리는 다음과 같은 결과를 반환해요:

severityText | resource.attributes.service.name | body
ERROR | payment | Payment failed: connection timeout to payment gateway after 30000ms
ERROR | payment | Out of memory: Java heap space - shutting down pod payment-6f8d4b-ht7q3

더 알아보기 (Learn more)