From d2a5f42e375aaf7205030f5e2c5b73f2f9d2b837 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 14 Nov 2024 16:06:17 +0100 Subject: [PATCH] Dynatrace mock (#2745) * feat(web): small changes in dynatrace + mock for testing * feat(backend): undo dynatrace mock * feat(backend): removed commented code from page builder * feat(backend): added 404 for not found sql response in integrations --- backend/pkg/handlers/custom/pageEventBuilder.go | 13 ++----------- backend/pkg/integrations/clients/dynatrace.go | 5 +++-- backend/pkg/integrations/handlers.go | 7 ++++++- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/backend/pkg/handlers/custom/pageEventBuilder.go b/backend/pkg/handlers/custom/pageEventBuilder.go index 589551b79..11e37687b 100644 --- a/backend/pkg/handlers/custom/pageEventBuilder.go +++ b/backend/pkg/handlers/custom/pageEventBuilder.go @@ -72,7 +72,7 @@ func (b *pageEventBuilder) Handle(message Message, timestamp uint64) Message { if msg.FirstContentfulPaint <= 30000 { b.pageEvent.FirstContentfulPaint = msg.FirstContentfulPaint } - return nil //b.buildIfTimingsComplete() + return nil case *PageRenderTiming: if b.pageEvent == nil { break @@ -80,7 +80,7 @@ func (b *pageEventBuilder) Handle(message Message, timestamp uint64) Message { b.pageEvent.SpeedIndex = msg.SpeedIndex b.pageEvent.VisuallyComplete = msg.VisuallyComplete b.pageEvent.TimeToInteractive = msg.TimeToInteractive - return nil //b.buildIfTimingsComplete() + return nil case *WebVitals: if b.webVitals == nil { b.webVitals = make(map[string]string) @@ -105,17 +105,8 @@ func (b *pageEventBuilder) Build() Message { if vitals, err := json.Marshal(b.webVitals); err == nil { pageEvent.WebVitals = string(vitals) } else { - // DEBUG fmt.Printf("Error marshalling web vitals: %v\n", err) } } return pageEvent } - -//func (b *pageEventBuilder) buildIfTimingsComplete() Message { -// if b.firstTimingHandled { -// return b.Build() -// } -// b.firstTimingHandled = true -// return nil -//} diff --git a/backend/pkg/integrations/clients/dynatrace.go b/backend/pkg/integrations/clients/dynatrace.go index f82f8d4a4..06ad8419c 100644 --- a/backend/pkg/integrations/clients/dynatrace.go +++ b/backend/pkg/integrations/clients/dynatrace.go @@ -114,7 +114,7 @@ func requestParams(sessionID uint64) url.Values { return params } -func (d *dynatraceClient) requestLogs(token, environmentID string, sessionID uint64) (*Logs, error) { +func (d *dynatraceClient) requestLogs(token, environmentID string, sessionID uint64) (interface{}, error) { requestURL := fmt.Sprintf("https://%s.live.dynatrace.com/api/v2/logs/search", environmentID) if sessionID == 0 { requestURL += "?" + testRequestParams().Encode() @@ -149,5 +149,6 @@ func (d *dynatraceClient) requestLogs(token, environmentID string, sessionID uin if len(logs.Results) == 0 { return nil, fmt.Errorf("empty logs, body: %s", string(body)) } - return logs, nil + responseContent, _ := json.Marshal(logs.Results) + return responseContent, nil } diff --git a/backend/pkg/integrations/handlers.go b/backend/pkg/integrations/handlers.go index e90b9f862..83870e358 100644 --- a/backend/pkg/integrations/handlers.go +++ b/backend/pkg/integrations/handlers.go @@ -7,6 +7,7 @@ import ( "io" "net/http" "strconv" + "strings" "time" "github.com/gorilla/mux" @@ -90,7 +91,11 @@ func (e *Router) getIntegration(w http.ResponseWriter, r *http.Request) { intParams, err := e.services.Integrator.GetIntegration(project, integration) if err != nil { - e.ResponseWithError(r.Context(), w, http.StatusInternalServerError, err, startTime, r.URL.Path, bodySize) + if strings.Contains(err.Error(), "no rows in result set") { + e.ResponseWithError(r.Context(), w, http.StatusNotFound, err, startTime, r.URL.Path, bodySize) + } else { + e.ResponseWithError(r.Context(), w, http.StatusInternalServerError, err, startTime, r.URL.Path, bodySize) + } return } e.ResponseWithJSON(r.Context(), w, intParams, startTime, r.URL.Path, bodySize)