Skip to content

Conversation

@xhebox
Copy link
Collaborator

@xhebox xhebox commented Jul 13, 2022

What problem does this PR solve?

Introduce etcd, and cli, as following:

[2022/07/13 10:29:42.645 +08:00] [INFO] [main.gin] [[email protected]/zap.go:77] [/api/admin/namespace/test_namespac]  [status=200] [method=PUT] [path=/api/admin/namespace/test_namespac] [query=] [ip=127.0.0.1] [user-agent=Go-http-client/1.1] [latency=965.145µs]
[2022/07/13 10:30:12.727 +08:00] [INFO] [main.gin] [[email protected]/zap.go:77] [/api/admin/namespace/test]  [status=200] [method=PUT] [path=/api/admin/namespace/test] [query=] [ip=127.0.0.1] [user-agent=Go-http-client/1.1] [latency=951.025µs]
[2022/07/13 10:30:14.743 +08:00] [INFO] [main.gin] [[email protected]/zap.go:77] [/api/admin/namespace/]  [status=200] [method=GET] [path=/api/admin/namespace/] [query=] [ip=127.0.0.1] [user-agent=Go-http-client/1.1] [latency=845.403µs]
^C[2022/07/13 10:30:25.100 +08:00] [INFO] [main.etcd] [embed/etcd.go:368] [closing etcd server]  [name=default] [data-dir=/home/xhe/project/pingcap/weir/etcd] [advertise-peer-urls=[http://localhost:2380]] [advertise-client-urls=[http://localhost:2379]]
[2022/07/13 10:30:25.101 +08:00] [INFO] [main.etcd] [etcdserver/server.go:1453] [skipped leadership transfer for single voting member cluster]  [local-member-id=8e9e05c52164694d] [current-leader-member-id=8e9e05c52164694d]
[2022/07/13 10:30:25.111 +08:00] [INFO] [main.etcd] [embed/etcd.go:563] [stopping serving peer traffic]  [address=127.0.0.1:2380]
[2022/07/13 10:30:25.112 +08:00] [INFO] [main.etcd] [embed/etcd.go:568] [stopped serving peer traffic]  [address=127.0.0.1:2380]
[2022/07/13 10:30:25.112 +08:00] [INFO] [main.etcd] [embed/etcd.go:370] [closed etcd server]  [name=default] [data-dir=/home/xhe/project/pingcap/weir/etcd] [advertise-peer-urls=[http://localhost:2380]] [advertise-client-urls=[http://localhost:2379]]
[2022/07/13 10:30:25.112 +08:00] [INFO] [main] [weirproxy/main.go:100] [gracefully shutdown] 
    qps: 1000
[xhe@PC weir]$ cat 1 | ./bin/weirctl namespace put test_namespac
reload namespace error
[xhe@PC weir]$ cat 1 | ./bin/weirctl namespace put test_namespac^C
[xhe@PC weir]$ vim 1
[xhe@PC weir]$ cat 1 | ./bin/weirctl namespace put test
""
[xhe@PC weir]$ ./bin/weirctl namespace list
- version: v1
  namespace: test
  frontend:
    allowed_dbs:
    - test_weir_db
    slow_sql_time: 50
    denied_ips: []
    usernames:
    - hell
    - hel1
    sql_blacklist:
    - sql: select * from tbl0
    - sql: select * from tbl1
    sql_whitelist:
    - sql: select * from tbl2
    - sql: select * from tbl3
  backend:

What is changed and how it works?

Check List

Tests

  • Manual test (add detailed scripts or steps below)

Code changes

  • Has configuration change
  • Has HTTP API interfaces change

Release note

  • No release note

xhebox added 3 commits July 8, 2022 14:52
1. add `util/cmd` to use cobra. It also introduced a non-global logger
	 passing down to all instances. `util/cmd/encoder.go` is a new encoder
	 that is consitent with the `pingcap/log`.
2. replace `proxy/server.go` with `server/server.go`.
3. replace `proxy/api.go` with the package `server/api`, which is
	 splitted into smaller packages for further development.
4. introduce etcd. Now HTTP API will start with etcd, share the same
	 port 2379, like PD.
5. move `pkg/proxy/metrics` to `pkg/metrics`.
6. rewrite configcenter to an etcd-based manager.

Signed-off-by: xhe <[email protected]>
1. introduce weirctl like pdctl
2. add namespace control subcommand to ctl
3. refine namespace HTTP api on server
4. resolve namespace manager deadlock, introduced by removing util/sync2

Signed-off-by: xhe <[email protected]>
@xhebox xhebox requested a review from djshow832 July 13, 2022 02:36
@xhebox xhebox changed the title Xhe dev introduce etcd and cli Jul 13, 2022

type BackendObserver struct {
backendInfo map[string]*BackendInfo
client *clientv3.Client
Copy link
Collaborator Author

@xhebox xhebox Jul 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global etcd client is removed and it is inserted here. There was only one client for session manager demo. But it should be configured in namespace to support multi-cluster proxy as the original weir. It is worth doing because it is simple and more flexible.

return nil
}

func (e *ConfigManager) get(ctx context.Context, ns, key string) (*mvccpb.KeyValue, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No global configuration applied for all the namespaces?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we can do that later. This is merely a demonstration of how this will work. We can add a section in yaml config, and do the validation in SetNamespace.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want this PR to be too large. Or I don't want to do it in one PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, this method is an abstraction for various configurations. It is not for namespace only.


// This is the tricky part. While HTTP services rely on managers, managers also rely on the etcd server.
// Etcd server is used to bring up the config manager and HTTP services itself.
// That means we have cyclic dependencies. Here's the solution:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the other dependencies? Etcd server relies on whom?

Copy link
Collaborator Author

@xhebox xhebox Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Etcd server is used to bring up the config manager and HTTP services itself. implies that etcd relies on HTTP services or HTTP handlers.

Copy link
Collaborator Author

@xhebox xhebox Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

etcd server -> http -> config manager -> etcd database(but it can not be split from etcd server)
<------------------------------- the loop -----------------------

This is how we can integrate etcd client api and our weirproxy api into one single port. I prefer the method, it also simplifies the management of user-config and code.

@djshow832 djshow832 merged commit 9ed3564 into main Jul 14, 2022
@djshow832 djshow832 deleted the xhe_dev branch July 14, 2022 09:01
xhebox added a commit that referenced this pull request Jul 21, 2022
cmd: introduce waitgroup wrapper

a big refactor to take an approach like PD

introduce weirctl

time format is part of pingcap/log format spec

no config/logger in struct, pass down as needed

add missing license

Signed-off-by: xhe <[email protected]>
This was referenced Jul 25, 2022
@djshow832 djshow832 changed the title introduce etcd and cli *: introduce etcd and cli Jul 25, 2022
This was referenced Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants