-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
487 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/extension-datadog | ||
extension-datadog.iml | ||
/coverage.out | ||
/extension-datadog.run.xml | ||
/e2e/e2e-coverage-docker.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2023 Steadybit GmbH | ||
|
||
package e2e | ||
|
||
import ( | ||
"context" | ||
"github.com/steadybit/action-kit/go/action_kit_test/e2e" | ||
"github.com/steadybit/discovery-kit/go/discovery_kit_api" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestWithMinikube(t *testing.T) { | ||
server := createMockDatadogServer() | ||
defer server.Close() | ||
port := strings.SplitAfter(server.URL, ":")[2] | ||
|
||
extFactory := e2e.HelmExtensionFactory{ | ||
Name: "extension-datadog", | ||
Port: 8090, | ||
ExtraArgs: func(m *e2e.Minikube) []string { | ||
return []string{ | ||
"--set", "logging.level=debug", | ||
"--set", "datadog.apiKey=123456-7890", | ||
"--set", "datadog.applicationKey=555-666-777", | ||
"--set", "datadog.siteParameter=datadoghq.eu", | ||
"--set", "datadog.siteUrl=https://app.datadoghq.eu", | ||
"--set", "testing.scheme=http", | ||
"--set", "testing.host=host.minikube.internal:" + port, | ||
} | ||
}, | ||
} | ||
|
||
mOpts := e2e.DefaultMiniKubeOpts | ||
mOpts.Runtimes = []e2e.Runtime{e2e.RuntimeDocker} | ||
|
||
e2e.WithMinikube(t, mOpts, &extFactory, []e2e.WithMinikubeTestCase{ | ||
{ | ||
Name: "target discovery", | ||
Test: testDiscovery, | ||
}, | ||
}) | ||
} | ||
|
||
func testDiscovery(t *testing.T, m *e2e.Minikube, e *e2e.Extension) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | ||
defer cancel() | ||
|
||
target, err := e2e.PollForTarget(ctx, e, "com.github.steadybit.extension_datadog.monitor", func(target discovery_kit_api.Target) bool { | ||
return e2e.HasAttribute(target, "datadog.monitor.id", "8080808") | ||
}) | ||
|
||
require.NoError(t, err) | ||
assert.Equal(t, target.TargetType, "com.github.steadybit.extension_datadog.monitor") | ||
assert.True(t, e2e.HasAttribute(target, "datadog.monitor.name", "[DEV] Monitor Kubernetes Deployments Replica Pods")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package e2e | ||
|
||
import ( | ||
"github.com/rs/zerolog/log" | ||
"net/http" | ||
"net/http/httptest" | ||
"strconv" | ||
) | ||
|
||
func createMockDatadogServer() *httptest.Server { | ||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
log.Info().Str("path", r.URL.Path).Str("method", r.Method).Str("query", r.URL.RawQuery).Msg("Request received") | ||
if r.URL.Path == "/api/v1/validate" { | ||
w.WriteHeader(http.StatusOK) | ||
w.Write(apiV1Validate()) | ||
} else if r.URL.Path == "/api/v1/monitor" { | ||
page, _ := strconv.Atoi(r.URL.Query().Get("page")) | ||
w.WriteHeader(http.StatusOK) | ||
w.Write(apiV1Monitor(page)) | ||
} else { | ||
w.WriteHeader(http.StatusBadRequest) | ||
} | ||
})) | ||
return server | ||
} | ||
|
||
func apiV1Validate() []byte { | ||
return []byte(`{"valid": true}`) | ||
} | ||
|
||
func apiV1Monitor(page int) []byte { | ||
if page == 0 { | ||
return []byte( | ||
`[ | ||
{ | ||
"id": 8080808, | ||
"org_id": 9090909090, | ||
"type": "query alert", | ||
"name": "[DEV] Monitor Kubernetes Deployments Replica Pods", | ||
"message": "More than one Deployments Replica's pods are down", | ||
"tags": [ | ||
"integration:kubernetes", | ||
"env:dev" | ||
], | ||
"query": "min(last_5m):avg:kubernetes_state.deployment.replicas_desired{kube_cluster_name:dev-demo} by {kube_namespace,kube_deployment} - avg:kubernetes_state.deployment.replicas_available{kube_cluster_name:dev-demo} by {kube_namespace,kube_deployment} >= 2", | ||
"options": { | ||
"thresholds": { | ||
"critical": 2.0, | ||
"warning": 1.0 | ||
}, | ||
"notify_audit": true, | ||
"require_full_window": false, | ||
"notify_no_data": true, | ||
"renotify_interval": 0, | ||
"timeout_h": 0, | ||
"include_tags": true, | ||
"escalation_message": "", | ||
"new_group_delay": 60, | ||
"silenced": {} | ||
}, | ||
"multi": true, | ||
"created_at": 1666859636000, | ||
"created": "2022-10-27T08:33:56.272148+00:00", | ||
"modified": "2023-06-20T10:15:46.744422+00:00", | ||
"deleted": null, | ||
"restricted_roles": null, | ||
"priority": null, | ||
"overall_state_modified": "2023-06-21T05:42:33+00:00", | ||
"overall_state": "OK", | ||
"creator": { | ||
"name": "Theo Test", | ||
"handle": "[email protected]", | ||
"email": "[email protected]", | ||
"id": 1010101010 | ||
}, | ||
"matching_downtimes": [] | ||
} | ||
]`) | ||
} else { | ||
return []byte(`[]`) | ||
} | ||
} |
Oops, something went wrong.