Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/501#discussion_r24328969
--- Diff:
policy/src/main/java/brooklyn/enricher/RollingTimeWindowMeanEnricher.java ---
@@ -103,31 +119,69 @@ public void onEvent(SensorEvent<T> event) {
public void onEvent(SensorEvent<T> event, long eventTime) {
values.addLast(event.getValue());
timestamps.addLast(eventTime);
- pruneValues(eventTime);
- entity.setAttribute((AttributeSensor<Double>)target,
getAverage(eventTime).value); //TODO this can potentially go stale... maybe we
need to timestamp as well?
+ if (eventTime>0) {
+ ConfidenceQualifiedNumber average = getAverage(eventTime, 0);
+
+ if (average.confidence >
getConfig(CONFIDENCE_REQUIRED_TO_PUBLISH)) {
+ // without confidence, we might publish wildly varying
estimates,
+ // causing spurious resizes, so allow it to be configured,
and
+ // by default require a high value
+
+ // TODO would be nice to include timestamp, etc
+ entity.setAttribute((AttributeSensor<Double>)target,
average.value);
+ }
+ }
}
public ConfidenceQualifiedNumber getAverage() {
- return getAverage(System.currentTimeMillis());
+ return getAverage(System.currentTimeMillis(),
getConfig(TIMESTAMP_GRACE_TIME).toMilliseconds());
}
- public ConfidenceQualifiedNumber getAverage(long now) {
- pruneValues(now);
+ public ConfidenceQualifiedNumber getAverage(long fromTimeExact) {
+ return getAverage(fromTimeExact, 0);
+ }
+
+ public ConfidenceQualifiedNumber getAverage(long fromTime, long
graceAllowed) {
if (timestamps.isEmpty()) {
return lastAverage = new
ConfidenceQualifiedNumber(lastAverage.value, 0.0d);
}
+
+ // (previously there was an old comment here, pre-Jul-2014,
--- End diff --
Include a `TODO` in this comment - it's the sort of comment we want to
delete if/when we figure out what the old comment meant, or we're happy with
it. Hence it justifies a TODO because we want to change it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---