Skip to content

Commit

Permalink
Make jvm_info use an Info. UNTYPED -> UNKNOWN.
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Brazil <[email protected]>
  • Loading branch information
brian-brazil committed Jan 18, 2021
1 parent 37fa7fb commit 784db17
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class Collector {
*/
public abstract List<MetricFamilySamples> collect();
public enum Type {
UNTYPED, // XXX This is Unknown in OpenMetrics.
UNKNOWN, // This is untyped in Prometheus text format.

This comment has been minimized.

Copy link
@iggyzap

iggyzap Jul 28, 2021

Nice. This breaks integration with opencensus-java.

This comment has been minimized.

Copy link
@fstab

fstab Jul 29, 2021

Member

As specified in OpenMetrics:

Type specifies the MetricFamily type. Valid values are "unknown", "gauge", "counter", "stateset", "info", "histogram", "gaugehistogram", and "summary".

This comment has been minimized.

Copy link
@iggyzap

iggyzap via email Jul 29, 2021

COUNTER,
GAUGE,
STATE_SET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* </pre>
*/
public class Enumeration extends SimpleCollector<Enumeration.Child> implements Counter.Describable {

private final Set<String> states;

Enumeration(Builder b) {
Expand Down Expand Up @@ -166,7 +166,7 @@ public void state(String s) {
public void state(Enum e) {
state(e.name());
}

/**
* Get the state.
*/
Expand Down
2 changes: 1 addition & 1 deletion simpleclient/src/main/java/io/prometheus/client/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* </pre>
*/
public class Info extends SimpleCollector<Info.Child> implements Counter.Describable {

Info(Builder b) {
super(b);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testLabels() {
labels.labels("b").info("baz", "meh");
assertEquals(1.0, getInfo("labels", "l", "a", "foo", "bar"), .001);
assertEquals(1.0, getInfo("labels", "l", "b", "baz", "meh"), .001);

assertEquals(null, getInfo("nolabels", "l", "a"));
assertEquals(null, getInfo("nolabels", "l", "b"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TextFormat {
* Content-type for Prometheus text version 0.0.4.
*/
public final static String CONTENT_TYPE_004 = "text/plain; version=0.0.4; charset=utf-8";

/**
* Content-type for Openmetrics text version 1.0.0.
*/
Expand All @@ -29,7 +29,7 @@ public static String chooseContentType(String acceptHeader) {
if (acceptHeader == null) {
return CONTENT_TYPE_004;
}

for (String accepts : acceptHeader.split(",")) {
if ("application/openmetrics-text".equals(accepts.split(";")[0].trim())) {
return CONTENT_TYPE_OPENMETRICS_100;
Expand Down Expand Up @@ -193,13 +193,13 @@ public static void writeOpenMetrics100(Writer writer, Enumeration<Collector.Metr
while(mfs.hasMoreElements()) {
Collector.MetricFamilySamples metricFamilySamples = mfs.nextElement();
String name = metricFamilySamples.name;

writer.write("# TYPE ");
writer.write(name);
writer.write(' ');
writer.write(omTypeString(metricFamilySamples.type));
writer.write('\n');

if (!metricFamilySamples.unit.isEmpty()) {
writer.write("# UNIT ");
writer.write(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ public List<MetricFamilySamples> collect() {
ArrayList<MetricFamilySamples.Sample> samples = new ArrayList<Collector.MetricFamilySamples.Sample>();
MetricFamilySamples.Sample sample = new MetricFamilySamples.Sample("nolabels", labelNames, labelValues, 1.0, 1518123006L);
samples.add(sample);
mfs.add(new MetricFamilySamples("nolabels", Collector.Type.UNTYPED, "help", samples));
mfs.add(new MetricFamilySamples("nolabels", Collector.Type.UNKNOWN, "help", samples));
return mfs;
}
}

new CustomCollector().register(registry);
TextFormat.writeOpenMetrics100(writer, registry.metricFamilySamples());
assertEquals("# TYPE nolabels unknown\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public List<MetricFamilySamples> collect() {
ArrayList<MetricFamilySamples.Sample> samples = new ArrayList<Collector.MetricFamilySamples.Sample>();
MetricFamilySamples.Sample sample = new MetricFamilySamples.Sample("nolabels", labelNames, labelValues, 1.0, 1518123456L);
samples.add(sample);
mfs.add(new MetricFamilySamples("nolabels", Collector.Type.UNTYPED, "help", samples));
mfs.add(new MetricFamilySamples("nolabels", Collector.Type.UNKNOWN, "help", samples));
return mfs;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.prometheus.client.hotspot;

import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
import io.prometheus.client.Info;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -26,20 +26,12 @@ public class VersionInfoExports extends Collector {


public List<MetricFamilySamples> collect() {
List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();

GaugeMetricFamily jvmInfo = new GaugeMetricFamily(
"jvm_info",
"JVM version info",
Arrays.asList("version", "vendor", "runtime"));
jvmInfo.addMetric(
Arrays.asList(
System.getProperty("java.runtime.version", "unknown"),
System.getProperty("java.vm.vendor", "unknown"),
System.getProperty("java.runtime.name", "unknown")),
1L);
mfs.add(jvmInfo);

return mfs;
Info i = Info.build().name("jvm").help("VM version info").create();
i.info(
"version", System.getProperty("java.runtime.version", "unknown"),
"vendor", System.getProperty("java.vm.vendor", "unknown"),
"runtime", System.getProperty("java.runtime.name", "unknown")
);
return i.collect();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public void testVersionInfo() {
assertEquals(
1L,
registry.getSampleValue(
"jvm_info", new String[]{"version", "vendor", "runtime"}, new String[]{System.getProperty("java.runtime.version", "unknown"), System.getProperty("java.vm.vendor", "unknown"), System.getProperty("java.runtime.name", "unknown")}),
"jvm_info", new String[]{"runtime", "vendor", "version"},
new String[]{
System.getProperty("java.runtime.name", "unknown"),
System.getProperty("java.vm.vendor", "unknown"),
System.getProperty("java.runtime.version", "unknown")}),
.0000001);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ String requestWithAccept(String accept) throws IOException {
return s.hasNext() ? s.next() : "";
}

@Test
@Test(expected = IllegalArgumentException.class)
public void testRefuseUsingUnbound() throws IOException {
CollectorRegistry registry = new CollectorRegistry();
Expand Down

0 comments on commit 784db17

Please sign in to comment.