Skip to content

Commit

Permalink
working DELETE
Browse files Browse the repository at this point in the history
  • Loading branch information
Siva Manivannan committed Jun 18, 2024
1 parent af1bf2a commit 1d65986
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/apiserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions pkg/handlers/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 1d65986

Please sign in to comment.