Skip to content

Commit

Permalink
enhancement(ux)!: Use external tagging for metrics serialization (#2231)
Browse files Browse the repository at this point in the history
* enhancement(ux)!: Use external tagging for metrics serialization

Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>

* Update docs

Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>

* Update behavior tests

Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>

* Update metadata and wordings on the metrics page

Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
  • Loading branch information
a-rodin1 committed Apr 7, 2020
1 parent c20f7ec commit febbdfb
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 232 deletions.
48 changes: 19 additions & 29 deletions .meta/data_model/metric.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,14 @@ The metric timestamp, representing when the metric was created/ingested within \
Vector.\
"""

[data_model.metric.schema.type]
type = "struct"
required = true
description = """\
The metric value. The value is an enumeration and will be comprised of \
different attributes depending on the value type.\
"""


[data_model.metric.schema.type.children.counter]
[data_model.metric.schema.counter]
type = "struct"
description = """\
A single value that can _only_ be incremented or reset to zero value, it \
cannot be decremented.\
"""

[data_model.metric.schema.type.children.counter.children.value]
[data_model.metric.schema.counter.children.value]
type = "double"
examples = [2.6, 5.0]
required = true
Expand All @@ -61,30 +52,29 @@ The value to increment the counter by. Can only be positive.\
"""


[data_model.metric.schema.type.children.gauge]
[data_model.metric.schema.gauge]
type = "struct"
description = """\
A gauge represents a point-in-time value that can increase and decrease. \
Vector's internal gauge type represents changes to that value. Gauges should be \
used to track fluctuations in values, like current memory or CPU usage.\
"""

[data_model.metric.schema.type.children.gauge.children.value]
[data_model.metric.schema.gauge.children.value]
type = "double"
examples = [554222.0]
required = true
description = """\
A specific point-in-time value for the gauge.\
"""


[data_model.metric.schema.type.children.set]
[data_model.metric.schema.set]
type = "struct"
description = """\
A set represents a count of unique values, AKA the cardinality.\
"""

[data_model.metric.schema.type.children.set.children.values]
[data_model.metric.schema.set.children.values]
type = "[string]"
examples = [["unique item 1", "unique item 2"]]
required = true
Expand All @@ -93,21 +83,21 @@ The list of unique values.\
"""


[data_model.metric.schema.type.children.distribution]
[data_model.metric.schema.distribution]
type = "struct"
description = """\
A distribution represents a distribution of sampled values.\
"""

[data_model.metric.schema.type.children.distribution.children.values]
[data_model.metric.schema.distribution.children.values]
type = "[double]"
examples = [[12.0, 43.3, 25.2]]
required = true
description = """\
The list of values contained within the distribution.\
"""

[data_model.metric.schema.type.children.distribution.children.sample_rates]
[data_model.metric.schema.distribution.children.sample_rates]
type = "[int]"
examples = [[12, 43, 25]]
required = true
Expand All @@ -116,39 +106,39 @@ The rate at which each individual value was sampled.\
"""


[data_model.metric.schema.type.children.aggregated_histogram]
[data_model.metric.schema.aggregated_histogram]
type = "struct"
description = """\
Also called a "timer". A `aggregated_histogram` samples observations (usually \
things like request durations or response sizes) and counts them in \
configurable buckets. It also provides a sum of all observed values.\
"""

[data_model.metric.schema.type.children.aggregated_histogram.children.buckets]
[data_model.metric.schema.aggregated_histogram.children.buckets]
type = "[double]"
examples = [[1, 2, 5, 10, 25]]
required = true
description = """\
The buckets contained within this histogram.\
"""

[data_model.metric.schema.type.children.aggregated_histogram.children.counts]
[data_model.metric.schema.aggregated_histogram.children.counts]
type = "[int]"
examples = [[1, 5, 25, 2, 5]]
required = true
description = """\
The number of values contained within each bucket.\
"""

[data_model.metric.schema.type.children.aggregated_histogram.children.count]
[data_model.metric.schema.aggregated_histogram.children.count]
type = "int"
examples = [54]
required = true
description = """\
The total number of values contained within the histogram.\
"""

[data_model.metric.schema.type.children.aggregated_histogram.children.sum]
[data_model.metric.schema.aggregated_histogram.children.sum]
type = "double"
examples = [524.0]
required = true
Expand All @@ -157,7 +147,7 @@ The sum of all values contained within the histogram.\
"""


[data_model.metric.schema.type.children.aggregated_summary]
[data_model.metric.schema.aggregated_summary]
type = "struct"
description = """\
Similar to a histogram, a summary samples observations (usually things like \
Expand All @@ -166,31 +156,31 @@ of observations and a sum of all observed values, it calculates configurable \
quantiles over a sliding time window.
"""

[data_model.metric.schema.type.children.aggregated_summary.children.quantiles]
[data_model.metric.schema.aggregated_summary.children.quantiles]
type = "[double]"
examples = [[0.1, 0.5, 0.75, 1.0]]
required = true
description = """\
The quantiles contained within the summary, where 0 ≤ quantile ≤ 1.\
"""

[data_model.metric.schema.type.children.aggregated_summary.children.values]
[data_model.metric.schema.aggregated_summary.children.values]
type = "[double]"
examples = [[2.1, 4.68, 23.02, 120.1]]
required = true
description = """\
The values contained within the summary that align with the `quantiles`.\
"""

[data_model.metric.schema.type.children.aggregated_summary.children.count]
[data_model.metric.schema.aggregated_summary.children.count]
type = "int"
examples = [54]
required = true
description = """\
The total number of values contained within the summary.\
"""

[data_model.metric.schema.type.children.aggregated_summary.children.sum]
[data_model.metric.schema.aggregated_summary.children.sum]
type = "double"
examples = [524.0]
required = true
Expand Down
3 changes: 2 additions & 1 deletion src/event/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Metric {
pub timestamp: Option<DateTime<Utc>>,
pub tags: Option<BTreeMap<String, String>>,
pub kind: MetricKind,
#[serde(flatten)]
pub value: MetricValue,
}

Expand All @@ -20,7 +21,7 @@ pub enum MetricKind {
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, is_enum_variant)]
#[serde(tag = "type", rename_all = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum MetricValue {
Counter {
value: f64,
Expand Down
6 changes: 3 additions & 3 deletions src/sinks/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ mod test {
value: MetricValue::Counter { value: 100.0 },
});
assert_eq!(
r#"{"name":"foos","timestamp":"2018-11-14T08:09:10.000000011Z","tags":{"Key3":"Value3","key1":"value1","key2":"value2"},"kind":"incremental","value":{"type":"counter","value":100.0}}"#,
r#"{"name":"foos","timestamp":"2018-11-14T08:09:10.000000011Z","tags":{"Key3":"Value3","key1":"value1","key2":"value2"},"kind":"incremental","counter":{"value":100.0}}"#,
encode_event(event, &EncodingConfig::from(Encoding::Text)).unwrap()
);
}
Expand All @@ -190,7 +190,7 @@ mod test {
},
});
assert_eq!(
r#"{"name":"users","timestamp":null,"tags":null,"kind":"incremental","value":{"type":"set","values":["bob"]}}"#,
r#"{"name":"users","timestamp":null,"tags":null,"kind":"incremental","set":{"values":["bob"]}}"#,
encode_event(event, &EncodingConfig::from(Encoding::Text)).unwrap()
);
}
Expand All @@ -208,7 +208,7 @@ mod test {
},
});
assert_eq!(
r#"{"name":"glork","timestamp":null,"tags":null,"kind":"incremental","value":{"type":"distribution","values":[10.0],"sample_rates":[1]}}"#,
r#"{"name":"glork","timestamp":null,"tags":null,"kind":"incremental","distribution":{"values":[10.0],"sample_rates":[1]}}"#,
encode_event(event, &EncodingConfig::from(Encoding::Text)).unwrap()
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/topology/unit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,7 @@ mod tests {
name = "foometric"
[tests.input.metric.tags]
tagfoo = "valfoo"
[tests.input.metric.value]
type = "counter"
[tests.input.metric.counter]
value = 100.0
[[tests.outputs]]
Expand Down
6 changes: 2 additions & 4 deletions tests/behavior/transforms/lua_v2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
[tests.input.metric]
name = "example counter"
kind = "absolute"
value.type = "counter"
value.value = 1.0
counter.value = 1.0
[[tests.outputs]]
extract_from = "lua_v2_metric"
[[tests.outputs.conditions]]
Expand Down Expand Up @@ -119,8 +118,7 @@
[tests.input.metric]
name = "example metric"
kind = "absolute"
value.type = "counter"
value.value = 1.0
counter.value = 1.0
[[tests.outputs]]
extract_from = "lua_v2_metric_to_log"
[[tests.outputs.conditions]]
Expand Down
Loading

0 comments on commit febbdfb

Please sign in to comment.