From c53f1d5c79ccb776c9090acdaae36d01e99b8ae6 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Mon, 29 Jul 2024 13:17:46 +0800 Subject: [PATCH] api: enhance ttl config api output (#8451) close tikv/pd#8450 Signed-off-by: lhy1024 Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- server/api/config.go | 12 ++++++++---- tests/server/config/config_test.go | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/server/api/config.go b/server/api/config.go index c8233f8d5eb..d280439a988 100644 --- a/server/api/config.go +++ b/server/api/config.go @@ -119,19 +119,23 @@ func (h *confHandler) SetConfig(w http.ResponseWriter, r *http.Request) { return } - if ttlSec := r.URL.Query().Get("ttlSecond"); ttlSec != "" { - ttls, err := strconv.Atoi(ttlSec) + if ttlString := r.URL.Query().Get("ttlSecond"); ttlString != "" { + ttlSec, err := strconv.Atoi(ttlString) if err != nil { h.rd.JSON(w, http.StatusBadRequest, err.Error()) return } // if ttlSecond defined, we will apply if to temp configuration. - err = h.svr.SaveTTLConfig(conf, time.Duration(ttls)*time.Second) + err = h.svr.SaveTTLConfig(conf, time.Duration(ttlSec)*time.Second) if err != nil { h.rd.JSON(w, http.StatusBadRequest, err.Error()) return } - h.rd.JSON(w, http.StatusOK, "The config is updated.") + if ttlSec == 0 { + h.rd.JSON(w, http.StatusOK, "The ttl config is deleted.") + } else { + h.rd.JSON(w, http.StatusOK, "The ttl config is updated.") + } return } diff --git a/tests/server/config/config_test.go b/tests/server/config/config_test.go index b5d5b044f12..d225614fa96 100644 --- a/tests/server/config/config_test.go +++ b/tests/server/config/config_test.go @@ -530,10 +530,12 @@ func (suite *configTestSuite) checkConfigTTL(cluster *tests.TestCluster) { assertTTLConfig(re, cluster, false) // test cleaning up - err = tu.CheckPostJSON(tests.TestDialClient, createTTLUrl(urlPrefix, 5), postData, tu.StatusOK(re)) + err = tu.CheckPostJSON(tests.TestDialClient, createTTLUrl(urlPrefix, 5), postData, + tu.StatusOK(re), tu.StringEqual(re, "\"The ttl config is updated.\"\n")) re.NoError(err) assertTTLConfig(re, cluster, true) - err = tu.CheckPostJSON(tests.TestDialClient, createTTLUrl(urlPrefix, 0), postData, tu.StatusOK(re)) + err = tu.CheckPostJSON(tests.TestDialClient, createTTLUrl(urlPrefix, 0), postData, + tu.StatusOK(re), tu.StatusOK(re), tu.StringEqual(re, "\"The ttl config is deleted.\"\n")) re.NoError(err) assertTTLConfig(re, cluster, false)