diff --git a/pkg/apiserver/server.go b/pkg/apiserver/server.go index a850fbd..24cb3fd 100644 --- a/pkg/apiserver/server.go +++ b/pkg/apiserver/server.go @@ -67,7 +67,7 @@ func Start(params APIServerParams) { r.HandleFunc("/api/v1/app/updates", handlers.GetAppUpdates).Methods("GET") r.HandleFunc("/api/v1/app/history", handlers.GetAppHistory).Methods("GET") r.HandleFunc("/api/v1/app/custom-metrics", handlers.SendCustomAppMetrics).Methods("POST", "PATCH") - r.HandleFunc("/api/v1/app/custom-metrics/:key", handlers.SendCustomAppMetrics).Methods("DELETE") + r.HandleFunc("/api/v1/app/custom-metrics/{key}", handlers.DeleteCustomAppMetricsKey).Methods("DELETE") r.HandleFunc("/api/v1/app/instance-tags", handlers.SendAppInstanceTags).Methods("POST") // integration diff --git a/pkg/handlers/app.go b/pkg/handlers/app.go index e226110..62d9f58 100644 --- a/pkg/handlers/app.go +++ b/pkg/handlers/app.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/gorilla/mux" "github.com/pkg/errors" appstatetypes "github.com/replicatedhq/replicated-sdk/pkg/appstate/types" "github.com/replicatedhq/replicated-sdk/pkg/config" @@ -388,9 +389,9 @@ func SendCustomAppMetrics(w http.ResponseWriter, r *http.Request) { } func DeleteCustomAppMetricsKey(w http.ResponseWriter, r *http.Request) { - key := r.PathValue("key") + key, ok := mux.Vars(r)["key"] - if key == "" { + if !ok || key == "" { w.WriteHeader(http.StatusBadRequest) fmt.Fprintf(w, "key cannot be empty") logger.Errorf("cannot delete custom metrics key - key cannot be empty") @@ -406,7 +407,7 @@ func DeleteCustomAppMetricsKey(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{key: nil} - if err := report.SendCustomAppMetrics(clientset, store.GetStore(), data); err != nil { + if err := report.SendCustomAppMetrics(clientset, store.GetStore(), data, false); err != nil { logger.Error(errors.Wrapf(err, "failed to delete custom merics key: %s", key)) w.WriteHeader(http.StatusBadRequest) return