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

[logs][archives] Add Resource #544

Merged

Conversation

txominpelu
Copy link
Contributor

@txominpelu txominpelu commented Jun 18, 2020

@ghost ghost added the size/XL label Jun 18, 2020
@txominpelu txominpelu force-pushed the inigo.mediavilla/logs_archives_provider branch from f80b036 to 3b4779d Compare June 18, 2020 14:13
@gzussa
Copy link
Contributor

gzussa commented Jun 19, 2020

Hi, Thanks for this PR. Any reasons why we have to use your mocking system instead of the one already in place ?

@ghost ghost added size/XXL and removed size/XL labels Jun 23, 2020
@txominpelu txominpelu force-pushed the inigo.mediavilla/logs_archives_provider branch 4 times, most recently from 96dd85d to 3f4dd0e Compare June 25, 2020 12:14
Copy link
Contributor

@gzussa gzussa left a comment

Choose a reason for hiding this comment

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

Great job! This is pretty solid already. I added comments for some nitpic and common practices.


func buildAzureMap(destination datadogV2.LogsArchiveDestinationAzure) map[string]interface{} {
result := make(map[string]interface{})
result["client_id"] = destination.Integration.ClientId
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use Getter instead? (here and similar places)

}

//Map to model
func buildDatadogArchiveCreateReq(d *schema.ResourceData) (datadogV2.LogsArchiveCreateRequest, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's return pointers whenever possible

}

func buildCreateReqDestination(d *schema.ResourceData) (datadogV2.LogsArchiveCreateRequestDestination, error) {
emptyDestination := datadogV2.LogsArchiveCreateRequestDestination{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to use datadogV2.New... methods instead (here and similar places)

return defined
}

var buildCreateReqDestinationByTypeFunctions = map[string]func(map[string]interface{}) (datadogV2.LogsArchiveCreateRequestDestination, error){
Copy link
Contributor

Choose a reason for hiding this comment

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

This variable is only used in one place. Do we need to keep this as a variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, we don't need it. I'll move that back to the only place where it is called.

if !ok {
return &datadogV2.LogsArchiveDestinationAzure{}, fmt.Errorf("tenant_id is not defined")
}
integration := datadogV2.LogsArchiveIntegrationAzure{
Copy link
Contributor

Choose a reason for hiding this comment

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

Let try to use New methods as much as possible

Comment on lines 40 to 83
httpClient := &http.Client{Transport: logging.NewTransport("Datadog", rec)}
datadogClientV1 := buildDatadogClientV1(httpClient)
datadogClientV1.GetConfig().Debug = true
authV1, err := buildAuthV1(os.Getenv("DD_API_KEY"), os.Getenv("DD_APP_KEY"), os.Getenv("DD_HOST"))
if err != nil {
t.Fatalf("Error creating Datadog Client context: %s", err)
}
var testAzureAcct = datadogV1.AzureAccount{
ClientId: datadogV1.PtrString("testc7f6-1234-5678-9101-3fcbf464test"),
ClientSecret: datadogV1.PtrString("testingx./Sw*g/Y33t..R1cH+hScMDt"),
TenantName: datadogV1.PtrString("my-tenant-id"),
}
_, _, err = datadogClientV1.AzureIntegrationApi.CreateAzureIntegration(authV1).Body(testAzureAcct).Execute()
if err != nil {
t.Fatalf("Error creating Azure Account: Response %s: %v", err.(datadogV1.GenericOpenAPIError).Body(), err)
}
defer deleteAzureIntegration(t, datadogClientV1, authV1, testAzureAcct)

accProviders := testAccProvidersWithHttpClient(t, httpClient)
accProvider := testAccProvider(t, accProviders)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add comments here in order to explain what we are doing here and why

}

// readFixture opens the file at path and returns the contents as a string
func readFixture(t *testing.T, path string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need fixture now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, this is no longer required. I will clean it up.

func buildAzureDestination(d map[string]interface{}) (*datadogV2.LogsArchiveDestinationAzure, error) {
clientId, ok := d["client_id"]
if !ok {
return &datadogV2.LogsArchiveDestinationAzure{}, fmt.Errorf("client_id is not defined")
Copy link
Contributor

Choose a reason for hiding this comment

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

should we just return nil instead of an object here and below?

func buildGCSDestination(d map[string]interface{}) (*datadogV2.LogsArchiveDestinationGCS, error) {
clientEmail, ok := d["client_email"]
if !ok {
return &datadogV2.LogsArchiveDestinationGCS{}, fmt.Errorf("client_email is not defined")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as above

rec := initRecorder(t)
defer rec.Stop()
httpClient := &http.Client{Transport: logging.NewTransport("Datadog", rec)}
// At the moment there's no azure integration in tf so we manually:
Copy link
Contributor

Choose a reason for hiding this comment

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

name = "my first gcs archive"
query = "service:tata"
gcs = {
bucket = "dd-logs-test-datadog-api-client-go"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's clean the indentation

name = "my first s3 archive"
query = "service:tutu"
s3 = {
bucket = "my-bucket"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

* `client_email` - (Required) Your client email.
* `project_id` - (Required) Your project id.
* `azure` - (Optional) Definition of an azure archive.
storage_account = "storageAccount"
Copy link
Contributor

Choose a reason for hiding this comment

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

is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, I will fix it.

name = "my first s3 archive after update"
query = "service:tutu"
s3 = {
bucket = "my-bucket"
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

@txominpelu txominpelu force-pushed the inigo.mediavilla/logs_archives_provider branch from 878a143 to 1463897 Compare June 26, 2020 10:49
@gzussa gzussa merged commit 288436d into DataDog:master Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants