-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Describable returning an empty list (#785)
* Fix Describable returning an empty list Signed-off-by: Fabian Stäber <[email protected]> * Fix implementation and add test Signed-off-by: Fabian Stäber <[email protected]>
- Loading branch information
Showing
2 changed files
with
58 additions
and
4 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
47 changes: 47 additions & 0 deletions
47
simpleclient/src/test/java/io/prometheus/client/EmptyDescribableTest.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,47 @@ | ||
package io.prometheus.client; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.*; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class EmptyDescribableTest { | ||
|
||
static class TestCollector extends Collector implements Collector.Describable { | ||
|
||
private final List<MetricFamilySamples> describeResult; | ||
|
||
TestCollector(List<MetricFamilySamples> describeResult) { | ||
this.describeResult = describeResult; | ||
} | ||
|
||
@Override | ||
public List<MetricFamilySamples> collect() { | ||
List<String> labelNames = Arrays.asList("label1", "label2"); | ||
List<String> labelValues1 = Arrays.asList("a", "b"); | ||
List<String> labelValues2 = Arrays.asList("c", "d"); | ||
List<MetricFamilySamples.Sample> samples = new ArrayList<MetricFamilySamples.Sample>(2); | ||
samples.add(new MetricFamilySamples.Sample("my_metric", labelNames, labelValues1, 1.0)); | ||
samples.add(new MetricFamilySamples.Sample("my_metric", labelNames, labelValues2, 2.0)); | ||
MetricFamilySamples mfs = new MetricFamilySamples("my_metric", "", Type.UNKNOWN, "help text", samples); | ||
return Collections.singletonList(mfs); | ||
} | ||
|
||
@Override | ||
public List<MetricFamilySamples> describe() { | ||
return describeResult; | ||
} | ||
} | ||
|
||
@Test | ||
public void testEmptyDescribe() { | ||
CollectorRegistry registry = new CollectorRegistry(); | ||
TestCollector collector = new TestCollector(new ArrayList<Collector.MetricFamilySamples>()); | ||
collector.register(registry); | ||
Set<String> includedNames = new HashSet<String>(Collections.singletonList("my_metric")); | ||
List<Collector.MetricFamilySamples> mfs = Collections.list(registry.filteredMetricFamilySamples(includedNames)); | ||
assertEquals(1, mfs.size()); | ||
assertEquals(2, mfs.get(0).samples.size()); | ||
} | ||
} |