Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import java.util.List;
import java.util.Map;
Expand All @@ -22,6 +23,7 @@
@Getter
@Setter
@JsonTypeName("prometheus")
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
@JsonIgnoreProperties(ignoreUnknown = true)
public class PrometheusResult implements DataSourceResult {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,30 @@ public void testConstructorWithPrometheusError() throws IOException {
PrometheusResult result = (PrometheusResult) response.getResults().get(dataSourceName);
assertNotNull(result);
}

@Test
public void testPrometheusResultWithTypeLabelInMetric() throws IOException {
// Regression test: metrics containing a label named "type" should not cause
// InvalidTypeIdException during deserialization (GitHub #5684)
String queryId = "query-type-label";
String sessionId = "session-type-label";
String rawResult =
"{\"resultType\":\"vector\",\"result\":[{\"metric\":"
+ "{\"__name__\":\"cpu_usage\",\"type\":\"gauge\",\"instance\":\"localhost:9090\"},"
+ "\"value\":[1625000000,\"0.5\"]}]}";
String dataSourceName = "prom-with-type-label";
String dataSourceType = "prometheus";

ExecuteDirectQueryActionResponse response =
new ExecuteDirectQueryActionResponse(
queryId, rawResult, sessionId, dataSourceName, dataSourceType);

assertEquals(queryId, response.getQueryId());
assertEquals(1, response.getResults().size());
assertInstanceOf(PrometheusResult.class, response.getResults().get(dataSourceName));
PrometheusResult result = (PrometheusResult) response.getResults().get(dataSourceName);
assertNotNull(result.getResult());
assertEquals(1, result.getResult().size());
assertEquals("gauge", result.getResult().get(0).getMetric().get("type"));
}
}