Skip to content

Commit

Permalink
metrics: Support customize Prometheus address (#808)
Browse files Browse the repository at this point in the history
Signed-off-by: Breezewish <me@breeswish.org>
  • Loading branch information
breezewish authored Nov 25, 2020
1 parent 07742d6 commit 7f2eaca
Show file tree
Hide file tree
Showing 52 changed files with 1,402 additions and 495 deletions.
104 changes: 23 additions & 81 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ Although TiDB Dashboard can also be integrated into [PD], this form is not conve

### Step 1. Start a TiDB cluster

#### Solution A. Use TiUP (Recommended)

[TiUP] is the offical component manager for [TiDB]. It can help you set up a local TiDB cluster in a few minutes.

Download and install TiUP:
Expand All @@ -40,73 +38,7 @@ Start a local TiDB cluster:
tiup playground nightly
```

> Note: you might notice that there is already a TiDB Dashboard integrated into the PD started by TiUP. For development purpose, we will not use the that TiDB Dashboard. Please keep following the rest of the steps in this document.
#### Solution B. Download and Run Binary Manually

<details>

Alternatively, you can deploy a cluster with binary files manually.

1. Download binaries

Linux:

```bash
mkdir tidb_cluster
cd tidb_cluster
wget https://download.pingcap.org/tidb-nightly-linux-amd64.tar.gz
tar -xzf tidb-nightly-linux-amd64.tar.gz
cd tidb-nightly-linux-amd64
```

MacOS:

```bash
mkdir tidb_cluster
cd tidb_cluster
wget https://download.pingcap.org/tidb-nightly-darwin-amd64.tar.gz
wget https://download.pingcap.org/tikv-nightly-darwin-amd64.tar.gz
wget https://download.pingcap.org/pd-nightly-darwin-amd64.tar.gz
mkdir tidb-nightly-darwin-amd64
tar -xzf tidb-nightly-darwin-amd64.tar.gz -C tidb-nightly-darwin-amd64 --strip-components=1
tar -xzf tikv-nightly-darwin-amd64.tar.gz -C tidb-nightly-darwin-amd64 --strip-components=1
tar -xzf pd-nightly-darwin-amd64.tar.gz -C tidb-nightly-darwin-amd64 --strip-components=1
cd tidb-nightly-darwin-amd64
```

2. Start a PD server

```bash
./bin/pd-server --name=pd --data-dir=pd --client-urls=http://127.0.0.1:2379 --log-file=pd.log
# Now pd-server is listen on port 2379
```

3. Start a TiKV server

Open a new terminal:

```bash
./bin/tikv-server --addr="127.0.0.1:20160" --pd-endpoints="127.0.0.1:2379" --data-dir=tikv --log-file=./tikv.log
# Now tikv-server is listen on port 20160
```

4. Start a TiDB server

Open a new terminal:

```bash
./bin/tidb-server --store=tikv --path="127.0.0.1:2379" --log-file=tidb.log
# Now tidb-server is listen on port 4000
```

5. Use mysql-client to check everything works fine:

```bash
mysql -h 127.0.0.1 -P 4000 -uroot
```

</details>
You might notice that there is already a TiDB Dashboard integrated into the PD started by TiUP. For development purpose, it will not be used intentionally.

### Step 2. Prepare Prerequisites

Expand All @@ -124,7 +56,7 @@ The followings are required for developing TiDB Dashboard:
1. Clone the repository:

```bash
git clone https://github.com/pingcap-incubator/tidb-dashboard.git
git clone https://github.com/pingcap/tidb-dashboard.git
cd tidb-dashboard
```

Expand All @@ -144,34 +76,42 @@ The followings are required for developing TiDB Dashboard:
yarn start
```

1. That's it! You can access TiDB Dashboard now:
TiDB Dashboard UI: http://127.0.0.1:3001
Swagger UI for TiDB Dashboard APIs: http://localhost:12333/dashboard/api/swagger
1. That's it! You can access TiDB Dashboard now: http://127.0.0.1:3001
### Step 4. Run E2E Tests (optional)
Now we have only a few e2e tests in the `ui/tests` folder, you can contribute more for it.
After finishing the above steps, we can run the tests by following commands:
When back-end server and front-end server are both started, E2E tests can be run by:
```bash
cd ui/tests
yarn
yarn test
```
### Step 5. Run Storybook Playground (optional)
> Now we have only a few e2e tests. Contributions are welcome!
## Additional Guides
### Swagger UI
We use [Swagger] to generate the API server and corresponding clients. Swagger provides a web UI in which you can
see all TiDB Dashboard API endpoints and specifications, or even send API requests.
Swagger UI is available at http://localhost:12333/dashboard/api/swagger after the above Step 3 is finished.
### Storybook
We expose some UI components in a playground provided by [React Storybook]. In the playground you can see what
components look like and how to use them.
After finishing the above steps, we can run the storybook playground by following commands:
Storybook can be started using the following commands:
```bash
cd ui
yarn storybook
```
You can add more stories for your components to the playground.
> We have not yet make all components available in the Storybook. Contributions are welcome!
## Contribution flow
Expand Down Expand Up @@ -256,3 +196,5 @@ The body of the commit message should describe why the change was made and at a
[tidb]: https://github.com/pingcap/tidb
[tikv]: https://github.com/tikv/tikv
[tiup]: https://tiup.io
[Swagger]: https://swagger.io
[React Storybook]: https://storybook.js.org
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require (
go.uber.org/zap v1.13.0
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58
google.golang.org/grpc v1.25.1
gopkg.in/oleiade/reflections.v1 v1.0.0
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAG
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
24 changes: 12 additions & 12 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ func (s *Service) Start(ctx context.Context) error {
),
fx.Populate(&s.apiHandlerEngine),
fx.Invoke(
user.Register,
info.Register,
clusterinfo.Register,
profiling.Register,
logsearch.Register,
slowquery.Register,
statement.Register,
diagnose.Register,
keyvisual.Register,
metrics.Register,
queryeditor.Register,
configuration.Register,
user.RegisterRouter,
info.RegisterRouter,
clusterinfo.RegisterRouter,
profiling.RegisterRouter,
logsearch.RegisterRouter,
slowquery.RegisterRouter,
statement.RegisterRouter,
diagnose.RegisterRouter,
keyvisual.RegisterRouter,
metrics.RegisterRouter,
queryeditor.RegisterRouter,
configuration.RegisterRouter,
// Must be at the end
s.status.Register,
),
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/clusterinfo/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewService(lc fx.Lifecycle, p ServiceParams) *Service {
return s
}

func Register(r *gin.RouterGroup, auth *user.AuthService, s *Service) {
func RegisterRouter(r *gin.RouterGroup, auth *user.AuthService, s *Service) {
endpoint := r.Group("/topology")
endpoint.Use(auth.MWAuthRequired())
endpoint.GET("/tidb", s.getTiDBTopology)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/configuration/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver/utils"
)

func Register(r *gin.RouterGroup, auth *user.AuthService, s *Service) {
func RegisterRouter(r *gin.RouterGroup, auth *user.AuthService, s *Service) {
endpoint := r.Group("/configuration")
endpoint.Use(auth.MWAuthRequired())
endpoint.Use(utils.MWConnectTiDB(s.params.TiDBClient))
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/diagnose/diagnose.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewService(config *config.Config, tidbClient *tidb.Client, db *dbstore.DB,
}
}

func Register(r *gin.RouterGroup, auth *user.AuthService, s *Service) {
func RegisterRouter(r *gin.RouterGroup, auth *user.AuthService, s *Service) {
endpoint := r.Group("/diagnose")
endpoint.GET("/reports",
auth.MWAuthRequired(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewService(p ServiceParams) *Service {
return &Service{params: p}
}

func Register(r *gin.RouterGroup, auth *user.AuthService, s *Service) {
func RegisterRouter(r *gin.RouterGroup, auth *user.AuthService, s *Service) {
endpoint := r.Group("/info")
endpoint.GET("/info", s.infoHandler)
endpoint.Use(auth.MWAuthRequired())
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/logsearch/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewService(lc fx.Lifecycle, config *config.Config, db *dbstore.DB) *Service
return service
}

func Register(r *gin.RouterGroup, auth *user.AuthService, s *Service) {
func RegisterRouter(r *gin.RouterGroup, auth *user.AuthService, s *Service) {
endpoint := r.Group("/logs")
{
endpoint.GET("/download", s.DownloadLogs)
Expand Down
131 changes: 0 additions & 131 deletions pkg/apiserver/metrics/metrics.go

This file was deleted.

Loading

0 comments on commit 7f2eaca

Please sign in to comment.