vega / vega

A visualization grammar.

Home Page:https://vega.github.io/vega

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot get property correctly

I075818 opened this issue · comments

Use VIGA edit tool,run the below json, it will get error message "Cannot read properties of undefined (reading ‘attributes’)" .
If the ‘metric.attributes.pod_id’ is replaced with ‘pod_id’, it works.

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "description": "A timeline visualization of the lives of the first five U.S. presidents.",
  "data": [
    {
      "name": "testdata",
      "values": [
        {
  "_index": "metrics-otel-v1-2023.09.06",
  "_type": "_doc",
  "_id": "_YH3aIoBwqxJSF1N_aqW",
  "_version": 1,
  "_score": null,
  "_source": {
    "kind": "SUMMARY",
    "count": 5,
    "flags": 0,
    "description": "POC metrics for outbound request",
    "sum": 7.003,
    "serviceName": "mcs",
    "schemaUrl": "",
    "quantiles": [
      {
        "quantile": 0.5,
        "value": 0
      },
      {
        "quantile": 0.95,
        "value": 0
      }
    ],
    "unit": "",
    "name": "outbound_request_seconds",
    "startTime": "2023-09-06T04:35:22.773Z",
    "quantileValuesCount": 2,
    "time": "2023-09-06T05:29:52.773Z",
    "metric.attributes.pod_id": "p2",
    "resource.attributes.net@host@name": "10.236.136.67",
    "metric.attributes.uri": "https://hello-app-jiedong.c-5c85d6f.kyma.ondemand.com/random",
    "resource.attributes.service@instance@id": "10.236.136.67:9090",
    "resource.attributes.service@name": "mcs",
    "resource.attributes.http@scheme": "http",
    "instrumentationScope.version": "0.82.0",
    "resource.attributes.net@host@port": "9090",
    "instrumentationScope.name": "otelcol/prometheusreceiver",
    "metric.attributes.method": "POST",
    "[metric.attributes.com](http://metric.attributes.com/)_sap_hybris_telemetry_flag": "customer_facing",
    "[metric.attributes.com](http://metric.attributes.com/)_sap_hybris_extensibility_type": "synchronous",
    "metric.attributes.status": "200",
    "metric.attributes.exception": "None",
    "metric.attributes.pod_name": "-",
    "[metric.attributes.com](http://metric.attributes.com/)_sap_hybris_extensibility_point_type": "remove-from-cart"
  },
  "fields": {
    "startTime": [
      "2023-09-06T04:35:22.773Z"
    ],
    "time": [
      "2023-09-06T05:29:52.773Z"
    ]
  },
  "sort": [
    1693978192773,
    2070754
  ]
},
{
  "_index": "metrics-otel-v1-2023.09.06",
  "_type": "_doc",
  "_id": "_4H3aIoBwqxJSF1N_aqW",
  "_version": 1,
  "_score": null,
  "_source": {
    "kind": "SUMMARY",
    "count": 5,
    "flags": 0,
    "description": "POC metrics for outbound request",
    "sum": 5.563,
    "serviceName": "mcs",
    "schemaUrl": "",
    "quantiles": [
      {
        "quantile": 0.5,
        "value": 0
      },
      {
        "quantile": 0.95,
        "value": 0
      }
    ],
    "unit": "",
    "name": "outbound_request_seconds",
    "startTime": "2023-09-06T05:03:22.773Z",
    "quantileValuesCount": 2,
    "time": "2023-09-06T05:29:52.773Z",
    "metric.attributes.pod_id": "p1",
    "resource.attributes.net@host@name": "10.236.136.67",
    "metric.attributes.uri": "https://hello-app-jiedong.c-5c85d6f.kyma.ondemand.com/random",
    "resource.attributes.service@instance@id": "10.236.136.67:9090",
    "resource.attributes.service@name": "mcs",
    "resource.attributes.http@scheme": "http",
    "instrumentationScope.version": "0.82.0",
    "resource.attributes.net@host@port": "9090",
    "instrumentationScope.name": "otelcol/prometheusreceiver",
    "metric.attributes.method": "POST",
    "[metric.attributes.com](http://metric.attributes.com/)_sap_hybris_telemetry_flag": "customer_facing",
    "[metric.attributes.com](http://metric.attributes.com/)_sap_hybris_extensibility_type": "synchronous",
    "metric.attributes.status": "500",
    "metric.attributes.exception": "None",
    "metric.attributes.pod_name": "-",
    "[metric.attributes.com](http://metric.attributes.com/)_sap_hybris_extensibility_point_type": "remove-from-cart"
  },
  "fields": {
    "startTime": [
      "2023-09-06T05:03:22.773Z"
    ],
    "time": [
      "2023-09-06T05:29:52.773Z"
    ]
  },
  "sort": [
    1693978192773,
    1494437
  ],
  "$$_isAnchor": true
}
  ] ,
  "transform":[
    { "type": "filter", "expr": "datum._source.name == 'outbound_request_seconds'"}
    
  ]
},
{"name": "groupbyPod",
  "source":"testdata",
  "transform": [
    {"type": "aggregate",
     "ops":["sum"],
     "fields":["_source.count"],
     "as":["s1"],
    "groupby":["_source.metric.attributes.pod_id"]
    }
  ]}
]
  
}

Thanks for the report. Can you provide a minimal reproducible example that demonstrates the issue?

Hi domoritz,
Please use this json to debug.

{
    "$schema": "https://vega.github.io/schema/vega/v5.json",
    "description": "A timeline visualization of the lives of the first five U.S. presidents.",
    "data": [
        {
            "name": "testdata",
            "values": [
                {
                    "_index": "metrics-otel-v1-2023.09.06",
                    "_type": "_doc",
                    "_id": "_YH3aIoBwqxJSF1N_aqW",
                    "_source": {
                        "kind": "SUMMARY",
                        "count": 5,
                        "flags": 0,
                        "description": "POC metrics for outbound request",
                        "sum": 7.003,
                        "name": "outbound_request_seconds",
                        "startTime": "2023-09-06T04:35:22.773Z",
                        "quantileValuesCount": 2,
                        "time": "2023-09-06T05:29:52.773Z",
                        "metric.attributes.pod_id": "p2"
                    }
                },
                {
                    "_index": "metrics-otel-v1-2023.09.06",
                    "_type": "_doc",
                    "_id": "_4H3aIoBwqxJSF1N_aqW",
                    "_source": {
                        "kind": "SUMMARY",
                        "count": 5,
                        "flags": 0,
                        "description": "POC metrics for outbound request",
                        "sum": 5.563,
                        "name": "outbound_request_seconds",
                        "startTime": "2023-09-06T05:03:22.773Z",
                        "quantileValuesCount": 2,
                        "time": "2023-09-06T05:29:52.773Z",
                        "metric.attributes.pod_id": "p1"
                    }
                }
            ],
            "transform": [
                {
                    "type": "filter",
                    "expr": "datum._source.name == 'outbound_request_seconds'"
                }
            ]
        },
        {
            "name": "groupbyPod",
            "source": "testdata",
            "transform": [
                {
                    "type": "aggregate",
                    "ops": [
                        "sum"
                    ],
                    "fields": [
                        "_source.count"
                    ],
                    "as": [
                        "s1"
                    ],
                    "groupby": [
                        "_source.metric.attributes.pod_id"
                    ]
                }
            ]
        }
    ]
}

There are no marks in your sample spec. Regardless, I think you just need to escape any property names containing . with \\.

e.g. "_source\\.metric\\.attributes\\.pod_id"

Thank you very much!