ValueMetric supports multiple aggregation types
1. Add support for MIN, MAX, AVG
2. ValueMetric also allow floats now, in addition to long data type.
AnomalyDetection still takes long only. I am not sure if it makes
sense to do anomaly on AVG. I will leave that for later.
3. ValueMetric supports sliced condition change for pushed events.
I don't think it makes sense for pulled events to have sliced condition
changes so leave it for now.
Test: unit test
Change-Id: I8bc510d98ea9b8a6eb16d04ff99dce6b574249cd
diff --git a/cmds/statsd/src/FieldValue.cpp b/cmds/statsd/src/FieldValue.cpp
index f150f07..7b6d29b 100644
--- a/cmds/statsd/src/FieldValue.cpp
+++ b/cmds/statsd/src/FieldValue.cpp
@@ -141,6 +141,9 @@
case FLOAT:
float_value = from.float_value;
break;
+ case DOUBLE:
+ double_value = from.double_value;
+ break;
case STRING:
str_value = from.str_value;
break;
@@ -157,6 +160,8 @@
return std::to_string(long_value) + "[L]";
case FLOAT:
return std::to_string(float_value) + "[F]";
+ case DOUBLE:
+ return std::to_string(double_value) + "[D]";
case STRING:
return str_value + "[S]";
default:
@@ -174,6 +179,8 @@
return long_value == that.long_value;
case FLOAT:
return float_value == that.float_value;
+ case DOUBLE:
+ return double_value == that.double_value;
case STRING:
return str_value == that.str_value;
default:
@@ -190,6 +197,8 @@
return long_value != that.long_value;
case FLOAT:
return float_value != that.float_value;
+ case DOUBLE:
+ return double_value != that.double_value;
case STRING:
return str_value != that.str_value;
default:
@@ -207,6 +216,8 @@
return long_value < that.long_value;
case FLOAT:
return float_value < that.float_value;
+ case DOUBLE:
+ return double_value < that.double_value;
case STRING:
return str_value < that.str_value;
default:
@@ -214,6 +225,142 @@
}
}
+bool Value::operator>(const Value& that) const {
+ if (type != that.getType()) return type > that.getType();
+
+ switch (type) {
+ case INT:
+ return int_value > that.int_value;
+ case LONG:
+ return long_value > that.long_value;
+ case FLOAT:
+ return float_value > that.float_value;
+ case DOUBLE:
+ return double_value > that.double_value;
+ case STRING:
+ return str_value > that.str_value;
+ default:
+ return false;
+ }
+}
+
+bool Value::operator>=(const Value& that) const {
+ if (type != that.getType()) return type >= that.getType();
+
+ switch (type) {
+ case INT:
+ return int_value >= that.int_value;
+ case LONG:
+ return long_value >= that.long_value;
+ case FLOAT:
+ return float_value >= that.float_value;
+ case DOUBLE:
+ return double_value >= that.double_value;
+ case STRING:
+ return str_value >= that.str_value;
+ default:
+ return false;
+ }
+}
+
+Value Value::operator-(const Value& that) const {
+ Value v;
+ if (type != that.type) {
+ ALOGE("Can't operate on different value types, %d, %d", type, that.type);
+ return v;
+ }
+ if (type == STRING) {
+ ALOGE("Can't operate on string value type");
+ return v;
+ }
+
+ switch (type) {
+ case INT:
+ v.setInt(int_value - that.int_value);
+ break;
+ case LONG:
+ v.setLong(long_value - that.long_value);
+ break;
+ case FLOAT:
+ v.setFloat(float_value - that.float_value);
+ break;
+ case DOUBLE:
+ v.setDouble(double_value - that.double_value);
+ break;
+ default:
+ break;
+ }
+ return v;
+}
+
+Value& Value::operator=(const Value& that) {
+ type = that.type;
+ switch (type) {
+ case INT:
+ int_value = that.int_value;
+ break;
+ case LONG:
+ long_value = that.long_value;
+ break;
+ case FLOAT:
+ float_value = that.float_value;
+ break;
+ case DOUBLE:
+ double_value = that.double_value;
+ break;
+ case STRING:
+ str_value = that.str_value;
+ break;
+ default:
+ break;
+ }
+ return *this;
+}
+
+Value& Value::operator+=(const Value& that) {
+ if (type != that.type) {
+ ALOGE("Can't operate on different value types, %d, %d", type, that.type);
+ return *this;
+ }
+ if (type == STRING) {
+ ALOGE("Can't operate on string value type");
+ return *this;
+ }
+
+ switch (type) {
+ case INT:
+ int_value += that.int_value;
+ break;
+ case LONG:
+ long_value += that.long_value;
+ break;
+ case FLOAT:
+ float_value += that.float_value;
+ break;
+ case DOUBLE:
+ double_value += that.double_value;
+ break;
+ default:
+ break;
+ }
+ return *this;
+}
+
+double Value::getDouble() const {
+ switch (type) {
+ case INT:
+ return int_value;
+ case LONG:
+ return long_value;
+ case FLOAT:
+ return float_value;
+ case DOUBLE:
+ return double_value;
+ default:
+ return 0;
+ }
+}
+
bool equalDimensions(const std::vector<Matcher>& dimension_a,
const std::vector<Matcher>& dimension_b) {
bool eq = dimension_a.size() == dimension_b.size();