Skip to content

CaaS - fix cortex CLI #2194

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

Merged
merged 3 commits into from
May 27, 2021
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
2 changes: 1 addition & 1 deletion pkg/operator/endpoints/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ func Delete(w http.ResponseWriter, r *http.Request) {
respondError(w, r, err)
return
}
respond(w, response)
respondJSON(w, r, response)
}
2 changes: 1 addition & 1 deletion pkg/operator/endpoints/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ func Deploy(w http.ResponseWriter, r *http.Request) {
return
}

respond(w, response)
respondJSON(w, r, response)
}
6 changes: 3 additions & 3 deletions pkg/operator/endpoints/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GetAPIs(w http.ResponseWriter, r *http.Request) {
return
}

respond(w, response)
respondJSON(w, r, response)
}

func GetAPI(w http.ResponseWriter, r *http.Request) {
Expand All @@ -42,7 +42,7 @@ func GetAPI(w http.ResponseWriter, r *http.Request) {
return
}

respond(w, response)
respondJSON(w, r, response)
}

func GetAPIByID(w http.ResponseWriter, r *http.Request) {
Expand All @@ -55,5 +55,5 @@ func GetAPIByID(w http.ResponseWriter, r *http.Request) {
return
}

respond(w, response)
respondJSON(w, r, response)
}
2 changes: 1 addition & 1 deletion pkg/operator/endpoints/get_batch_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ func GetBatchJob(w http.ResponseWriter, r *http.Request) {
Endpoint: parsedURL.String(),
}

respond(w, response)
respondJSON(w, r, response)
}
2 changes: 1 addition & 1 deletion pkg/operator/endpoints/get_task_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ func GetTaskJob(w http.ResponseWriter, r *http.Request) {
Endpoint: parsedURL.String(),
}

respond(w, response)
respondJSON(w, r, response)
}
2 changes: 1 addition & 1 deletion pkg/operator/endpoints/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Info(w http.ResponseWriter, r *http.Request) {
NodeInfos: nodeInfos,
NumPendingReplicas: numPendingReplicas,
}
respond(w, response)
respondJSON(w, r, response)
}

func getNodeInfos() ([]schema.NodeInfo, int, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/endpoints/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ func Refresh(w http.ResponseWriter, r *http.Request) {
response := schema.RefreshResponse{
Message: msg,
}
respond(w, response)
respondJSON(w, r, response)
}
12 changes: 4 additions & 8 deletions pkg/operator/endpoints/respond.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ import (

var operatorLogger = logging.GetLogger()

func respond(w http.ResponseWriter, response interface{}) {
func respondJSON(w http.ResponseWriter, r *http.Request, response interface{}) {
if err := json.NewEncoder(w).Encode(response); err != nil {
respondError(w, r, errors.Wrap(err, "failed to encode response"))
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
}

func respondPlainText(w http.ResponseWriter, response string) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write([]byte(response))
}

func respondError(w http.ResponseWriter, r *http.Request, err error, strs ...string) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/endpoints/stop_batch_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func StopBatchJob(w http.ResponseWriter, r *http.Request) {
return
}

respond(w, schema.DeleteResponse{
respondJSON(w, r, schema.DeleteResponse{
Message: fmt.Sprintf("stopped job %s", jobID),
})
}
2 changes: 1 addition & 1 deletion pkg/operator/endpoints/stop_task_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func StopTaskJob(w http.ResponseWriter, r *http.Request) {
return
}

respond(w, schema.DeleteResponse{
respondJSON(w, r, schema.DeleteResponse{
Message: fmt.Sprintf("stopped job %s", jobID),
})
}
2 changes: 1 addition & 1 deletion pkg/operator/endpoints/submit_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ func SubmitBatchJob(w http.ResponseWriter, r *http.Request) {
return
}

respond(w, jobSpec)
respondJSON(w, r, jobSpec)
}
2 changes: 1 addition & 1 deletion pkg/operator/endpoints/submit_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ func SubmitTaskJob(w http.ResponseWriter, r *http.Request) {
return
}

respond(w, jobSpec)
respondJSON(w, r, jobSpec)
}
2 changes: 1 addition & 1 deletion pkg/operator/endpoints/verify_cortex.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ import (
)

func VerifyCortex(w http.ResponseWriter, r *http.Request) {
respond(w, schema.VerifyCortexResponse{})
respondJSON(w, r, schema.VerifyCortexResponse{})
}
5 changes: 5 additions & 0 deletions pkg/operator/resources/realtimeapi/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package realtimeapi
import (
"context"
"fmt"
"math"
"time"

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

avgLatency := float64(values[0].Value)

if math.IsNaN(avgLatency) {
return nil, nil
}
return &avgLatency, nil
}

Expand Down