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

ChromeUX History API doesn't support NaN values #1970

Closed
dbeneker opened this issue May 8, 2023 · 2 comments · Fixed by #1971
Closed

ChromeUX History API doesn't support NaN values #1970

dbeneker opened this issue May 8, 2023 · 2 comments · Fixed by #1971
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@dbeneker
Copy link

dbeneker commented May 8, 2023

For some domains, the chrome ux history api chromeuxreport.googleapis.com/v1/records:queryHistoryRecord could contain Nan values.

For example:

{
  "record": {
    "key": {
      "origin": "https://nordbeton.shop"
    },
    "metrics": {
      "cumulative_layout_shift": {
        "histogramTimeseries": [
          {
            "start": "0.00",
            "end": "0.10",
            "densities": [
              "NaN",
              "NaN",
              "NaN",
              0.953582763671875,
              0.94488525390625,
              0.93817138671875,

The api client does not support that and returns an error: json: cannot unmarshal string into Go struct field TimeseriesBin.record.metrics.histogramTimeseries.densities of type float64

The Bin struct, used in the daily chrome ux api, does solve this by using a custom UnmarshalJSON() method with gensupport.JSONFloat64.

But in the TimeseriesBin struct is that step missing.

Environment details

  • Programming language: Golang
  • OS: MacOS
  • Language runtime version: go1.20.3 darwin/amd64
  • Package version: v0.120.0

Steps to reproduce

package main

import (
	"context"
	"fmt"

	"google.golang.org/api/chromeuxreport/v1"
	"google.golang.org/api/option"
)

func main() {
	s, err := chromeuxreport.NewService(
		context.Background(),
		option.WithAPIKey("API-KEY"))
	if err != nil {
		panic(err)
	}
	req := &chromeuxreport.QueryHistoryRequest{
		Origin: "https://nordbeton.shop",
	}
	res, err := s.Records.QueryHistoryRecord(req).Do()
	if err != nil {
                // returns
                // json: cannot unmarshal string into Go struct field TimeseriesBin.record.metrics.histogramTimeseries.densities of type float64
		panic(err)
	}
	fmt.Println(res)
}
@dbeneker dbeneker added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels May 8, 2023
@codyoss
Copy link
Member

codyoss commented May 8, 2023

This seems like a reasonable feature request to me. I will try to get a patch out today if possible to be included in our next release

codyoss added a commit to codyoss/google-api-go-client that referenced this issue May 8, 2023
Just like normal floats our arrary of floats should be able to
handle things like "NaN".

Fixes: googleapis#1970
@codyoss
Copy link
Member

codyoss commented May 9, 2023

Release should be out in the next hour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants