Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2021.12.30.1 [skip pd_pr] #1113

Merged
merged 36 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a28d3fc
Revert "Release v2021.12.06.1 (#1084)"
baurine Dec 30, 2021
ee4d16d
Compitable with different TiDB versions for conprof and non-root-logi…
baurine Nov 10, 2021
b8399a9
build(deps): bump ws from 5.2.2 to 5.2.3 in /ui (#1055)
dependabot[bot] Nov 10, 2021
975d426
CICD: Update the release pipeline for recent PD format policies (#1054)
breezewish Nov 10, 2021
6d63f33
fix i18n wording (#1056)
baurine Nov 10, 2021
f47da2e
Refactor: Change util module to util package (#1052)
breezewish Nov 11, 2021
d9c5a56
Refactor: Fix godot incorrectly add dot suffix to annotations (#1059)
breezewish Nov 11, 2021
b6560ae
lint: Add goheader for copyright lints (#1062)
breezewish Nov 12, 2021
877899a
Refactor: Migrate to use the `rest` package in util/ (#1060)
breezewish Nov 22, 2021
50daa9e
fix(*): globally delete/update data by GORM (#1065)
shhdgit Nov 22, 2021
819a45a
ui: bump dependencies (#1066)
breezewish Nov 23, 2021
bd90f01
refactor: Switch to use ziputil, netutil, reflectutil and fileswap (#…
breezewish Nov 24, 2021
926c58c
Fix request header being pinned after pd profiling (#1069)
shhdgit Nov 25, 2021
9af1a84
Integrate speedscope (#1064)
YiniXu9506 Nov 29, 2021
2d2ab19
fix potential panic when GetPDInstances (#1075)
crazycs520 Nov 30, 2021
78fafc2
Refactor: a new httpclient (#1073)
breezewish Dec 1, 2021
3db85c2
Refactor: Switch to use util/distro in all places (#1078)
breezewish Dec 1, 2021
3728b24
chore: support import relative file URL (#1082)
YiniXu9506 Dec 5, 2021
1a7d6e1
Refactor: Move tools into a standalone module (#1079)
breezewish Dec 6, 2021
f98b8f4
Fix script to embed the ui (#1088)
breezewish Dec 8, 2021
b858495
Refactor feature flag to support more modules (#1057)
shhdgit Dec 8, 2021
1b47110
Drop sysutil dependency (#1093)
breezewish Dec 10, 2021
f9dd2d7
chore: add graph generation (#1085)
YiniXu9506 Dec 14, 2021
37341db
Refactor: Add TopologyProvider (#1098)
breezewish Dec 16, 2021
0148da5
esbuild: i18n + dep (#1101)
baurine Dec 16, 2021
564c6a5
script: Add a script to generate version matrix (#1104)
breezewish Dec 21, 2021
e9caf73
distro: support dynamic config (#1094)
baurine Dec 22, 2021
6bdcdf2
chore: support multiple profiling types (#1095)
YiniXu9506 Dec 22, 2021
eefe543
fix(distro): check distro_strings.json fmt by prettier (#1106)
shhdgit Dec 22, 2021
daeb3a2
script: fix generate assets (#1107)
baurine Dec 27, 2021
14f6a34
Add integration test (#1083)
shhdgit Dec 27, 2021
c4f3719
debug_api: Switch to use the new util (#1103)
breezewish Dec 27, 2021
2214f60
refactor(ui): auto refresh button (#1105)
shhdgit Dec 28, 2021
cc3bc17
ui: refine conprof (#1102)
baurine Dec 29, 2021
1a7c822
update release-version
baurine Dec 30, 2021
9d6b17a
sync with master
baurine Dec 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix request header being pinned after pd profiling (#1069)
  • Loading branch information
shhdgit authored and baurine committed Dec 30, 2021
commit 926c58c02ec4bf50075216eb220b66fc5f4fb05e
10 changes: 5 additions & 5 deletions pkg/apiserver/profiling/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package profiling

import (
"fmt"
"net/http"
"time"

"go.uber.org/fx"
Expand Down Expand Up @@ -92,8 +91,9 @@ type pdFetcher struct {

func (f *pdFetcher) fetch(op *fetchOptions) ([]byte, error) {
baseURL := fmt.Sprintf("%s://%s:%d", f.statusAPIHTTPScheme, op.ip, op.port)
f.client.WithBeforeRequest(func(req *http.Request) {
req.Header.Add("PD-Allow-follower-handle", "true")
})
return f.client.WithTimeout(maxProfilingTimeout).WithBaseURL(baseURL).SendGetRequest(op.path)
return f.client.
WithTimeout(maxProfilingTimeout).
WithBaseURL(baseURL).
AddRequestHeader("PD-Allow-follower-handle", "true").
SendGetRequest(op.path)
}
27 changes: 19 additions & 8 deletions pkg/httpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const (

type Client struct {
http.Client
BeforeRequest func(req *http.Request)

header http.Header
}

func NewHTTPClient(lc fx.Lifecycle, config *config.Config) *Client {
Expand All @@ -52,14 +53,27 @@ func NewHTTPClient(lc fx.Lifecycle, config *config.Config) *Client {
}
}

// Clone is a temporary solution to the unexpected shared pointer field and race problem
// TODO: use latest `/util/client` for better api experience.
func (c *Client) Clone() *Client {
return &Client{
Client: c.Client,
header: c.header.Clone(),
}
}

func (c Client) WithTimeout(timeout time.Duration) *Client {
c.Timeout = timeout
return &c
}

func (c Client) WithBeforeRequest(callback func(req *http.Request)) *Client {
c.BeforeRequest = callback
return &c
func (c *Client) CloneAndAddRequestHeader(key, value string) *Client {
cc := c.Clone()
if cc.header == nil {
cc.header = http.Header{}
}
cc.header.Add(key, value)
return cc
}

// TODO: Replace using go-resty.
Expand Down Expand Up @@ -90,10 +104,7 @@ func (c *Client) Send(
log.Warn("SendRequest failed", zap.String("uri", uri), zap.Error(err))
return nil, e
}

if c.BeforeRequest != nil {
c.BeforeRequest(req)
}
req.Header = c.header

resp, err := c.Do(req)
if err != nil {
Expand Down
67 changes: 67 additions & 0 deletions pkg/httpc/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2021 PingCAP, Inc. Licensed under Apache-2.0.

package httpc

import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/require"
"go.uber.org/fx/fxtest"

"github.com/pingcap/tidb-dashboard/pkg/config"
)

func newTestClient(t *testing.T) *Client {
lc := fxtest.NewLifecycle(t)
config := &config.Config{}
return NewHTTPClient(lc, config)
}

func Test_Clone(t *testing.T) {
c := newTestClient(t)
cc := c.Clone()

require.NotSame(t, c, cc)

require.Nil(t, c.header)
require.Nil(t, cc.header)
require.NotSame(t, c.header, cc.header)
}

func Test_CloneAndAddRequestHeader(t *testing.T) {
c := newTestClient(t)
cc := c.CloneAndAddRequestHeader("1", "11")

require.Nil(t, c.header)
require.Equal(t, "11", cc.header.Get("1"))

cc2 := cc.CloneAndAddRequestHeader("2", "22")
require.Equal(t, "11", cc.header.Get("1"))
require.Equal(t, "", cc.header.Get("2"))
require.Equal(t, "11", cc2.header.Get("1"))
require.Equal(t, "22", cc2.header.Get("2"))
}

func Test_Send_withHeader(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(r.Header.Get("1")))
}))
defer ts.Close()

c := newTestClient(t)
resp1, _ := c.Send(context.Background(), ts.URL, http.MethodGet, nil, nil, "")
d1, _ := resp1.Body()
require.Equal(t, "", string(d1))

cc := c.CloneAndAddRequestHeader("1", "11")
resp2, _ := cc.Send(context.Background(), ts.URL, http.MethodGet, nil, nil, "")
d2, _ := resp2.Body()
require.Equal(t, "11", string(d2))

resp3, _ := c.Send(context.Background(), ts.URL, http.MethodGet, nil, nil, "")
d3, _ := resp3.Body()
require.Equal(t, "", string(d3))
}
4 changes: 2 additions & 2 deletions pkg/pd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (c Client) WithTimeout(timeout time.Duration) *Client {
return &c
}

func (c Client) WithBeforeRequest(callback func(req *http.Request)) *Client {
c.httpClient.BeforeRequest = callback
func (c Client) AddRequestHeader(key, value string) *Client {
c.httpClient = c.httpClient.CloneAndAddRequestHeader(key, value)
return &c
}

Expand Down
52 changes: 52 additions & 0 deletions pkg/pd/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2021 PingCAP, Inc. Licensed under Apache-2.0.

package pd

import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/require"
"go.uber.org/fx/fxtest"

"github.com/pingcap/tidb-dashboard/pkg/config"
"github.com/pingcap/tidb-dashboard/pkg/httpc"
)

func newTestClient(t *testing.T) *Client {
lc := fxtest.NewLifecycle(t)
config := &config.Config{}
c := NewPDClient(lc, httpc.NewHTTPClient(lc, config), config)
c.lifecycleCtx = context.Background()
return c
}

func Test_AddRequestHeader_returnDifferentHTTPClient(t *testing.T) {
c := newTestClient(t)
cc := c.AddRequestHeader("1", "11")

require.NotSame(t, c.httpClient, cc.httpClient)
}

func Test_Get_withHeader(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(r.Header.Get("1")))
}))
defer ts.Close()

c := newTestClient(t).WithBaseURL(ts.URL)
resp1, _ := c.Get("")
d1, _ := resp1.Body()
require.Equal(t, "", string(d1))

cc := c.AddRequestHeader("1", "11")
resp2, _ := cc.Get("")
d2, _ := resp2.Body()
require.Equal(t, "11", string(d2))

resp3, _ := c.Get("")
d3, _ := resp3.Body()
require.Equal(t, "", string(d3))
}