Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialization of metrics from OTLP output broken #2434

Open
scottgerring opened this issue Dec 16, 2024 · 0 comments
Open

Deserialization of metrics from OTLP output broken #2434

scottgerring opened this issue Dec 16, 2024 · 0 comments

Comments

@scottgerring
Copy link
Contributor

Identified during #2432. Given this code:

    async fn test_roundtrip_example_data() -> Result<()> {
        let metrics_in = include_str!("../expected/metrics/test_u64_counter_meter.json");
        let metrics: MetricsData = serde_json::from_str(metrics_in)?;
        let metrics_out = serde_json::to_string(&metrics)?;

        println!("{:}", metrics_out);

        let metrics_in_json: Value = serde_json::from_str(metrics_in)?;
        let metrics_out_json: Value = serde_json::from_str(&metrics_out)?;

        assert_eq!(metrics_in_json, metrics_out_json);

        Ok(())
    }

And some sample data:

{
  "resourceMetrics": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "stringValue": "metrics-integration-test"
            }
          }
        ]
      },
      "scopeMetrics": [
        {
          "scope": {
            "name": "test_u64_counter_meter"
          },
          "metrics": [
            {
              "name": "counter_u64",
              "sum": {
                "dataPoints": [
                  {
                    "attributes": [
                      {
                        "key": "mykey1",
                        "value": {
                          "stringValue": "myvalue1"
                        }
                      },
                      {
                        "key": "mykey2",
                        "value": {
                          "stringValue": "myvalue2"
                        }
                      }
                    ],
                    "startTimeUnixNano": "1734255506254812000",
                    "timeUnixNano": "1734255533415552000",
                    "asInt": "10"
                  }
                ],
                "aggregationTemporality": 2,
                "isMonotonic": true
              }
            }
          ]
        }
      ]
    }
  ]
}

The assertion fails:

  left: Object {"resourceMetrics": Array [Object {"resource": Object {"attributes": Array [Object {"key": String("service.name"), "value": Object {"stringValue": String("metrics-integration-test")}}]}, "scopeMetrics": Array [Object {"metrics": Array [Object {"name": String("counter_u64"), "sum": Object {"aggregationTemporality": Number(2), "dataPoints": Array [Object {"asInt": String("10"), "attributes": Array [Object {"key": String("mykey1"), "value": Object {"stringValue": String("myvalue1")}}, Object {"key": String("mykey2"), "value": Object {"stringValue": String("myvalue2")}}], "startTimeUnixNano": String("1734255506254812000"), "timeUnixNano": String("1734255533415552000")}], "isMonotonic": Bool(true)}}], "scope": Object {"name": String("test_u64_counter_meter")}}]}]}
 right: Object {"resourceMetrics": Array [Object {"resource": Object {"attributes": Array [Object {"key": String("service.name"), "value": Object {"stringValue": String("metrics-integration-test")}}], "droppedAttributesCount": Number(0)}, "schemaUrl": String(""), "scopeMetrics": Array [Object {"metrics": Array [Object {"description": String(""), "metadata": Array [], "name": String("counter_u64"), "sum": Object {"aggregationTemporality": Number(2), "dataPoints": Array [Object {"attributes": Array [Object {"key": String("mykey1"), "value": Object {"stringValue": String("myvalue1")}}, Object {"key": String("mykey2"), "value": Object {"stringValue": String("myvalue2")}}], "exemplars": Array [], "flags": Number(0), "startTimeUnixNano": String("1734255506254812000"), "timeUnixNano": String("1734255533415552000")}], "isMonotonic": Bool(true)}, "unit": String("")}], "schemaUrl": String(""), "scope": Object {"attributes": Array [], "droppedAttributesCount": Number(0), "name": String("test_u64_counter_meter"), "version": String("")}}]}]}

There's a bunch of things that are unimportant, but the asInt in dataPoints goes missing, and this is the metric value itself. Raising a separate issue as this feels like it could be a serde-and-protobuf-can-of-worms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant