-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from cliveseldon/custom_metric_fixes
Fix storing of Gauge metrics
- Loading branch information
Showing
5 changed files
with
136 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
engine/src/test/java/io/seldon/engine/grpc/MetricsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.seldon.engine.grpc; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.google.common.util.concurrent.AtomicDouble; | ||
|
||
import io.micrometer.core.instrument.Tag; | ||
import io.seldon.engine.metrics.CustomMetricsManager; | ||
import io.seldon.protos.PredictionProtos.Metric; | ||
import io.seldon.protos.PredictionProtos.Metric.MetricType; | ||
|
||
|
||
public class MetricsTest { | ||
|
||
@Test | ||
public void testGauge() | ||
{ | ||
CustomMetricsManager m = new CustomMetricsManager(); | ||
Iterable<Tag> tags = Arrays.asList(Tag.of("tag1", "tag1value1")); | ||
Metric metric1 = Metric.newBuilder().setKey("key1").setValue(1.0f).setType(MetricType.GAUGE).build(); | ||
AtomicDouble v1 = m.get(tags, metric1); | ||
v1.set(metric1.getValue()); | ||
Metric metric2 = Metric.newBuilder().setKey("key1").setValue(2.0f).setType(MetricType.GAUGE).build(); | ||
AtomicDouble v2 = m.get(tags, metric2); | ||
Assert.assertEquals(1.0D, v2.get(),0.01); | ||
Assert.assertEquals(v1, v2); | ||
Metric metric3 = Metric.newBuilder().setKey("key2").setValue(2.0f).setType(MetricType.GAUGE).build(); | ||
AtomicDouble v3 = m.get(tags, metric3); | ||
Assert.assertNotEquals(v1, v3); | ||
v2.set(metric2.getValue()); | ||
AtomicDouble v4 = m.get(tags, metric1); | ||
Assert.assertEquals(2.0D, v4.get(),0.01); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"meta": { | ||
"metrics": [ | ||
{ | ||
"type": "COUNTER", | ||
"key": "mycounter", | ||
"value": 1.0 | ||
}, | ||
{ | ||
"type": "GAUGE", | ||
"key": "mygauge", | ||
"value": 100.0 | ||
}, | ||
{ | ||
"type": "TIMER", | ||
"key": "mytimer", | ||
"value": 1.0 | ||
} | ||
] | ||
}, | ||
"data": { | ||
"ndarray": [ | ||
[ | ||
1, | ||
2 | ||
] | ||
] | ||
} | ||
} |