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] Add plain_proto_file and deprecate compressed_json_descriptor #2273

Merged
merged 4 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 30 additions & 2 deletions datadog/resource_datadog_synthetics_test_.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
b64 "encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
_nethttp "net/http"
"regexp"
Expand Down Expand Up @@ -236,6 +236,12 @@ func syntheticsTestRequest() *schema.Resource {
Description: "A protobuf JSON descriptor.",
Type: schema.TypeString,
Optional: true,
Deprecated: "Use `plain_proto_file` instead",
},
"plain_proto_file": {
Description: "The content of a proto file as a string",
Type: schema.TypeString,
Optional: true,
},
},
}
Expand Down Expand Up @@ -1488,6 +1494,16 @@ func buildSyntheticsAPITestStruct(d *schema.ResourceData) *datadogV1.SyntheticsA

request.SetCompressedJsonDescriptor(encodedCompressedJsonDescriptor)
}
if attr, ok := d.GetOk("request_definition.0.plain_proto_file"); ok {
stringifiedValue, _ := json.Marshal(attr.(string))
var compressedValue bytes.Buffer
zl := zlib.NewWriter(&compressedValue)
zl.Write(stringifiedValue)
zl.Close()
encodedCompressedProtoFile := b64.StdEncoding.EncodeToString(compressedValue.Bytes())

request.SetCompressedProtoFile(encodedCompressedProtoFile)
}

request = *completeSyntheticsTestRequest(request, d.Get("request_headers").(map[string]interface{}), d.Get("request_query").(map[string]interface{}), d.Get("request_basicauth").([]interface{}), d.Get("request_client_certificate").([]interface{}), d.Get("request_proxy").([]interface{}), d.Get("request_metadata").(map[string]interface{}))

Expand Down Expand Up @@ -2375,12 +2391,24 @@ func buildLocalRequest(request datadogV1.SyntheticsTestRequest) map[string]inter
decodedBytes := bytes.NewReader(decodedValue)
zl, _ := zlib.NewReader(decodedBytes)
defer zl.Close()
compressedJsonDescriptor, _ := ioutil.ReadAll(zl)
compressedJsonDescriptor, _ := io.ReadAll(zl)
var result string
_ = json.Unmarshal(compressedJsonDescriptor, &result)

localRequest["proto_json_descriptor"] = result
}
if request.HasCompressedProtoFile() {
decodedValue, _ := b64.StdEncoding.DecodeString(request.GetCompressedProtoFile())
decodedBytes := bytes.NewReader(decodedValue)
zl, _ := zlib.NewReader(decodedBytes)
defer zl.Close()
compressedProtoFile, _ := io.ReadAll(zl)
var result string
json.Unmarshal(compressedProtoFile, &result)

localRequest["plain_proto_file"] = result

}

return localRequest
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-05-17T17:05:32.491613-04:00
2024-02-08T12:25:53.842767+01:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-10-09T14:55:35.802692+02:00
2024-02-08T12:07:18.4908+01:00
706 changes: 464 additions & 242 deletions datadog/tests/cassettes/TestAccDatadogSyntheticsGRPCTest_Basic.yaml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions datadog/tests/resource_datadog_synthetics_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2358,7 +2358,7 @@ resource "datadog_synthetics_test" "websocket" {
}`, uniq)
}

var compressedJsonDescriptor = `syntax = "proto3";
var compressedProtoFile = `syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
Expand Down Expand Up @@ -2401,7 +2401,7 @@ func createSyntheticsGRPCTestStep(ctx context.Context, accProvider func() (*sche
resource.TestCheckResourceAttr(
"datadog_synthetics_test.grpc", "request_definition.0.service", "Hello"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.grpc", "request_definition.0.proto_json_descriptor", compressedJsonDescriptor),
"datadog_synthetics_test.grpc", "request_definition.0.plain_proto_file", compressedProtoFile),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.grpc", "request_metadata.%", "1"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -2469,7 +2469,7 @@ resource "datadog_synthetics_test" "grpc" {
host = "google.com"
port = 50050
service = "Hello"
proto_json_descriptor = <<EOT
plain_proto_file = <<EOT
%[2]sEOT
}

Expand Down Expand Up @@ -2512,7 +2512,7 @@ resource "datadog_synthetics_test" "grpc" {
tags = ["foo:bar", "baz"]

status = "paused"
}`, uniq, compressedJsonDescriptor)
}`, uniq, compressedProtoFile)
}

func updateSyntheticsGRPCTestStep(ctx context.Context, accProvider func() (*schema.Provider, error), t *testing.T) resource.TestStep {
Expand Down
16 changes: 9 additions & 7 deletions docs/resources/synthetics_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,11 @@ resource "datadog_synthetics_test" "grpc" {
type = "api"
subtype = "grpc"
request_definition {
method = "GET"
host = "google.com"
port = 50050
service = "Hello"
proto_json_descriptor = <<EOT
method = "GET"
host = "google.com"
port = 50050
service = "Hello"
plain_proto_file = <<EOT
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
Expand Down Expand Up @@ -609,8 +609,9 @@ Optional:
- `no_saving_response_body` (Boolean) Determines whether or not to save the response body.
- `number_of_packets` (Number) Number of pings to use per test for ICMP tests (`subtype = "icmp"`) between 0 and 10.
- `persist_cookies` (Boolean) Persist cookies across redirects.
- `plain_proto_file` (String) The content of a proto file as a string

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add period at the end of this line for consistency

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made another pr #2274 for these comment, feel free to give it a 👍

- `port` (Number) Port to use when performing the test.
- `proto_json_descriptor` (String) A protobuf JSON descriptor.
- `proto_json_descriptor` (String, Deprecated) A protobuf JSON descriptor. **Deprecated.** Use `plain_proto_file` instead

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add period at the end of this line for consistency

- `servername` (String) For SSL tests, it specifies on which server you want to initiate the TLS handshake, allowing the server to present one of multiple possible certificates on the same IP address and TCP port number.
- `service` (String) The gRPC service on which you want to perform the gRPC call.
- `should_track_hops` (Boolean) This will turn on a traceroute probe to discover all gateways along the path to the host destination. For ICMP tests (`subtype = "icmp"`).
Expand Down Expand Up @@ -954,8 +955,9 @@ Optional:
- `no_saving_response_body` (Boolean) Determines whether or not to save the response body.
- `number_of_packets` (Number) Number of pings to use per test for ICMP tests (`subtype = "icmp"`) between 0 and 10.
- `persist_cookies` (Boolean) Persist cookies across redirects.
- `plain_proto_file` (String) The content of a proto file as a string

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add period

- `port` (Number) Port to use when performing the test.
- `proto_json_descriptor` (String) A protobuf JSON descriptor.
- `proto_json_descriptor` (String, Deprecated) A protobuf JSON descriptor. **Deprecated.** Use `plain_proto_file` instead

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add period

- `servername` (String) For SSL tests, it specifies on which server you want to initiate the TLS handshake, allowing the server to present one of multiple possible certificates on the same IP address and TCP port number.
- `service` (String) The gRPC service on which you want to perform the gRPC call.
- `should_track_hops` (Boolean) This will turn on a traceroute probe to discover all gateways along the path to the host destination. For ICMP tests (`subtype = "icmp"`).
Expand Down
10 changes: 5 additions & 5 deletions examples/resources/datadog_synthetics_test/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ resource "datadog_synthetics_test" "grpc" {
type = "api"
subtype = "grpc"
request_definition {
method = "GET"
host = "google.com"
port = 50050
service = "Hello"
proto_json_descriptor = <<EOT
method = "GET"
host = "google.com"
port = 50050
service = "Hello"
plain_proto_file = <<EOT
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
Expand Down