-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Refactor globalConfiguration / WebProvider #1938
Refactor globalConfiguration / WebProvider #1938
Conversation
juliens
commented
Aug 10, 2017
- split the globalconfiguration to a new package (not in package server)
- split traefik configuration and global configuration
- webprovider is now in package provider
- the run func need a global configuration and not a traefik configuration
94d42ec
to
dc348d3
Compare
dc348d3
to
931ad6f
Compare
931ad6f
to
a568d2d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juliens Your refacto SGTM.
Only two suggestions.
server/server.go
Outdated
statsRecorder := middlewares.NewStatsRecorder(server.globalConfiguration.Web.Statistics.RecentErrors) | ||
server.globalConfiguration.Web.StatsRecorder = statsRecorder | ||
serverMiddlewares = append(serverMiddlewares, statsRecorder) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is your mind about the deletion of the statsRecorder
variable?
if server.globalConfiguration.Web.Statistics != nil {
server.globalConfiguration.Web.StatsRecorder = middlewares.NewStatsRecorder(server.globalConfiguration.Web.Statistics.RecentErrors)
serverMiddlewares = append(serverMiddlewares, server.globalConfiguration.Web.StatsRecorder)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok for me
server/server.go
Outdated
metricsMiddleware := thoas_stats.New() | ||
server.globalConfiguration.Web.MetricsRecorder = metricsMiddleware | ||
serverMiddlewares = append(serverMiddlewares, metricsMiddleware) | ||
if server.globalConfiguration.Web.Statistics != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is your mind about the deletion of the metricsMiddleware
variable?
if server.globalConfiguration.Web.Statistics != nil {
server.globalConfiguration.Web.MetricsRecorder = thoas_stats.New()
serverMiddlewares = append(serverMiddlewares, server.globalConfiguration.Web.MetricsRecorder)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok for me
e046ae8
to
6674e82
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmd/traefik/traefik.go
Outdated
fmtlog.SetFlags(fmtlog.Lshortfile | fmtlog.LstdFlags) | ||
|
||
// load global configuration | ||
globalConfiguration := traefikConfiguration.GlobalConfiguration | ||
http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = globalConfiguration.MaxIdleConnsPerHost |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure to understand/remember why we apply those parameters to DefaultTransport
whereas we used those ones to apply to a specific instance (in server.go
createHTTPTransport
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually like code before the introduction of the timeouts PR #1873 and gets reintroduced here, which it shouldn't. Can you align your version please.
provider/web/web.go
Outdated
Debug bool | ||
CurrentConfigurations *safe.Safe | ||
MetricsRecorder *thoas_stats.Stats | ||
StatsRecorder *middlewares.StatsRecorder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intended (MetricsRecorder
& StatsRecorder
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imho the naming is confusing. Can you rename MetricsRecorder
with Stats
to make the distinction with the existing Metrics
implementation clear?
To be sure, fields like StatsRecorder
can not be configured as part of the Web provider now?
server *Server | ||
Auth *types.Auth | ||
// Provider is a provider.Provider implementation that provides the UI | ||
type Provider struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this struct embed a provider.BaseProvider
like any other provider ?
if server.globalConfiguration.Web != nil && server.globalConfiguration.Web.Statistics != nil { | ||
statsRecorder = middlewares.NewStatsRecorder(server.globalConfiguration.Web.Statistics.RecentErrors) | ||
serverMiddlewares = append(serverMiddlewares, statsRecorder) | ||
if server.globalConfiguration.Web != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if these changes are compliant with the metrics refactor made in #1968
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @marco-jantke
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICS it doesn't interfere with the metrics implementation but the naming confuses at the moment. Its a good step by the way to get rid of the global stats
variable. Anyhow MetricsRecorder
is a confusing naming. I would stick with Stats
.
This may seem like a silly question, but if we are migrating the web provider to its own middleware, can we use this opportunity to rename it to something like 'api', or 'rest' or some sort of API-like provider name? It can be very confusing for people to have the API and the Admin panel be named "web" |
+1 to what @dtomcej said. |
It's not only a rest api but it's also an endpoint for the webui. A good name is hard to find. |
True... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the feeling the package naming is quite verbose, as one example configuration.TraeifkConfiguration
. Should we maybe use only and consistently config
like config.TraefikConfig
?
cmd/traefik/traefik.go
Outdated
fmtlog.SetFlags(fmtlog.Lshortfile | fmtlog.LstdFlags) | ||
|
||
// load global configuration | ||
globalConfiguration := traefikConfiguration.GlobalConfiguration | ||
http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = globalConfiguration.MaxIdleConnsPerHost |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually like code before the introduction of the timeouts PR #1873 and gets reintroduced here, which it shouldn't. Can you align your version please.
provider/web/web.go
Outdated
Debug bool | ||
CurrentConfigurations *safe.Safe | ||
MetricsRecorder *thoas_stats.Stats | ||
StatsRecorder *middlewares.StatsRecorder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imho the naming is confusing. Can you rename MetricsRecorder
with Stats
to make the distinction with the existing Metrics
implementation clear?
To be sure, fields like StatsRecorder
can not be configured as part of the Web provider now?
if server.globalConfiguration.Web != nil && server.globalConfiguration.Web.Statistics != nil { | ||
statsRecorder = middlewares.NewStatsRecorder(server.globalConfiguration.Web.Statistics.RecentErrors) | ||
serverMiddlewares = append(serverMiddlewares, statsRecorder) | ||
if server.globalConfiguration.Web != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICS it doesn't interfere with the metrics implementation but the naming confuses at the moment. Its a good step by the way to get rid of the global stats
variable. Anyhow MetricsRecorder
is a confusing naming. I would stick with Stats
.
0ccaf5e
to
1bf033a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👏
Hey @marco-jantke, we all use automatic completion today, so I think we can live we "long" package names ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
- Traefik configuration is in main - Metrics and statsRecord are not global vars anymore - run use GlobalConfiguration - fix log rotation test to adapt to he new number of lines due to the refactoring
1bf033a
to
fa8396f
Compare