Skip to content

Commit

Permalink
fix: don't log metrics calls when API_HOST is empty (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
walkah authored Jun 19, 2024
1 parent 05fa726 commit ec4bebf
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pkg/metricsDashboard/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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,
Expand All @@ -91,7 +92,7 @@ func TrackNodeConnectionEvent(params NodeConnectionParams) {
byts, _ := json.Marshal(data)
payload := string(byts)

TrackEvent(url, payload)
trackEvent(nodeConnectionEndpoint, payload)
}

type DealPayload struct {
Expand All @@ -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)
}

0 comments on commit ec4bebf

Please sign in to comment.