Skip to content

Commit d7c03dc

Browse files
authored
CaaS - fix cortex CLI (#2194)
1 parent 0a1e2c2 commit d7c03dc

14 files changed

+23
-22
lines changed

pkg/operator/endpoints/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ func Delete(w http.ResponseWriter, r *http.Request) {
3232
respondError(w, r, err)
3333
return
3434
}
35-
respond(w, response)
35+
respondJSON(w, r, response)
3636
}

pkg/operator/endpoints/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ func Deploy(w http.ResponseWriter, r *http.Request) {
4848
return
4949
}
5050

51-
respond(w, response)
51+
respondJSON(w, r, response)
5252
}

pkg/operator/endpoints/get.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func GetAPIs(w http.ResponseWriter, r *http.Request) {
3030
return
3131
}
3232

33-
respond(w, response)
33+
respondJSON(w, r, response)
3434
}
3535

3636
func GetAPI(w http.ResponseWriter, r *http.Request) {
@@ -42,7 +42,7 @@ func GetAPI(w http.ResponseWriter, r *http.Request) {
4242
return
4343
}
4444

45-
respond(w, response)
45+
respondJSON(w, r, response)
4646
}
4747

4848
func GetAPIByID(w http.ResponseWriter, r *http.Request) {
@@ -55,5 +55,5 @@ func GetAPIByID(w http.ResponseWriter, r *http.Request) {
5555
return
5656
}
5757

58-
respond(w, response)
58+
respondJSON(w, r, response)
5959
}

pkg/operator/endpoints/get_batch_job.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ func GetBatchJob(w http.ResponseWriter, r *http.Request) {
8686
Endpoint: parsedURL.String(),
8787
}
8888

89-
respond(w, response)
89+
respondJSON(w, r, response)
9090
}

pkg/operator/endpoints/get_task_job.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ func GetTaskJob(w http.ResponseWriter, r *http.Request) {
8686
Endpoint: parsedURL.String(),
8787
}
8888

89-
respond(w, response)
89+
respondJSON(w, r, response)
9090
}

pkg/operator/endpoints/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func Info(w http.ResponseWriter, r *http.Request) {
4848
NodeInfos: nodeInfos,
4949
NumPendingReplicas: numPendingReplicas,
5050
}
51-
respond(w, response)
51+
respondJSON(w, r, response)
5252
}
5353

5454
func getNodeInfos() ([]schema.NodeInfo, int, error) {

pkg/operator/endpoints/refresh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ func Refresh(w http.ResponseWriter, r *http.Request) {
3737
response := schema.RefreshResponse{
3838
Message: msg,
3939
}
40-
respond(w, response)
40+
respondJSON(w, r, response)
4141
}

pkg/operator/endpoints/respond.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ import (
2828

2929
var operatorLogger = logging.GetLogger()
3030

31-
func respond(w http.ResponseWriter, response interface{}) {
31+
func respondJSON(w http.ResponseWriter, r *http.Request, response interface{}) {
32+
if err := json.NewEncoder(w).Encode(response); err != nil {
33+
respondError(w, r, errors.Wrap(err, "failed to encode response"))
34+
}
3235
w.Header().Set("Content-Type", "application/json")
3336
w.WriteHeader(http.StatusOK)
34-
json.NewEncoder(w).Encode(response)
35-
}
36-
37-
func respondPlainText(w http.ResponseWriter, response string) {
38-
w.Header().Set("Content-Type", "text/plain")
39-
w.WriteHeader(http.StatusOK)
40-
w.Write([]byte(response))
4137
}
4238

4339
func respondError(w http.ResponseWriter, r *http.Request, err error, strs ...string) {

pkg/operator/endpoints/stop_batch_job.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func StopBatchJob(w http.ResponseWriter, r *http.Request) {
4646
return
4747
}
4848

49-
respond(w, schema.DeleteResponse{
49+
respondJSON(w, r, schema.DeleteResponse{
5050
Message: fmt.Sprintf("stopped job %s", jobID),
5151
})
5252
}

pkg/operator/endpoints/stop_task_job.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func StopTaskJob(w http.ResponseWriter, r *http.Request) {
4646
return
4747
}
4848

49-
respond(w, schema.DeleteResponse{
49+
respondJSON(w, r, schema.DeleteResponse{
5050
Message: fmt.Sprintf("stopped job %s", jobID),
5151
})
5252
}

pkg/operator/endpoints/submit_batch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ func SubmitBatchJob(w http.ResponseWriter, r *http.Request) {
9494
return
9595
}
9696

97-
respond(w, jobSpec)
97+
respondJSON(w, r, jobSpec)
9898
}

pkg/operator/endpoints/submit_task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ func SubmitTaskJob(w http.ResponseWriter, r *http.Request) {
7474
return
7575
}
7676

77-
respond(w, jobSpec)
77+
respondJSON(w, r, jobSpec)
7878
}

pkg/operator/endpoints/verify_cortex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ import (
2323
)
2424

2525
func VerifyCortex(w http.ResponseWriter, r *http.Request) {
26-
respond(w, schema.VerifyCortexResponse{})
26+
respondJSON(w, r, schema.VerifyCortexResponse{})
2727
}

pkg/operator/resources/realtimeapi/metrics.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package realtimeapi
1919
import (
2020
"context"
2121
"fmt"
22+
"math"
2223
"time"
2324

2425
"github.com/cortexlabs/cortex/pkg/config"
@@ -152,6 +153,10 @@ func getAvgLatencyMetric(promAPIv1 promv1.API, apiSpec spec.API) (*float64, erro
152153
}
153154

154155
avgLatency := float64(values[0].Value)
156+
157+
if math.IsNaN(avgLatency) {
158+
return nil, nil
159+
}
155160
return &avgLatency, nil
156161
}
157162

0 commit comments

Comments
 (0)