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

openapi(dm): add openapi conifg in dm-master config file #3836

Merged
merged 10 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
7 changes: 6 additions & 1 deletion dm/dm/master/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewConfig() *Config {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

--openapi for command line config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now i think config file is enough becasue we will enable OpenAPI as default in the feature

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok added in 0463672


type ExperimentalFeatures struct {
OpenAPI bool `toml:"openapi"`
OpenAPI bool `toml:"openapi,omitempty"` // OpenAPI is available in v5.4 as default.
}

// Config is the configuration for dm-master.
Expand Down Expand Up @@ -128,6 +128,7 @@ type Config struct {
AutoCompactionMode string `toml:"auto-compaction-mode" json:"auto-compaction-mode"`
AutoCompactionRetention string `toml:"auto-compaction-retention" json:"auto-compaction-retention"`
QuotaBackendBytes int64 `toml:"quota-backend-bytes" json:"quota-backend-bytes"`
OpenAPI bool `toml:"openapi"`
Copy link
Contributor

Choose a reason for hiding this comment

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

json?


// directory path used to store source config files when upgrading from v1.0.x.
// if this path set, DM-master leader will try to upgrade from v1.0.x to the current version.
Expand Down Expand Up @@ -313,6 +314,10 @@ func (c *Config) adjust() error {
c.QuotaBackendBytes = quotaBackendBytesLowerBound
}

if c.ExperimentalFeatures.OpenAPI {
log.L().Warn("openapi is a GA feature and removed from experimental features, so this configuration may have no affect in feature release, please set openapi=true in dm-master config file")
}

return err
}

Expand Down
1 change: 1 addition & 0 deletions dm/dm/master/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (t *testConfigSuite) TestConfig(c *check.C) {
c.Assert(cfg.Join, check.Equals, "")
c.Assert(cfg.String(), check.Matches, fmt.Sprintf("{.*master-addr\":\"%s\".*}", masterAddr))
c.Assert(cfg.ExperimentalFeatures.OpenAPI, check.Equals, false)
c.Assert(cfg.OpenAPI, check.Equals, false)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions dm/dm/master/dm-master.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ rpc-timeout = "30s"
rpc-rate-burst = 40
rpc-rate-limit = 10.0

# openapi feature
openapi = false

# some experimental features
[experimental]
openapi = false
Copy link
Contributor

Choose a reason for hiding this comment

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

This file used for --print-sample-config, so I prefer to remove these lines.

6 changes: 3 additions & 3 deletions dm/dm/master/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (t *openAPISuite) TestRedirectRequestToLeader(c *check.C) {
cfg1.PeerUrls = tempurl.Alloc()
cfg1.AdvertisePeerUrls = cfg1.PeerUrls
cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls)
cfg1.ExperimentalFeatures.OpenAPI = true
cfg1.OpenAPI = true

s1 := NewServer(cfg1)
c.Assert(s1.Start(ctx), check.IsNil)
Expand All @@ -108,7 +108,7 @@ func (t *openAPISuite) TestRedirectRequestToLeader(c *check.C) {
cfg2.PeerUrls = tempurl.Alloc()
cfg2.AdvertisePeerUrls = cfg2.PeerUrls
cfg2.Join = cfg1.MasterAddr // join to an existing cluster
cfg2.ExperimentalFeatures.OpenAPI = true
cfg2.OpenAPI = true

s2 := NewServer(cfg2)
c.Assert(s2.Start(ctx), check.IsNil)
Expand Down Expand Up @@ -778,7 +778,7 @@ func setupServer(ctx context.Context, c *check.C) *Server {
cfg1.AdvertisePeerUrls = cfg1.PeerUrls
cfg1.AdvertiseAddr = cfg1.MasterAddr
cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls)
cfg1.ExperimentalFeatures.OpenAPI = true
cfg1.OpenAPI = true

s1 := NewServer(cfg1)
c.Assert(s1.Start(ctx), check.IsNil)
Expand Down
2 changes: 1 addition & 1 deletion dm/dm/master/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (s *Server) Start(ctx context.Context) (err error) {
"/status": getStatusHandle(),
"/debug/": getDebugHandler(),
}
if s.cfg.ExperimentalFeatures.OpenAPI {
if s.cfg.OpenAPI || s.cfg.ExperimentalFeatures.OpenAPI {
if initOpenAPIErr := s.InitOpenAPIHandles(); initOpenAPIErr != nil {
return terror.ErrOpenAPICommonError.Delegate(initOpenAPIErr)
}
Expand Down
2 changes: 1 addition & 1 deletion dm/tests/dmctl_basic/conf/get_master1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ max-request-bytes = 1572864
auto-compaction-mode = "periodic"
auto-compaction-retention = "1h"
quota-backend-bytes = 2147483648
openapi = false
Copy link
Contributor

@GMHDBJD GMHDBJD Dec 28, 2021

Choose a reason for hiding this comment

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

Can we omit the below lines when by get-config at L29? looks so confused.

[experimental]
  openapi = false

v1-sources-path = ""
ssl-ca = ""
ssl-cert = ""
ssl-key = ""

[experimental]
openapi = false
Copy link
Contributor

Choose a reason for hiding this comment

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

if experimental.openapi==true, still print it? Why not set it to false when adjust?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes we should adjust this value , added in 0964771

2 changes: 0 additions & 2 deletions dm/tests/openapi/conf/dm-master1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ initial-cluster = "master1=http://127.0.0.1:8291"
master-addr = ":8261"
name = "master1"
peer-urls = "127.0.0.1:8291"

[experimental]
openapi = true
2 changes: 0 additions & 2 deletions dm/tests/openapi/conf/dm-master2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ join = "127.0.0.1:8261"
master-addr = ":8361"
name = "master2"
peer-urls = "127.0.0.1:8292"

[experimental]
openapi = true