Skip to content

Commit

Permalink
Add option to change the data type (from int to float or vice-versa) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
james-bebbington authored Jul 10, 2020
1 parent d2861ad commit 554000d
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 105 deletions.
3 changes: 3 additions & 0 deletions processor/metricstransformprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ const (
// Update updates an existing metric.
Update ConfigAction = "update"

// ToggleScalarDataType changes the data type from int64 to double, or vice-versa
ToggleScalarDataType OperationAction = "toggle_scalar_data_type"

// UpdateLabel applies name changes to label and/or label values.
UpdateLabel OperationAction = "update_label"

Expand Down
26 changes: 26 additions & 0 deletions processor/metricstransformprocessor/metrics_transform_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ func (mtp *metricsTransformProcessor) update(metric *metricspb.Metric, transform
// update label
if op.Action == UpdateLabel {
mtp.updateLabelOp(metric, op)
} else if op.Action == ToggleScalarDataType {
mtp.ToggleScalarDataType(metric)
}
}
}
Expand All @@ -124,3 +126,27 @@ func (mtp *metricsTransformProcessor) updateLabelOp(metric *metricspb.Metric, op
// label value update
}
}

func (mtp *metricsTransformProcessor) ToggleScalarDataType(metric *metricspb.Metric) {
for _, ts := range metric.Timeseries {
for _, dp := range ts.Points {
switch metric.MetricDescriptor.Type {
case metricspb.MetricDescriptor_GAUGE_INT64, metricspb.MetricDescriptor_CUMULATIVE_INT64:
dp.Value = &metricspb.Point_DoubleValue{DoubleValue: float64(dp.GetInt64Value())}
case metricspb.MetricDescriptor_GAUGE_DOUBLE, metricspb.MetricDescriptor_CUMULATIVE_DOUBLE:
dp.Value = &metricspb.Point_Int64Value{Int64Value: int64(dp.GetDoubleValue())}
}
}
}

switch metric.MetricDescriptor.Type {
case metricspb.MetricDescriptor_GAUGE_INT64:
metric.MetricDescriptor.Type = metricspb.MetricDescriptor_GAUGE_DOUBLE
case metricspb.MetricDescriptor_CUMULATIVE_INT64:
metric.MetricDescriptor.Type = metricspb.MetricDescriptor_CUMULATIVE_DOUBLE
case metricspb.MetricDescriptor_GAUGE_DOUBLE:
metric.MetricDescriptor.Type = metricspb.MetricDescriptor_GAUGE_INT64
case metricspb.MetricDescriptor_CUMULATIVE_DOUBLE:
metric.MetricDescriptor.Type = metricspb.MetricDescriptor_CUMULATIVE_INT64
}
}
Loading

0 comments on commit 554000d

Please sign in to comment.