From ec4bebf59ec75cda59a7f180d8f45f214d0d2b03 Mon Sep 17 00:00:00 2001 From: James Walker Date: Wed, 19 Jun 2024 18:47:41 -0400 Subject: [PATCH] fix: don't log metrics calls when API_HOST is empty (#172) --- pkg/metricsDashboard/logger.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/metricsDashboard/logger.go b/pkg/metricsDashboard/logger.go index eb504b5c..8aef75fe 100644 --- a/pkg/metricsDashboard/logger.go +++ b/pkg/metricsDashboard/logger.go @@ -16,9 +16,14 @@ const nodeInfoEndpoint = "nodes" const nodeConnectionEndpoint = "uptimes" const dealsEndpoint = "deals" -var host = os.Getenv("API_HOST") + "metrics-dashboard/" +func trackEvent(path string, json string) { + var host = os.Getenv("API_HOST") + if host == "" { + return + } + + var url = host + "metrics-dashboard/" + path -func TrackEvent(url string, json string) { data := []byte(json) client := &http.Client{Timeout: time.Second * 1} @@ -34,7 +39,6 @@ func TrackEvent(url string, json string) { } func TrackJobOfferUpdate(evOffer data.JobOfferContainer) { - var url = host + jobsEndpoint var module = evOffer.JobOffer.Module.Name if module == "" { module = evOffer.JobOffer.Module.Repo + ":" + evOffer.JobOffer.Module.Hash @@ -53,12 +57,10 @@ func TrackJobOfferUpdate(evOffer data.JobOfferContainer) { byts, _ := json.Marshal(data) payload := string(byts) - TrackEvent(url, payload) + trackEvent(jobsEndpoint, payload) } func TrackNodeInfo(resourceOffer data.ResourceOffer) { - var url = host + nodeInfoEndpoint - data := map[string]interface{}{ "ID": resourceOffer.ResourceProvider, "GPU": resourceOffer.Spec.GPU, @@ -69,7 +71,7 @@ func TrackNodeInfo(resourceOffer data.ResourceOffer) { byts, _ := json.Marshal(data) payload := string(byts) - TrackEvent(url, payload) + trackEvent(nodeInfoEndpoint, payload) } type NodeConnectionParams struct { @@ -80,7 +82,6 @@ type NodeConnectionParams struct { } func TrackNodeConnectionEvent(params NodeConnectionParams) { - var url = host + nodeConnectionEndpoint data := map[string]interface{}{ "ID": params.ID, "Event": params.Event, @@ -91,7 +92,7 @@ func TrackNodeConnectionEvent(params NodeConnectionParams) { byts, _ := json.Marshal(data) payload := string(byts) - TrackEvent(url, payload) + trackEvent(nodeConnectionEndpoint, payload) } type DealPayload struct { @@ -102,9 +103,8 @@ type DealPayload struct { } func TrackDeal(params DealPayload) { - var url = host + dealsEndpoint byts, _ := json.Marshal(params) payload := string(byts) - TrackEvent(url, payload) + trackEvent(dealsEndpoint, payload) }