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

datadog_screenboard - panic: interface conversion: interface {} is string, not float64 #117

Closed
sudomateo opened this issue Nov 12, 2018 · 24 comments

Comments

@sudomateo
Copy link

sudomateo commented Nov 12, 2018

Terraform Version

$ terraform -v
Terraform v0.11.10
+ provider.datadog v1.5.0

Affected Resource(s)

  • datadog_screenboard

Terraform Configuration Files

resource "datadog_screenboard" "example" {
  title     = "Datadog Terraform Testing"
  read_only = false

  widget {
    type        = "timeseries"
    x           = 25
    y           = 5
    title       = "graph title terraform"
    title_size  = 16
    title_align = "right"
    legend      = true
    legend_size = 16

    time {
      live_span = "1d"
    }

    tile_def {
      viz = "timeseries"

      request {
        q    = "avg:system.cpu.user{*}"
        type = "line"

        style {
          palette = "purple"
          type    = "dashed"
          width   = "thin"
        }
      }

      marker {
        label = "test marker"
        type  = "error dashed"
        value = "y < 6"
      }

      event {
        q = "test event"
      }
    }
  }
}

Panic Output

https://gist.github.com/sudomateo/14662ec6cd8684cef2a8f6d6b9499649

Expected Behavior

The terraform apply command should have created the datadog_screenboard resource successfully.

Actual Behavior

The terraform apply command produced a panic as noted above.

Steps to Reproduce

  1. Create main.tf with the content above.
  2. Run terraform init to download the Datadog provider plugin.
  3. Run terraform plan to verify the plan output.
  4. Run terraform apply to apply the plan. Enter yes when prompted.
  5. Note the crash.

Important Factoids

After testing with previous commits, it seems that this issue was introduced by commit 19ba2e52a2ee8218716157608b40a215c15d798c. However, you'll have to build using commit bd8075f19b50ff62cc391c5238054dc390143eb9 if you want to compile the provider plugin successfully.

Also, even the acceptance tests are failing:

$ pwd
/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/datadog

$ TF_ACC=1 go test -run TestAccDatadogScreenboard_update -v -timeout 120m
=== RUN   TestAccDatadogScreenboard_update
panic: interface conversion: interface {} is string, not float64

goroutine 1931 [running]:
github.com/terraform-providers/terraform-provider-datadog/datadog.setJSONNumberFromDict(0xc0005b6330, 0x19780e4, 0x9, 0xc0000f6120)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_screenboard.go:601 +0x13d
github.com/terraform-providers/terraform-provider-datadog/datadog.setFromDict(0xc0005b6330, 0x19780e4, 0x9, 0x17fc940, 0xc0000f6120)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_screenboard.go:624 +0x24d
github.com/terraform-providers/terraform-provider-datadog/datadog.batchSetFromDict(0xc0005b6330, 0xc000554a38, 0xa, 0xa)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_screenboard.go:644 +0x7e
github.com/terraform-providers/terraform-provider-datadog/datadog.buildTileDef(0x181e300, 0xc000350ba0, 0x1977607)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_screenboard.go:795 +0x1dc
github.com/terraform-providers/terraform-provider-datadog/datadog.buildWidgets(0xc0005554b8, 0x1978162, 0x9, 0x1823ea0)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_screenboard.go:940 +0x882
github.com/terraform-providers/terraform-provider-datadog/datadog.buildScreenboard(0xc000280150, 0xc000555548, 0x102d321, 0x19ba9a8)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_screenboard.go:963 +0x3c3
github.com/terraform-providers/terraform-provider-datadog/datadog.resourceDatadogScreenboardCreate(0xc000280150, 0x1970080, 0xc00063de40, 0x24, 0x21dec60)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_screenboard.go:969 +0x35
github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc0002817a0, 0xc0004140f0, 0xc00047e480, 0x1970080, 0xc00063de40, 0xc0003cc001, 0x43, 0x0)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/helper/schema/resource.go:225 +0x351
github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0xc0002818f0, 0xc0001f61e0, 0xc0004140f0, 0xc00047e480, 0x1, 0x107e533, 0x0)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/helper/schema/provider.go:283 +0x9c
github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform.(*EvalApply).Eval(0xc0003f3e40, 0x1b06360, 0xc0001c3d40, 0x2, 0x2, 0x197355f, 0x4)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform/eval_apply.go:57 +0x226
github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform.EvalRaw(0x1af7500, 0xc0003f3e40, 0x1b06360, 0xc0001c3d40, 0x0, 0x0, 0x0, 0x0)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform/eval.go:53 +0x156
github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform.(*EvalSequence).Eval(0xc000351ba0, 0x1b06360, 0xc0001c3d40, 0x2, 0x2, 0x197355f, 0x4)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform/eval_sequence.go:14 +0x9c
github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform.EvalRaw(0x1af7a40, 0xc000351ba0, 0x1b06360, 0xc0001c3d40, 0x18660c0, 0x2156502, 0x182bf20, 0xc0003b6570)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform/eval.go:53 +0x156
github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform.Eval(0x1af7a40, 0xc000351ba0, 0x1b06360, 0xc0001c3d40, 0xc000351ba0, 0x1af7a40, 0xc000351ba0, 0x19bab48)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform/eval.go:34 +0x4d
github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform.(*Graph).walk.func1(0x19412e0, 0xc00040e000, 0x0, 0x0)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/terraform/graph.go:126 +0xc45
github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/dag.(*Walker).walkVertex(0xc0003702a0, 0x19412e0, 0xc00040e000, 0xc00063d680)
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/dag/walk.go:387 +0x367
created by github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/dag.(*Walker).Update
	/Users/msanabria/go/src/github.com/terraform-providers/terraform-provider-datadog/vendor/github.com/hashicorp/terraform/dag/walk.go:310 +0x986
exit status 2
FAIL	github.com/terraform-providers/terraform-provider-datadog/datadog	1.165s
@ghost ghost added bug crash labels Nov 12, 2018
@sudomateo sudomateo changed the title Cannot create datadog_screenboard from example in the docs datadog_screenboard - panic: setJSONNumberToDict(): is not convertible to float Nov 12, 2018
@sudomateo sudomateo changed the title datadog_screenboard - panic: setJSONNumberToDict(): is not convertible to float datadog_screenboard - panic: interface conversion: interface {} is string, not float64 Nov 12, 2018
@masci masci self-assigned this Nov 12, 2018
@masci
Copy link
Contributor

masci commented Nov 13, 2018

The root cause is fixed locally (bypass the conversion logic that assumes everything is a float) but the fix is taking more time than expected due to recent changes to the client. In particular, the client changed the type for some of the Precision fields on the different structs that support it from string to json.Number, making impossible to encode valid configs like precision: "*". I opened zorkian/go-datadog-api#193 to revert all the fields to the string type but in the meantime zorkian/go-datadog-api#190 was merged and acceptance tests don't pass anymore, opened zorkian/go-datadog-api#192 to discuss the issue.

@masci
Copy link
Contributor

masci commented Nov 13, 2018

Update: zorkian/go-datadog-api#193 was just closed, trying to start a discussion around the type to be used for Precision since current state is just broken. If anybody wants to chime in, that would help.

@sudomateo
Copy link
Author

@masci Looks like they submitted pull request zorkian/go-datadog-api#194 to address this. I chimed in with a thumbs up but I don't have much else to offer the discussion in terms of golang code at the moment. I'd be more than happy to test though.

masterzen pushed a commit to masterzen/terraform-provider-datadog that referenced this issue Nov 17, 2018
…screenboards

This contains the fixes from PR DataDog#194 and DataDog#195 from
zorkian/go-datadog-api and the necessary changes in the provider.
@masterzen
Copy link

I've pushed to my fork a change to the provider to use zorkian/go-datadog-api#194 and zorkian/go-datadog-api#195.
I checked that it fixes this issue along with #119 and #109.

I won't open a PR here now because the go-datadog-api fixes haven't been merged and my code doesn't contain any test covering the failure.

@sudomateo if you want to try the fix, it is self contained thanks to the vendorization, you just need tomake build once checked out (you'll need to copy the provider in the local directory where you run the terraform command or in ~/.terraform.d/plugins/ if I remember correctly.

@sudomateo
Copy link
Author

sudomateo commented Nov 18, 2018

@masterzen I built your fork and tested it just now. Here's my findings:
Fixed #117
Fixed #119
Fixed #105

@masterzen
Copy link

@sudomateo , I'll double check tomorrow, but the only screenboard I tried got the graphs at the correct coordinates.

Also, I made a mistake, it's supposed to fix #105 not #109.

@sudomateo
Copy link
Author

@masterzen I made a mistake in my testing. I accidentally built your master branch instead of your fix branch. I just tested again and confirmed it fixed #117, #119 and #105. I edited my comment above to reflect this. Thank you for the work!

@masterzen
Copy link

@sudomateo thanks for confirming :)
Now we have to wait for zorkian/go-datadog-api#194 and zorkian/go-datadog-api#195 to be merged.

@masci
Copy link
Contributor

masci commented Nov 19, 2018

Thanks everybody for the help on this.
I think zorkian/go-datadog-api#195 needs a similar fix as seen on zorkian/go-datadog-api#194 to work properly, I don't know how popular is setting width: 100% for a screenboard but that wouldn't work with the patch as it is.

@masci
Copy link
Contributor

masci commented Nov 30, 2018

Can anybody confirm this is fixed with 1.6.0? Thanks

@masterzen
Copy link

@masci it fixes the problem for me.

@sudomateo
Copy link
Author

@masci Confirmed this is fixed using the above example with the following versions:

$ terraform -v
Terraform v0.11.10
+ provider.datadog v1.6.0

@masci
Copy link
Contributor

masci commented Dec 1, 2018

Thanks guys!
Closing...

@masci masci closed this as completed Dec 1, 2018
@gphat
Copy link

gphat commented Dec 1, 2018

Hey @masci, I'm getting this error now in 1.6.0 for Screenboard.height:

json: cannot unmarshal string into Go struct field Screenboard.height of type int

versions:

$ terraform -v
Terraform v0.11.10
+ provider.datadog v1.6.0

@masci
Copy link
Contributor

masci commented Dec 1, 2018

@gphat arf, sorry about that... What value do you have for height, mind to share a snippet of HCL to reproduce? I added both strings and ints to the tests https://github.com/terraform-providers/terraform-provider-datadog/blob/master/datadog/resource_datadog_screenboard_test.go#L18. There's a known issue for values like "100%" but shouldn't be the case for height.

@gphat
Copy link

gphat commented Dec 2, 2018

From doing some digging -- this is happening on state retrieval, so the HCL isn't what I need to show -- it look as though I have a "height": "", in my response. Looks like I didn't specify a height and am entrusting Datadog to do the right thing? :)

@masci
Copy link
Contributor

masci commented Dec 2, 2018

Not sure I follow... I can't make the API send me back "height": "", when I set height to zero, it's just missing from the response payload when I subsequently retrieve the screenboard.

@gphat
Copy link

gphat commented Dec 2, 2018

Exciting! It looks like I skipped 0.15. The dashboard in question was made with 0.14. I will try blowing it away and recreating...

@gphat
Copy link

gphat commented Dec 2, 2018

Yeah, it seems if I jump from 0.14 to 0.16 I have to delete the board, state rm it from my state file then re-create the dashboard. No reason to open this, but others may find this report helpful.

@cp3hu
Copy link

cp3hu commented Dec 3, 2018

Hi @masci , do you know how i can fix the error that i get in 1.6.0
json: cannot unmarshal number into Go struct field Params.count of type string
I'm actually trying to import a screenboard.

Terraform v0.11.10
+ provider.datadog v1.6.0

@masci
Copy link
Contributor

masci commented Dec 3, 2018

@cp3hu is this also happening with older versions or is it a regression in 1.6?

@cp3hu
Copy link

cp3hu commented Dec 3, 2018

In older version ( 1.4.0) i had a cast error which is fixed by the latest release json: cannot unmarshal number into Go struct field Screenboard.height of type string

@masci
Copy link
Contributor

masci commented Dec 3, 2018

@cp3hu ok it seems fixing the height problem exposed this one, so it's new. Do you mind opening a new issue to track this specifically?

@cp3hu
Copy link

cp3hu commented Dec 4, 2018

Issue created and linked

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

No branches or pull requests

5 participants