Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: analytics client #430

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions server/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package analytics

import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"runtime"
"strconv"
"time"

"github.com/denisbrodbeck/machineid"
)
Expand Down Expand Up @@ -192,7 +190,7 @@ func sendPayloadToURL(payload Payload, url string) (*http.Response, []byte, erro

request.Header.Set("Content-Type", "application/json")

client := getClient()
client := http.DefaultClient

resp, err := client.Do(request)
if err != nil {
Expand All @@ -206,15 +204,3 @@ func sendPayloadToURL(payload Payload, url string) (*http.Response, []byte, erro

return resp, body, err
}

func getClient() *http.Client {
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
// TODO: point to valid certificate
InsecureSkipVerify: true,
},
},
Timeout: 10 * time.Second,
}
}
12 changes: 6 additions & 6 deletions server/http/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *controller) CreateTest(ctx context.Context, test openapi.Test) (openapi
return openapi.Response(http.StatusInternalServerError, err.Error()), err
}

analytics.CreateAndSendEvent("test-created-backend", "test")
analytics.CreateAndSendEvent("test_created_backend", "test")

test.TestId = id
return openapi.Response(200, test), nil
Expand All @@ -56,7 +56,7 @@ func (s *controller) UpdateTest(ctx context.Context, testid string, updated open
return openapi.Response(http.StatusInternalServerError, err.Error()), err
}

analytics.CreateAndSendEvent("test-updated-backend", "test")
analytics.CreateAndSendEvent("test_updated_backend", "test")

return openapi.Response(204, nil), nil
}
Expand All @@ -77,7 +77,7 @@ func (s *controller) DeleteTest(ctx context.Context, testid string) (openapi.Imp
return openapi.Response(http.StatusInternalServerError, err.Error()), err
}

analytics.CreateAndSendEvent("test-deleted-backend", "test")
analytics.CreateAndSendEvent("test_deleted_backend", "test")

return openapi.Response(204, nil), nil
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func (s *controller) RunTest(ctx context.Context, testid string) (openapi.ImplRe

result := s.runner.Run(*test)

analytics.CreateAndSendEvent("test-run-backend", "test")
analytics.CreateAndSendEvent("test_run_backend", "test")

return openapi.Response(200, result), nil
}
Expand Down Expand Up @@ -219,7 +219,7 @@ func (s *controller) UpdateAssertion(ctx context.Context, testID string, asserti
return openapi.Response(http.StatusInternalServerError, err.Error()), err
}

analytics.CreateAndSendEvent("assertion-updated-backend", "test")
analytics.CreateAndSendEvent("assertion_updated_backend", "test")

return openapi.Response(http.StatusNoContent, nil), nil
}
Expand All @@ -235,7 +235,7 @@ func (s *controller) DeleteAssertion(ctx context.Context, testID string, asserti
return openapi.Response(http.StatusInternalServerError, err.Error()), err
}

analytics.CreateAndSendEvent("assertion-deleted-backend", "test")
analytics.CreateAndSendEvent("assertion_deleted_backend", "test")

return openapi.Response(http.StatusNoContent, nil), nil
}
Expand Down
2 changes: 1 addition & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func main() {
}
})

err = analytics.CreateAndSendEvent("server-started-backend", "beacon")
err = analytics.CreateAndSendEvent("server_started_backend", "beacon")
if err != nil {
log.Fatal(err)
}
Expand Down