Skip to content

Commit a8cf985

Browse files
authored
Merge pull request #20 from sunya-ch/v1.0.0
remove neccessity of pushgateway on ReqPushLog
2 parents 6747b72 + dc8e832 commit a8cf985

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

cpe-parser/api.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,16 @@ func ReqPushLog(w http.ResponseWriter, r *http.Request) {
184184
status = "ERROR"
185185
msg = fmt.Sprintf("%v", err)
186186
} else {
187-
err := common.PushValues(logSpec.Parser, logSpec.ClusterID, logSpec.Instance, logSpec.BenchmarkName, logSpec.JobName, logSpec.PodName, logSpec.ConstLabels, values)
188-
if err != nil {
189-
status = "ERROR"
190-
msg = fmt.Sprintf("%v", err)
191-
pkey = ppkey
192-
pval = ppval
193-
} else {
194-
status = "OK"
195-
msg = fmt.Sprintf("%v", logSpec.ConstLabels)
196-
pkey = ppkey
197-
pval = ppval
187+
if common.PushgatewayURL != "" {
188+
err := common.PushValues(logSpec.Parser, logSpec.ClusterID, logSpec.Instance, logSpec.BenchmarkName, logSpec.JobName, logSpec.PodName, logSpec.ConstLabels, values)
189+
if err != nil {
190+
fmt.Println("cannot push values to push gateway: ", err)
191+
}
198192
}
193+
status = "OK"
194+
msg = fmt.Sprintf("%v", logSpec.ConstLabels)
195+
pkey = ppkey
196+
pval = ppval
199197
}
200198
}
201199
}

cpe-parser/common/pusher.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/prometheus/client_golang/prometheus/push"
1717
)
1818

19-
var pushgatewayURL string = os.Getenv("PUSHGATEWAY_URL")
19+
var PushgatewayURL string = os.Getenv("PUSHGATEWAY_URL")
2020

2121
func relabelKey(key string) string {
2222
key = strings.ToLower(key)
@@ -124,7 +124,7 @@ func GetGauges(parserKey string, instance string, podName string, values map[str
124124
}
125125

126126
func PushValues(parserKey string, clusterID string, instance string, benchmarkName string, jobName string, podName string, const_labels map[string]string, values map[string]interface{}) error {
127-
if pushgatewayURL == "" {
127+
if PushgatewayURL == "" {
128128
return fmt.Errorf("No PUSHGATEWAY_URL set")
129129
}
130130

@@ -135,7 +135,7 @@ func PushValues(parserKey string, clusterID string, instance string, benchmarkNa
135135
})
136136
completionTime.SetToCurrentTime()
137137

138-
pusher := push.New(pushgatewayURL, jobName)
138+
pusher := push.New(PushgatewayURL, jobName)
139139
for _, gauge := range gauges {
140140
pusher.Collector(gauge)
141141
}

0 commit comments

Comments
 (0)