Verified Commit ada1cc54 authored by Giannis Kepas's avatar Giannis Kepas Committed by GitLab
Browse files

fix: Datadog integration api structure and add datadog_ci_visibility

Changelog: Improvements
parent b3e1e656
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -189,14 +189,42 @@ func (s *IntegrationsService) DeleteGroupMattermostSlashCommandsIntegration(gid
// https://docs.gitlab.com/api/group_integrations/#datadog
type GroupDatadogIntegration struct {
	Integration
	Properties *GroupDatadogIntegrationProperties `json:"properties"`

	// Deprecated: will be removed in client-go 3.0, use Properties.APIURL instead
	APIURL string `json:"api_url"`

	// Deprecated: will be removed in client-go 3.0, use Properties.DatadogEnv instead
	DatadogEnv string `json:"datadog_env"`

	// Deprecated: will be removed in client-go 3.0, use Properties.DatadogService instead
	DatadogService string `json:"datadog_service"`

	// Deprecated: will be removed in client-go 3.0, use Properties.DatadogSite instead
	DatadogSite string `json:"datadog_site"`

	// Deprecated: will be removed in client-go 3.0, use Properties.DatadogTags instead
	DatadogTags string `json:"datadog_tags"`

	// Deprecated: will be removed in client-go 3.0, use Properties.ArchiveTraceEvents instead
	ArchiveTraceEvents *bool `json:"archive_trace_events"`
}

// GroupDatadogIntegrationProperties represents Datadog specific properties
// returned by the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/api/group_integrations/#datadog
type GroupDatadogIntegrationProperties struct {
	APIURL              string `json:"api_url"`
	DatadogEnv          string `json:"datadog_env"`
	DatadogService      string `json:"datadog_service"`
	DatadogSite         string `json:"datadog_site"`
	DatadogTags         string `json:"datadog_tags"`
	DatadogCIVisibility bool   `json:"datadog_ci_visibility"`
	ArchiveTraceEvents  bool   `json:"archive_trace_events"`
}

// GroupDatadogIntegrationOptions represents the available options for
// creating or updating a Datadog integration for a group.
//
@@ -209,6 +237,7 @@ type GroupDatadogIntegrationOptions struct {
	DatadogService       *string `url:"datadog_service,omitempty" json:"datadog_service,omitempty"`
	DatadogSite          *string `url:"datadog_site,omitempty" json:"datadog_site,omitempty"`
	DatadogTags          *string `url:"datadog_tags,omitempty" json:"datadog_tags,omitempty"`
	DatadogCIVisibility  *bool   `url:"datadog_ci_visibility,omitempty" json:"datadog_ci_visibility,omitempty"`
	ArchiveTraceEvents   *bool   `url:"archive_trace_events,omitempty" json:"archive_trace_events,omitempty"`
	UseInheritedSettings *bool   `url:"use_inherited_settings,omitempty" json:"use_inherited_settings,omitempty"`
}
+24 −4
Original line number Diff line number Diff line
@@ -283,12 +283,16 @@ func TestGetGroupDatadogIntegration(t *testing.T) {
			"created_at": "2023-01-01T00:00:00.000Z",
			"updated_at": "2023-01-02T00:00:00.000Z",
			"active":     true,
			"inherited":  false,
			"properties": map[string]any{
				"api_url":               "https://api.datadoghq.com",
				"datadog_env":           "production",
				"datadog_service":       "gitlab-production",
				"datadog_site":          "datadoghq.com",
				"datadog_tags":          "env:prod\nteam:platform",
				"datadog_ci_visibility": true,
				"archive_trace_events":  true,
			},
		})
	})

@@ -301,7 +305,6 @@ func TestGetGroupDatadogIntegration(t *testing.T) {

	createdAt, _ := time.Parse(time.RFC3339, "2023-01-01T00:00:00.000Z")
	updatedAt, _ := time.Parse(time.RFC3339, "2023-01-02T00:00:00.000Z")
	archiveTraceEvents := true

	want := &GroupDatadogIntegration{
		Integration: Integration{
@@ -312,12 +315,15 @@ func TestGetGroupDatadogIntegration(t *testing.T) {
			UpdatedAt: &updatedAt,
			Active:    true,
		},
		Properties: &GroupDatadogIntegrationProperties{
			APIURL:              "https://api.datadoghq.com",
			DatadogEnv:          "production",
			DatadogService:      "gitlab-production",
			DatadogSite:         "datadoghq.com",
			DatadogTags:         "env:prod\nteam:platform",
		ArchiveTraceEvents: &archiveTraceEvents,
			DatadogCIVisibility: true,
			ArchiveTraceEvents:  true,
		},
	}

	assert.Equal(t, want, gdi)
@@ -330,6 +336,13 @@ func TestSetGroupDatadogIntegration(t *testing.T) {
	// GIVEN a group where we want to set the Datadog integration
	mux.HandleFunc("/api/v4/groups/1/integrations/datadog", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, http.MethodPut)
		testBodyJSON(t, r, map[string]any{
			"api_key":               "secret-api-key",
			"api_url":               "https://api.datadoghq.com",
			"datadog_site":          "datadoghq.com",
			"datadog_ci_visibility": true,
			"archive_trace_events":  true,
		})
		mustWriteJSONResponse(t, w, map[string]any{
			"id":         1,
			"title":      "Datadog",
@@ -337,9 +350,13 @@ func TestSetGroupDatadogIntegration(t *testing.T) {
			"created_at": "2023-01-01T00:00:00.000Z",
			"updated_at": "2023-01-02T00:00:00.000Z",
			"active":     true,
			"inherited":  false,
			"properties": map[string]any{
				"api_url":               "https://api.datadoghq.com",
				"datadog_site":          "datadoghq.com",
				"datadog_ci_visibility": true,
				"archive_trace_events":  true,
			},
		})
	})

@@ -347,6 +364,7 @@ func TestSetGroupDatadogIntegration(t *testing.T) {
		APIKey:              Ptr("secret-api-key"),
		APIURL:              Ptr("https://api.datadoghq.com"),
		DatadogSite:         Ptr("datadoghq.com"),
		DatadogCIVisibility: Ptr(true),
		ArchiveTraceEvents:  Ptr(true),
	}

@@ -359,7 +377,6 @@ func TestSetGroupDatadogIntegration(t *testing.T) {

	createdAt, _ := time.Parse(time.RFC3339, "2023-01-01T00:00:00.000Z")
	updatedAt, _ := time.Parse(time.RFC3339, "2023-01-02T00:00:00.000Z")
	archiveTraceEvents := true

	want := &GroupDatadogIntegration{
		Integration: Integration{
@@ -370,9 +387,12 @@ func TestSetGroupDatadogIntegration(t *testing.T) {
			UpdatedAt: &updatedAt,
			Active:    true,
		},
		Properties: &GroupDatadogIntegrationProperties{
			APIURL:              "https://api.datadoghq.com",
			DatadogSite:         "datadoghq.com",
		ArchiveTraceEvents: &archiveTraceEvents,
			DatadogCIVisibility: true,
			ArchiveTraceEvents:  true,
		},
	}

	assert.Equal(t, want, gdi)