Skip to content

Commit

Permalink
Metrics from distant past are now discarded
Browse files Browse the repository at this point in the history
  • Loading branch information
EinsamHauer committed Sep 27, 2021
1 parent 1590304 commit d8ef888
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>net.iponweb.disthene</groupId>
<artifactId>disthene</artifactId>
<packaging>jar</packaging>
<version>1.0.10</version>
<version>1.0.11</version>
<name>disthene</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/net/iponweb/disthene/carbon/CarbonServerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class CarbonServerHandler extends ChannelInboundHandlerAdapter {
@SuppressWarnings("UnstableApiUsage")
private static final CharMatcher PRINTABLE_WITHOUT_SPACE = CharMatcher.inRange('\u0021', '\u007e');

private MBassador<DistheneEvent> bus;
private Rollup rollup;
private TenantService tenantService;
private final MBassador<DistheneEvent> bus;
private final Rollup rollup;
private final TenantService tenantService;

public CarbonServerHandler(MBassador<DistheneEvent> bus, Rollup rollup, TenantService tenantService) {
this.bus = bus;
Expand All @@ -39,17 +39,24 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {

try {
final Metric metric = new Metric(in.toString(CharsetUtil.UTF_8).trim(), rollup);
if ((System.currentTimeMillis() / 1000L) - metric.getTimestamp() > 3600) {
logger.warn("Metric is from distant past (older than 1 hour): " + metric);
}
long metricAge = (System.currentTimeMillis() / 1000L) - metric.getTimestamp();

boolean isValid = true;

if (metricAge > 3600) {
if (metricAge > 7200) {
logger.warn("Metric is from distant past (older than 2 hours). Discarding metric: " + metric);
} else {
logger.warn("Metric is from distant past (older than 1 hour): " + metric);
}
}

if (!tenantService.isTenantAllowed(metric.getTenant())) {
isValid = false;
logger.warn("Unauthorized tenant: " + metric.getTenant() + ". Discarding metric: " + metric);
}

//noinspection UnstableApiUsage
if (!PRINTABLE_WITHOUT_SPACE.matchesAllOf(metric.getPath())) {
isValid = false;
logger.warn("Non printable characters in metric, discarding: " + metric + " (" + Hex.encodeHexString(metric.getPath().getBytes()) + ")");
Expand Down

0 comments on commit d8ef888

Please sign in to comment.