Populate initial base info with unknown state values
Set the current state key to a HashableDimensionKey with -1
(kStateUnknown) for each sliced state atom. Previously, the current
state key was being set to the DEFAULT_DIMENSION_KEY which is an empty
HashableDimensionKey.
Bug: 155487198
Test: make statsd_test && adb sync data && adb shell
data/nativetest/statsd_test/statsd_test
Change-Id: Icaa187ecae599407695d86eec6104d210aa98714
diff --git a/cmds/statsd/src/metrics/MetricProducer.cpp b/cmds/statsd/src/metrics/MetricProducer.cpp
index 2518d85..bb4f03e 100644
--- a/cmds/statsd/src/metrics/MetricProducer.cpp
+++ b/cmds/statsd/src/metrics/MetricProducer.cpp
@@ -293,6 +293,17 @@
}
}
+HashableDimensionKey MetricProducer::getUnknownStateKey() {
+ HashableDimensionKey stateKey;
+ for (auto atom : mSlicedStateAtoms) {
+ FieldValue fieldValue;
+ fieldValue.mField.setTag(atom);
+ fieldValue.mValue.setInt(StateTracker::kStateUnknown);
+ stateKey.addValue(fieldValue);
+ }
+ return stateKey;
+}
+
DropEvent MetricProducer::buildDropEvent(const int64_t dropTimeNs, const BucketDropReason reason) {
DropEvent event;
event.reason = reason;
diff --git a/cmds/statsd/src/metrics/MetricProducer.h b/cmds/statsd/src/metrics/MetricProducer.h
index e86fdf0..fe84739 100644
--- a/cmds/statsd/src/metrics/MetricProducer.h
+++ b/cmds/statsd/src/metrics/MetricProducer.h
@@ -384,6 +384,10 @@
// If no state map exists, keep the original state value.
void mapStateValue(const int32_t atomId, FieldValue* value);
+ // Returns a HashableDimensionKey with unknown state value for each state
+ // atom.
+ HashableDimensionKey getUnknownStateKey();
+
DropEvent buildDropEvent(const int64_t dropTimeNs, const BucketDropReason reason);
// Returns true if the number of drop events in the current bucket has
diff --git a/cmds/statsd/src/metrics/ValueMetricProducer.cpp b/cmds/statsd/src/metrics/ValueMetricProducer.cpp
index f03ce45..130e6f2 100644
--- a/cmds/statsd/src/metrics/ValueMetricProducer.cpp
+++ b/cmds/statsd/src/metrics/ValueMetricProducer.cpp
@@ -767,22 +767,24 @@
bool shouldSkipForPulledMetric = mIsPulled && !mUseDiff
&& mCondition != ConditionState::kTrue;
if (shouldSkipForPushMetric || shouldSkipForPulledMetric) {
- VLOG("ValueMetric skip event because condition is false");
+ VLOG("ValueMetric skip event because condition is false and we are not using diff (for "
+ "pulled metric)");
return;
}
if (hitGuardRailLocked(eventKey)) {
return;
}
+
vector<BaseInfo>& baseInfos = mCurrentBaseInfo[whatKey];
if (baseInfos.size() < mFieldMatchers.size()) {
VLOG("Resizing number of intervals to %d", (int)mFieldMatchers.size());
baseInfos.resize(mFieldMatchers.size());
}
- for (auto baseInfo : baseInfos) {
+ for (BaseInfo& baseInfo : baseInfos) {
if (!baseInfo.hasCurrentState) {
- baseInfo.currentState = DEFAULT_DIMENSION_KEY;
+ baseInfo.currentState = getUnknownStateKey();
baseInfo.hasCurrentState = true;
}
}
@@ -1033,7 +1035,7 @@
} else {
it++;
}
- // TODO: remove mCurrentBaseInfo entries when obsolete
+ // TODO(b/157655103): remove mCurrentBaseInfo entries when obsolete
}
mCurrentBucketIsInvalid = false;