Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #563 - Added update of sensision metrics upon broadcast/fusion of estimators #566

Merged
merged 2 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion warp10/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies {
//
compile project(':crypto')
compile project(':token')
compile 'io.warp10:sensision:1.0.19'
compile 'io.warp10:sensision:1.0.20'

compile 'joda-time:joda-time:2.2'
compile 'org.apache.commons:commons-lang3:3.6'
Expand Down
115 changes: 69 additions & 46 deletions warp10/src/main/java/io/warp10/continuum/ThrottlingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -917,54 +918,63 @@ public boolean accept(File d, String name) {
TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());

if (System.currentTimeMillis() - now > rampup) {
for (Map.Entry<String, HyperLogLogPlus> keyAndHllp: producerHLLPEstimators.entrySet()) {
String key = keyAndHllp.getKey();
HyperLogLogPlus hllp = keyAndHllp.getValue();

if (null == hllp) {
continue;
}

if (hllp.hasExpired()) {
continue;
}

try {
byte[] bytes = hllp.toBytes();
String encoded = new String(OrderPreservingBase64.encode(bytes), StandardCharsets.US_ASCII);
Map<String,String> labels = new HashMap<String, String>();
labels.put(SensisionConstants.SENSISION_LABEL_PRODUCER, key);
Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT, labels, hllp.cardinality());
Sensision.event(0L, null, null, null, SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_ESTIMATOR, labels, encoded);
broadcastEstimator(bytes);
} catch (IOException ioe) {
// Ignore exception
try {
for (Map.Entry<String, HyperLogLogPlus> keyAndHllp: producerHLLPEstimators.entrySet()) {
String key = keyAndHllp.getKey();
HyperLogLogPlus hllp = keyAndHllp.getValue();

if (null == hllp) {
continue;
}

if (hllp.hasExpired()) {
Map<String,String> labels = new HashMap<String, String>();
labels.put(SensisionConstants.SENSISION_LABEL_PRODUCER, key);
Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT, labels, 0, 24 * 3600 * 1000L);
continue;
}

try {
byte[] bytes = hllp.toBytes();
String encoded = new String(OrderPreservingBase64.encode(bytes), StandardCharsets.US_ASCII);
Map<String,String> labels = new HashMap<String, String>();
labels.put(SensisionConstants.SENSISION_LABEL_PRODUCER, key);
Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT, labels, hllp.cardinality());
Sensision.event(0L, null, null, null, SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_ESTIMATOR, labels, encoded);
broadcastEstimator(bytes);
} catch (IOException ioe) {
// Ignore exception
}
}
}

for (Map.Entry<String, HyperLogLogPlus> keyAndHllp: applicationHLLPEstimators.entrySet()) {
String key = keyAndHllp.getKey();
HyperLogLogPlus hllp = keyAndHllp.getValue();

if (null == hllp) {
continue;
}

if (hllp.hasExpired()) {
continue;
}

try {
byte[] bytes = hllp.toBytes();
String encoded = new String(OrderPreservingBase64.encode(bytes), StandardCharsets.US_ASCII);
Map<String,String> labels = new HashMap<String, String>();
labels.put(SensisionConstants.SENSISION_LABEL_APPLICATION, key);
Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT_PER_APP, labels, hllp.cardinality());
Sensision.event(0L, null, null, null, SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_ESTIMATOR_PER_APP, labels, encoded);
broadcastEstimator(bytes);
} catch (IOException ioe) {
// Ignore exception
}
for (Map.Entry<String, HyperLogLogPlus> keyAndHllp: applicationHLLPEstimators.entrySet()) {
String key = keyAndHllp.getKey();
HyperLogLogPlus hllp = keyAndHllp.getValue();

if (null == hllp) {
continue;
}

if (hllp.hasExpired()) {
Map<String,String> labels = new HashMap<String, String>();
labels.put(SensisionConstants.SENSISION_LABEL_APPLICATION, key);
Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT_PER_APP, labels, 0L, 24 * 3600 * 1000L);
continue;
}

try {
byte[] bytes = hllp.toBytes();
String encoded = new String(OrderPreservingBase64.encode(bytes), StandardCharsets.US_ASCII);
Map<String,String> labels = new HashMap<String, String>();
labels.put(SensisionConstants.SENSISION_LABEL_APPLICATION, key);
Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT_PER_APP, labels, hllp.cardinality());
Sensision.event(0L, null, null, null, SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_ESTIMATOR_PER_APP, labels, encoded);
broadcastEstimator(bytes);
} catch (IOException ioe) {
// Ignore exception
}
}
} catch (ConcurrentModificationException cme) {
}
}

Expand Down Expand Up @@ -1052,8 +1062,14 @@ public static void fuse(HyperLogLogPlus hllp) throws Exception {
synchronized(applicationHLLPEstimators) {
applicationHLLPEstimators.put(hllp.getKey().substring(1), hllp);
}
Map<String,String> labels = new HashMap<String,String>(1);
labels.put(SensisionConstants.SENSISION_LABEL_APPLICATION, hllp.getKey().substring(1));
Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT_PER_APP, labels, hllp.cardinality());
} else {
old.fuse(hllp);
Map<String,String> labels = new HashMap<String,String>(1);
labels.put(SensisionConstants.SENSISION_LABEL_APPLICATION, old.getKey().substring(1));
Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT_PER_APP, labels, old.cardinality());
}
} else {
HyperLogLogPlus old = producerHLLPEstimators.get(hllp.getKey());
Expand All @@ -1071,8 +1087,15 @@ public static void fuse(HyperLogLogPlus hllp) throws Exception {
synchronized(producerHLLPEstimators) {
producerHLLPEstimators.put(hllp.getKey(), hllp);
}

Map<String,String> labels = new HashMap<String,String>(1);
labels.put(SensisionConstants.SENSISION_LABEL_PRODUCER, hllp.getKey());
Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT, labels, hllp.cardinality());
} else {
old.fuse(hllp);
Map<String,String> labels = new HashMap<String,String>(1);
labels.put(SensisionConstants.SENSISION_LABEL_PRODUCER, old.getKey());
Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT, labels, old.cardinality());
}
}
}
Expand Down