Skip to content

Commit

Permalink
fix: fix api error and handle compatibility with lower version tidb c…
Browse files Browse the repository at this point in the history
…luster
  • Loading branch information
baurine authored and rleungx committed Mar 14, 2024
1 parent 58bb67b commit a86edef
Show file tree
Hide file tree
Showing 7 changed files with 361 additions and 342 deletions.
15 changes: 13 additions & 2 deletions pkg/apiserver/clusterinfo/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"fmt"
"net/http"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -167,7 +168,12 @@ func (s *Service) getTiProxyTopology(c *gin.Context) {
func (s *Service) getTSOTopology(c *gin.Context) {
instances, err := topology.FetchTSOTopology(s.lifecycleCtx, s.params.PDClient)
if err != nil {
rest.Error(c, err)
// TODO: refine later
if strings.Contains(err.Error(), "status code 404") {
rest.Error(c, rest.ErrNotFound.Wrap(err, "api not found"))
} else {
rest.Error(c, err)
}
return

Check warning on line 177 in pkg/apiserver/clusterinfo/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/clusterinfo/service.go#L168-L177

Added lines #L168 - L177 were not covered by tests
}
c.JSON(http.StatusOK, instances)

Check warning on line 179 in pkg/apiserver/clusterinfo/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/clusterinfo/service.go#L179

Added line #L179 was not covered by tests
Expand All @@ -182,7 +188,12 @@ func (s *Service) getTSOTopology(c *gin.Context) {
func (s *Service) getSchedulingTopology(c *gin.Context) {
instances, err := topology.FetchSchedulingTopology(s.lifecycleCtx, s.params.PDClient)
if err != nil {
rest.Error(c, err)
// TODO: refine later
if strings.Contains(err.Error(), "status code 404") {
rest.Error(c, rest.ErrNotFound.Wrap(err, "api not found"))
} else {
rest.Error(c, err)
}
return

Check warning on line 197 in pkg/apiserver/clusterinfo/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/clusterinfo/service.go#L188-L197

Added lines #L188 - L197 were not covered by tests
}
c.JSON(http.StatusOK, instances)

Check warning on line 199 in pkg/apiserver/clusterinfo/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/clusterinfo/service.go#L199

Added line #L199 was not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/topology/scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func FetchSchedulingTopology(ctx context.Context, pdClient *pd.Client) ([]SchedulingInfo, error) {
nodes := make([]SchedulingInfo, 0)
data, err := pdClient.WithoutPrefix().SendGetRequest("pd/api/v2/ms/members/scheduling")
data, err := pdClient.WithoutPrefix().SendGetRequest("/pd/api/v2/ms/members/scheduling")
if err != nil {
return nil, err
}

Check warning on line 20 in pkg/utils/topology/scheduling.go

View check run for this annotation

Codecov / codecov/patch

pkg/utils/topology/scheduling.go#L15-L20

Added lines #L15 - L20 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/topology/tso.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func FetchTSOTopology(ctx context.Context, pdClient *pd.Client) ([]TSOInfo, error) {
nodes := make([]TSOInfo, 0)
data, err := pdClient.WithoutPrefix().SendGetRequest("pd/api/v2/ms/members/tso")
data, err := pdClient.WithoutPrefix().SendGetRequest("/pd/api/v2/ms/members/tso")
if err != nil {
return nil, err
}

Check warning on line 20 in pkg/utils/topology/tso.go

View check run for this annotation

Codecov / codecov/patch

pkg/utils/topology/tso.go#L15-L20

Added lines #L15 - L20 were not covered by tests
Expand Down
Loading

0 comments on commit a86edef

Please sign in to comment.