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_synthetics_test] Correctly set grpc step request #2309

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions datadog/resource_datadog_synthetics_test_.go
Original file line number Diff line number Diff line change
Expand Up @@ -1565,17 +1565,14 @@ func buildSyntheticsAPITestStruct(d *schema.ResourceData) *datadogV1.SyntheticsA
requests := stepMap["request_definition"].([]interface{})
if len(requests) > 0 && requests[0] != nil {
requestMap := requests[0].(map[string]interface{})
request.SetMethod(requestMap["method"].(string))
request.SetUrl(requestMap["url"].(string))
request.SetBody(requestMap["body"].(string))
if v, ok := requestMap["body_type"].(string); ok && v != "" {
request.SetBodyType(datadogV1.SyntheticsTestRequestBodyType(v))
}
request.SetTimeout(float64(requestMap["timeout"].(int)))
request.SetAllowInsecure(requestMap["allow_insecure"].(bool))
request.SetFollowRedirects(requestMap["follow_redirects"].(bool))
request.SetPersistCookies(requestMap["persist_cookies"].(bool))
request.SetNoSavingResponseBody(requestMap["no_saving_response_body"].(bool))
if stepMap["subtype"] == "http" {
setHTTPStepRequest(requestMap, &request)
}
if stepMap["subtype"] == "grpc" {
setGRPCStepRequest(requestMap, &request)
}
}

request = *completeSyntheticsTestRequest(request, stepMap["request_headers"].(map[string]interface{}), stepMap["request_query"].(map[string]interface{}), stepMap["request_basicauth"].([]interface{}), stepMap["request_client_certificate"].([]interface{}), stepMap["request_proxy"].([]interface{}), map[string]interface{}{})
Expand Down Expand Up @@ -3451,3 +3448,48 @@ func convertStepParamsKey(key string) string {

return key
}

func setHTTPStepRequest(requestMap map[string]interface{}, request *datadogV1.SyntheticsTestRequest) {
request.SetMethod(requestMap["method"].(string))
request.SetUrl(requestMap["url"].(string))
request.SetBody(requestMap["body"].(string))
if v, ok := requestMap["body_type"].(string); ok && v != "" {
request.SetBodyType(datadogV1.SyntheticsTestRequestBodyType(v))
}
request.SetFollowRedirects(requestMap["follow_redirects"].(bool))
request.SetPersistCookies(requestMap["persist_cookies"].(bool))
request.SetNoSavingResponseBody(requestMap["no_saving_response_body"].(bool))
}

func setGRPCStepRequest(requestMap map[string]interface{}, request *datadogV1.SyntheticsTestRequest) {
request.SetCallType(datadogV1.SyntheticsTestCallType(requestMap["call_type"].(string)))
request.SetService(requestMap["service"].(string))
request.SetHost(requestMap["host"].(string))
request.SetPort(int64(requestMap["port"].(int)))
if requestMap["call_type"].(string) == "unary" {
request.SetMessage(requestMap["message"].(string))
request.SetMethod(requestMap["method"].(string))
}
if requestMap["plain_proto_file"] != nil {
stringifiedValue, _ := json.Marshal(requestMap["plain_proto_file"].(string))
var compressedValue bytes.Buffer
zl := zlib.NewWriter(&compressedValue)
zl.Write(stringifiedValue)
zl.Close()
encodedCompressedProtoFile := b64.StdEncoding.EncodeToString(compressedValue.Bytes())

request.SetCompressedProtoFile(encodedCompressedProtoFile)
}

// This is effectively useless as it wil not work but is necessary for the state to be in sync
AlaricCalmette marked this conversation as resolved.
Show resolved Hide resolved
if requestMap["proto_json_descriptor"] != nil {
stringifiedValue, _ := json.Marshal(requestMap["proto_json_descriptor"].(string))
var compressedValue bytes.Buffer
zl := zlib.NewWriter(&compressedValue)
zl.Write(stringifiedValue)
zl.Close()
encodedCompressedJsonDescriptor := b64.StdEncoding.EncodeToString(compressedValue.Bytes())

request.SetCompressedJsonDescriptor(encodedCompressedJsonDescriptor)
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-01-19T11:58:30.290388+01:00
2024-03-11T15:52:13.316572+01:00

Large diffs are not rendered by default.

43 changes: 42 additions & 1 deletion datadog/tests/resource_datadog_synthetics_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4103,7 +4103,7 @@ func createSyntheticsMultistepAPITest(ctx context.Context, accProvider func() (*
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "status", "paused"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.#", "4"),
"datadog_synthetics_test.multi", "api_step.#", "5"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.0.name", "First api step"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -4248,6 +4248,20 @@ func createSyntheticsMultistepAPITest(ctx context.Context, accProvider func() (*
"datadog_synthetics_test.multi", "api_step.3.request_basicauth.0.username", "username"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.3.request_basicauth.0.password", "password"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.4.request_definition.0.host", "fakehost.io"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.4.request_definition.0.service", "OboService"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.4.request_definition.0.port", "8443"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.4.request_definition.0.method", "GetOboUserJwt"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.4.request_definition.0.message", "{\"user_uuid\": \"1234\"}"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.4.request_definition.0.call_type", "unary"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.4.request_definition.0.plain_proto_file", "syntax = \"proto3\";\npackage pb;\noption go_package = \"github.com/DataDog/dd-source/domains/aaa_authn/apps/apis/obo/pb\";\nmessage GetOboUserJwtRequest {\n string user_uuid = 1; \n}\nmessage GetOboJwtResponse {\n string jwt = 1;\n}\nservice OboService {\n rpc GetOboUserJwt(GetOboUserJwtRequest) returns (GetOboJwtResponse);\n}\n"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "config_variable.0.type", "global"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -4429,6 +4443,33 @@ resource "datadog_synthetics_test" "multi" {
target = "200"
}
}

api_step {
name = "GRPC step"
subtype = "grpc"
request_definition {
call_type = "unary"
method = "GetOboUserJwt"
host = "fakehost.io"
port = 8443
service = "OboService"
message = "{\"user_uuid\": \"1234\"}"
AlaricCalmette marked this conversation as resolved.
Show resolved Hide resolved
plain_proto_file = <<EOT
syntax = "proto3";
package pb;
option go_package = "github.com/DataDog/dd-source/domains/aaa_authn/apps/apis/obo/pb";
message GetOboUserJwtRequest {
string user_uuid = 1;
}
message GetOboJwtResponse {
string jwt = 1;
}
service OboService {
rpc GetOboUserJwt(GetOboUserJwtRequest) returns (GetOboJwtResponse);
}
EOT
}
}
}
`, testName, variableName)
}
Expand Down
Loading