Skip to content

Commit

Permalink
feat: extract and ingest more metrics context (`aggregation temporali…
Browse files Browse the repository at this point in the history
…ty`, `unit` and `monotonicity`) (#136)
  • Loading branch information
wrn14897 committed Dec 4, 2023
1 parent 8c8c476 commit ff38d75
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/grumpy-paws-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperdx/api': minor
'@hyperdx/app': minor
---

feat: extract and ingest more metrics context (aggregation temporality, unit and
monotonicity)
8 changes: 6 additions & 2 deletions docker/ingestor/core.toml
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,12 @@ source = '''
if err == null && structured.event == "metric" {
# TODO: do this at extract_token
.hdx_token = del(structured.fields.__HDX_API_KEY)
.dt = structured.fields.metric_type
filtered_keys = ["metric_type"]
.at = to_int(del(structured.fields.metric_aggregation_temporality)) ?? 0
.dt = del(structured.fields.metric_type)
.im = to_bool(del(structured.fields.metric_is_monotonic)) ?? null
.u = del(structured.fields.metric_unit)
filtered_keys = []
for_each(object(structured.fields) ?? {})-> |key, value| {
if is_integer(value) || is_float(value) {
filtered_keys = push(filtered_keys, key)
Expand Down
18 changes: 17 additions & 1 deletion docker/otel-collector/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ processors:
- key: __HDX_API_KEY
from_context: authorization
action: upsert
# TODO: use transform to attach __HDX_API_KEY attribute to spans/metrics/logs
transform:
error_mode: ignore
metric_statements:
- context: resource
statements:
# map metrics context to resource context (so splunk_hec will capture it)
- set(attributes["metric_aggregation_temporality"], "0")
- set(attributes["metric_unit"], "")
- set(attributes["metric_is_monotonic"], false)
- context: metric
statements:
- set(resource.attributes["metric_aggregation_temporality"],
aggregation_temporality)
- set(resource.attributes["metric_unit"], unit)
- set(resource.attributes["metric_is_monotonic"], is_monotonic)
batch:
memory_limiter:
# 80% of maximum memory up to 2G
Expand Down Expand Up @@ -78,7 +94,7 @@ service:
exporters: [logzio/traces, logging]
metrics:
receivers: [otlp]
processors: [attributes/attachHdxKey, memory_limiter, batch]
processors: [attributes/attachHdxKey, transform, memory_limiter, batch]
exporters: [splunk_hec, logging]
logs:
receivers: [otlp, fluentforward]
Expand Down
5 changes: 4 additions & 1 deletion packages/api/src/clickhouse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,11 @@ const getMetricsTagsUncached = async (teamId: string) => {
const query = SqlString.format(
`
SELECT
format('{} - {}', name, data_type) as name,
any(is_delta) as is_delta,
any(is_monotonic) as is_monotonic,
any(unit) as unit,
data_type,
format('{} - {}', name, data_type) as name,
groupUniqArray(_string_attributes) AS tags
FROM ??
GROUP BY name, data_type
Expand Down
14 changes: 14 additions & 0 deletions packages/api/src/utils/logParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export type JSONBlob = Record<string, any>;

export type KeyPath = string[];

export enum AggregationTemporality {
Delta = 1,
Cumulative = 2,
}

export enum LogType {
Log = 'log',
Metric = 'metric',
Expand Down Expand Up @@ -67,8 +72,11 @@ export type LogStreamModel = KeyValuePairs &
export type MetricModel = {
_string_attributes: Record<string, string>;
data_type: string;
is_delta: boolean;
is_monotonic: boolean;
name: string;
timestamp: number;
unit: string;
value: number;
};

Expand Down Expand Up @@ -207,14 +215,17 @@ export type VectorSpan = {
};

export type VectorMetric = {
at: number; // aggregation temporality
authorization?: string;
b: JSONBlob; // tags
dt: string; // data type
hdx_platform: string;
hdx_token: string;
im: boolean; // is monotonic
n: string; // name
ts: number; // timestamp
tso: number; // observed timestamp
u: string; // unit
v: number; // value
};

Expand Down Expand Up @@ -276,8 +287,11 @@ class VectorMetricParser extends ParsingInterface<VectorMetric> {
return {
_string_attributes: metric.b,
data_type: metric.dt,
is_delta: metric.at === AggregationTemporality.Delta,
is_monotonic: metric.im,
name: metric.n,
timestamp: metric.ts,
unit: metric.u,
value: metric.v,
};
}
Expand Down

0 comments on commit ff38d75

Please sign in to comment.