From 0c463f32cdb4fd49ffe748566a736895e9d71a52 Mon Sep 17 00:00:00 2001 From: Yotam loewenbach Date: Thu, 6 Jun 2024 17:31:34 +0300 Subject: [PATCH] update e2e tests --- tests/logs_e2e_test.go | 25 ++++++++++++++----------- tests/metrics_e2e_test.go | 6 +++++- tests/traces_e2e_test.go | 7 ++++++- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/tests/logs_e2e_test.go b/tests/logs_e2e_test.go index 01a721e6..dadef83c 100644 --- a/tests/logs_e2e_test.go +++ b/tests/logs_e2e_test.go @@ -17,13 +17,13 @@ type LogResponse struct { Hits []struct { Source struct { Kubernetes struct { - ContainerImageID string `json:"container_image_id"` - ContainerName string `json:"container_name"` - ContainerImage string `json:"container_image"` - NamespaceName string `json:"namespace_name"` - PodName string `json:"pod_name"` - PodID string `json:"pod_id"` - Host string `json:"host"` + ContainerImageTag string `json:"container_image_tag"` + ContainerName string `json:"container_name"` + ContainerImage string `json:"container_image"` + NamespaceName string `json:"namespace_name"` + PodName string `json:"pod_name"` + PodID string `json:"pod_id"` + Host string `json:"host"` } `json:"kubernetes"` } `json:"_source"` } `json:"hits"` @@ -45,7 +45,7 @@ func TestLogzioMonitoringLogs(t *testing.T) { t.Errorf("No logs found") } // Verify required fields - requiredFields := []string{"container_image_id", "container_name", "container_image", "namespace_name", "pod_name", "pod_id", "host"} + requiredFields := []string{"container_image_tag", "container_name", "container_image", "namespace_name", "pod_name", "pod_id", "host"} missingFields := verifyLogs(logResponse, requiredFields) if len(missingFields) > 0 { t.Errorf("Missing log fields: %v", missingFields) @@ -56,7 +56,10 @@ func TestLogzioMonitoringLogs(t *testing.T) { func fetchLogs(logsApiKey string) (*LogResponse, error) { url := fmt.Sprintf("%s/search", BaseLogzioApiUrl) client := &http.Client{} - req, err := http.NewRequest("POST", url, bytes.NewBufferString(LogsQuery)) + envID := os.Getenv("ENV_ID") + query := fmt.Sprintf("env_id:%s AND type:agent-k8s", envID) + formattedQuery := formatQuery(query) + req, err := http.NewRequest("POST", url, bytes.NewBufferString(formattedQuery)) if err != nil { return nil, err } @@ -97,8 +100,8 @@ func verifyLogs(logResponse *LogResponse, requiredFields []string) []string { for _, hit := range logResponse.Hits.Hits { kubernetes := hit.Source.Kubernetes - if kubernetes.ContainerImageID == "" { - missingFieldsMap["container_image_id"] = true + if kubernetes.ContainerImageTag == "" { + missingFieldsMap["container_image_tag"] = true break } if kubernetes.ContainerName == "" { diff --git a/tests/metrics_e2e_test.go b/tests/metrics_e2e_test.go index 5db626b6..0eff3dce 100644 --- a/tests/metrics_e2e_test.go +++ b/tests/metrics_e2e_test.go @@ -3,6 +3,7 @@ package tests import ( "encoding/json" "fmt" + "go.uber.org/zap" "io" "net/http" "os" @@ -68,6 +69,7 @@ func TestLogzioMonitoringMetrics(t *testing.T) { if metricResponse.Status != "success" { t.Errorf("No metrics found") } + logger.Info("Found metrics", zap.Int("metrics_count", len(metricResponse.Data.Result))) // Verify required metrics missingMetrics := verifyMetrics(metricResponse, requiredMetrics) if len(missingMetrics) > 0 { @@ -81,8 +83,10 @@ func TestLogzioMonitoringMetrics(t *testing.T) { // fetchMetrics fetches the metrics from the logz.io API func fetchMetrics(metricsApiKey string) (*MetricResponse, error) { - url := fmt.Sprintf("%s/metrics/prometheus/api/v1/query?query={env_id='multi-env-test'}", BaseLogzioApiUrl) + envId := os.Getenv("ENV_ID") + url := fmt.Sprintf("%s/metrics/prometheus/api/v1/query?query={env_id='%s'}", BaseLogzioApiUrl, envId) client := &http.Client{} + logger.Info("sending api request", zap.String("url", url)) req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err diff --git a/tests/traces_e2e_test.go b/tests/traces_e2e_test.go index 089a839a..67dc0473 100644 --- a/tests/traces_e2e_test.go +++ b/tests/traces_e2e_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "go.uber.org/zap" "io" "net/http" "os" @@ -86,7 +87,11 @@ func verifyTraces(traceResponse *TraceResponse, requiredFields []string) []strin func fetchTraces(tracesApiKey string) (*TraceResponse, error) { url := fmt.Sprintf("%s/search", BaseLogzioApiUrl) client := &http.Client{} - req, err := http.NewRequest("POST", url, bytes.NewBufferString(TracesQuery)) + envID := os.Getenv("ENV_ID") + query := fmt.Sprintf(`JaegerTag.env_id:%s AND type:jaegerSpan`, envID) + logger.Info("sending api request", zap.String("url", url), zap.String("query", query)) + formattedQuery := formatQuery(query) + req, err := http.NewRequest("POST", url, bytes.NewBufferString(formattedQuery)) if err != nil { return nil, err }