Skip to content

Commit

Permalink
Enhance range tests and regex and add better default for output valid…
Browse files Browse the repository at this point in the history
…ator (OpenTSDB#2217)

* Enhance range tests and regex and add better default for output validator
  • Loading branch information
eswdd authored Jan 5, 2022
1 parent 8c6a86d commit a82a4f8
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/tsd/GraphHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ final class GraphHandler implements HttpRpc {
private static final boolean IS_WINDOWS =
System.getProperty("os.name", "").contains("Windows");

private static final String RANGE_COMPONENT = "\\\"?-?\\d*\\.?(\\d+)?([eE]-?\\d+)?\\\"?";
private static Pattern RANGE_VALIDATOR = Pattern.compile(
"\\[\\\"?-?\\d+\\.?(\\d+)?([eE]-?\\d+)?\\\"?:\\\"?-?(\\d+\\.?\\d+?)?([eE]-?\\d+)?\\\"?\\]");
"\\["+RANGE_COMPONENT+":"+RANGE_COMPONENT+"]");
private static Pattern LABEL_VALIDATOR = Pattern.compile("[a-zA-z0-9 \\-_]");
private static Pattern KEY_VALIDATOR = Pattern.compile(
"(out|left|top|center|right|horiz|box|bottom)?\\s?");
Expand Down
1 change: 1 addition & 0 deletions src/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ protected void setDefaults() {
default_map.put("tsd.core.storage_exception_handler.enable", "false");
default_map.put("tsd.core.uid.random_metrics", "false");
default_map.put("tsd.core.bulk.allow_out_of_order_timestamps", "false");
default_map.put("tsd.gnuplot.options.allowlist", ";axis x1y2");
default_map.put("tsd.query.filter.expansion_limit", "4096");
default_map.put("tsd.query.skip_unresolved_tagvs", "false");
default_map.put("tsd.query.allow_simultaneous_duplicates", "true");
Expand Down
86 changes: 84 additions & 2 deletions test/tsd/TestGraphHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -65,13 +66,94 @@ public final class TestGraphHandler {
}

@Test
public void setPlotParams() throws Exception {
public void setYRangeParams() throws Exception {
Plot plot = mock(Plot.class);
HttpQuery query = mock(HttpQuery.class);
Map<String, List<String>> params = Maps.newHashMap();
when(query.getQueryString()).thenReturn(params);

params.put("yrange", Lists.newArrayList("[0:1]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:0]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:42]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:-42]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:0.8]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:-0.8]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:42.4]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:-42.4]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:4e4]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:-4e4]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:4e-4]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:-4e-4]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:4.2e4]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[:-4.2e4]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[0:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[-5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[0.5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[-0.5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[10.5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[-10.5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[10e5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[-10e5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[10e-5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[-10e-5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[10.1e-5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[0:42]"));
params.put("yrange", Lists.newArrayList("[-10.1e-5:]"));
GraphHandler.setPlotParams(query, plot);

params.put("yrange", Lists.newArrayList("[33:system('touch /tmp/poc.txt')]"));
Expand Down

0 comments on commit a82a4f8

Please sign in to comment.