sample_rate
다음에서 지원:
optimization.sample_rate(byteOrString, rateNumerator, rateDenominator)
설명
이 함수는 결정론적 샘플링 전략에 따라 이벤트를 포함할지 여부를 결정합니다. 이 함수는 다음을 반환합니다.
- 입력 값의 일부에 대해
true(rateNumerator/rateDenominator)을 사용하여 이벤트가 샘플에 포함되어야 함을 나타냅니다. false: 이벤트가 샘플에 포함되지 않음을 나타냅니다.
이 함수는 이벤트의 하위 집합만 처리하려는 최적화 시나리오에 유용합니다. 다음과 같습니다.
hash.fingerprint2011(byteOrString) % rateDenominator < rateNumerator
매개변수 데이터 유형
- byteOrString:
BYTE또는STRING으로 평가되는 표현식입니다. - rateNumerator: 'INT'
- rateDenominator: 'INT'
반환 유형
BOOL
코드 샘플
events:
$e.metadata.event_type = "NETWORK_CONNECTION"
$asset_id = $e.principal.asset.asset_id
optimization.sample_rate($e.metadata.id, 1, 5) // Only 1 out of every 5 events
match:
$asset_id over 1h
outcome:
$event_count = count_distinct($e.metadata.id)
// estimate the usage by multiplying by the inverse of the sample rate
$usage_past_hour = sum(5.0 * $e.network.sent_bytes)
condition:
// Requiring a certain number of events after sampling avoids bias (e.g. a
// device with just 1 connection will still show up 20% of the time and
// if we multiply that traffic by 5, we'll get an incorrect estimate)
$e and ($usage_past_hour > 1000000000) and $event_count >= 100