Skip to content

Commit

Permalink
update e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yotamloe committed Jun 6, 2024
1 parent ed60767 commit 0c463f3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
25 changes: 14 additions & 11 deletions tests/logs_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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 == "" {
Expand Down
6 changes: 5 additions & 1 deletion tests/metrics_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"encoding/json"
"fmt"
"go.uber.org/zap"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion tests/traces_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"go.uber.org/zap"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0c463f3

Please sign in to comment.