diff --git a/spectator-reg-atlas/src/main/java/com/netflix/spectator/atlas/SubscriptionManager.java b/spectator-reg-atlas/src/main/java/com/netflix/spectator/atlas/SubscriptionManager.java index 52a70308e..e43ca83bf 100644 --- a/spectator-reg-atlas/src/main/java/com/netflix/spectator/atlas/SubscriptionManager.java +++ b/spectator-reg-atlas/src/main/java/com/netflix/spectator/atlas/SubscriptionManager.java @@ -112,10 +112,10 @@ void refresh() { private Subscriptions filterByStep(Subscriptions subs) { List filtered = new ArrayList<>(subs.getExpressions().size()); for (Subscription sub : subs.getExpressions()) { - if (isSupportedFrequency(sub.getFrequency())) { + if (sub.isTimeSeries() && isSupportedFrequency(sub.getFrequency())) { filtered.add(sub); } else { - LOGGER.trace("ignored subscription with invalid frequency: {}", sub); + LOGGER.trace("ignored subscription with unsupported type or invalid step: {}", sub); } } return new Subscriptions().withExpressions(filtered); diff --git a/spectator-reg-atlas/src/main/java/com/netflix/spectator/atlas/impl/Subscription.java b/spectator-reg-atlas/src/main/java/com/netflix/spectator/atlas/impl/Subscription.java index 7e7be50b2..f67bddf6a 100644 --- a/spectator-reg-atlas/src/main/java/com/netflix/spectator/atlas/impl/Subscription.java +++ b/spectator-reg-atlas/src/main/java/com/netflix/spectator/atlas/impl/Subscription.java @@ -24,6 +24,7 @@ public final class Subscription { private String id; + private String exprType; private String expression; private long frequency; @@ -42,6 +43,12 @@ public DataExpr dataExpr() { return expr; } + /** Return true if it is a time series expression. */ + public boolean isTimeSeries() { + // Null is for legacy endpoints that do not indicate the type. + return exprType == null || "TIME_SERIES".equals(exprType); + } + /** Id for a subscription. */ public String getId() { return id; @@ -58,6 +65,22 @@ public Subscription withId(String id) { return this; } + /** Expression type for the subscription. */ + public String getExprType() { + return exprType; + } + + /** Set the expression for the subscription. */ + public void setExprType(String exprType) { + this.exprType = exprType; + } + + /** Set the expression for the subscription. */ + public Subscription withExprType(String exprType) { + setExprType(exprType); + return this; + } + /** Expression for the subscription. */ public String getExpression() { return expression; @@ -97,6 +120,7 @@ public Subscription withFrequency(long frequency) { Subscription that = (Subscription) o; return frequency == that.frequency && equalsOrNull(id, that.id) + && equalsOrNull(exprType, that.exprType) && equalsOrNull(expression, that.expression); } @@ -106,6 +130,7 @@ private boolean equalsOrNull(Object a, Object b) { @Override public int hashCode() { int result = hashCodeOrZero(id); + result = 31 * result + hashCodeOrZero(exprType); result = 31 * result + hashCodeOrZero(expression); result = 31 * result + (int) (frequency ^ (frequency >>> 32)); return result; @@ -116,6 +141,6 @@ private int hashCodeOrZero(Object o) { } @Override public String toString() { - return "Subscription(" + id + ",[" + expression + "]," + frequency + ")"; + return "Subscription(" + id + "," + exprType + ",[" + expression + "]," + frequency + ")"; } } diff --git a/spectator-reg-atlas/src/test/java/com/netflix/spectator/atlas/impl/SubscriptionTest.java b/spectator-reg-atlas/src/test/java/com/netflix/spectator/atlas/impl/SubscriptionTest.java index 2e35b808f..a7284b976 100644 --- a/spectator-reg-atlas/src/test/java/com/netflix/spectator/atlas/impl/SubscriptionTest.java +++ b/spectator-reg-atlas/src/test/java/com/netflix/spectator/atlas/impl/SubscriptionTest.java @@ -42,4 +42,19 @@ public void dataExprInvalid() { Assertions.assertThrows(IllegalArgumentException.class, () -> new Subscription().withExpression(":true").dataExpr()); } + + @Test + public void timeSeries() { + Subscription sub = new Subscription().withExpression(":true,:sum"); + Assertions.assertTrue(sub.isTimeSeries()); + + sub.setExprType("TIME_SERIES"); + Assertions.assertTrue(sub.isTimeSeries()); + + sub.setExprType("EVENTS"); + Assertions.assertFalse(sub.isTimeSeries()); + + sub.setExprType("TRACE_TIME_SERIES"); + Assertions.assertFalse(sub.isTimeSeries()); + } }