Skip to content

Commit

Permalink
api: enhance ttl config api output (#8451)
Browse files Browse the repository at this point in the history
close #8450

Signed-off-by: lhy1024 <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
lhy1024 and ti-chi-bot[bot] committed Jul 29, 2024
1 parent 11da622 commit c53f1d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions server/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions tests/server/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c53f1d5

Please sign in to comment.