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

Fix type issue for threshold in screenboard rule #169

Merged
merged 4 commits into from
Sep 12, 2018

Conversation

anatolebeuzon
Copy link
Contributor

Because of a type issue, we could not submit thresholds such as 99.9 for rules in the uptime widget.

This PR fixes that.

screen_widgets.go Show resolved Hide resolved
@nyanshak
Copy link
Collaborator

nyanshak commented Sep 7, 2018

I'm having trouble finding any documentation about an "uptime" screen widget, so any testing I've been doing to validate this has been based on the code in the integration tests. Do you have any doc links you could share to make this a bit easier?

@anatolebeuzon
Copy link
Contributor Author

@nyanshak Actually the uptime widget is purposefully undocumented and still a WIP at this point. Sorry about that, missed it in the first PR. I added a warning in the code telling people not to rely too much on it.

@nyanshak
Copy link
Collaborator

nyanshak commented Sep 12, 2018

The reason for using json.Number, at least across many of Datadog's API endpoints, is that it's common for the API to accept (and send) multiple types.

I just tested against the screenboard API to make a screenboard with uptime widget with thresholds:

    {
      ... truncated ...
      "rules": {
        "1": {
          "threshold": "98", // Hmm.. this can be a string
          "color": "red",
          "timeframe": "7 days"
        },
        "0": {
          "threshold": "95.1", // Hmm, this can also be a string
          "color": "green",
          "timeframe": "Month-to-date"
        }
      },
      "type": "uptime"
    }

I'm able to send thresholds as strings (and Datadog subsequently sends them back as strings). Using float64 as the type results in errors somewhat like this:

json: cannot unmarshal string into Go struct field Rule.Threshold of type float64

Looking back, I believe this is originally the reason we started using json.Number rather than float64, as this case is handled properly there.

Besides that issue with the type, I'm happy to merge this.

screen_widgets.go Outdated Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

2 participants