Skip to content

Commit

Permalink
atlas: limit LWC subs to time series exprs (#1130)
Browse files Browse the repository at this point in the history
This registry only supports forwarding data for time series.
Ignore other expression types if present.
  • Loading branch information
brharrington committed Apr 3, 2024
1 parent e870f14 commit 62979fd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ void refresh() {
private Subscriptions filterByStep(Subscriptions subs) {
List<Subscription> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public final class Subscription {

private String id;
private String exprType;
private String expression;
private long frequency;

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand All @@ -116,6 +141,6 @@ private int hashCodeOrZero(Object o) {
}

@Override public String toString() {
return "Subscription(" + id + ",[" + expression + "]," + frequency + ")";
return "Subscription(" + id + "," + exprType + ",[" + expression + "]," + frequency + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 62979fd

Please sign in to comment.