You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by jv...@apache.org on 2018/06/01 15:06:42 UTC
[incubator-trafficcontrol] branch master updated: Add Grove
configurable plugin enable/disabling
This is an automated email from the ASF dual-hosted git repository.
jvd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new a6704d2 Add Grove configurable plugin enable/disabling
a6704d2 is described below
commit a6704d2e6dd323d0e4efff97c92c21c1e0bda7a5
Author: Robert Butts <ro...@apache.org>
AuthorDate: Wed May 30 13:42:50 2018 -0600
Add Grove configurable plugin enable/disabling
---
grove/README.md | 2 ++
grove/config/config.go | 2 ++
grove/grove.cfg | 3 ++-
grove/grove.go | 5 ++++-
grove/plugin/hello_context.go | 2 +-
grove/plugin/hello_world.go | 2 +-
grove/plugin/plugin.go | 17 ++++++++++++++---
7 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/grove/README.md b/grove/README.md
index f8f669e..80062d2 100644
--- a/grove/README.md
+++ b/grove/README.md
@@ -66,6 +66,7 @@ The config file is JSON of the following format:
"port": 8080,
"cache_size_bytes": 50000,
"remap_rules_file": "./remap.json",
+ "plugins": ["ats_log", "http_stats", "if_modified_since", "record_stats"],
```
The config file has the following fields:
@@ -96,6 +97,7 @@ The config file has the following fields:
| `server_write_timeout_ms` | The length of time in milliseconds to allow a client to write data, before the connection is terminated. This value should be carefully considered, as too short a timeout will result in terminating legitimate clients with slow connections, while too long a timeout will make the server vulnerable to SlowLoris attacks.|
| `cache_files` | Groups of cache files to use for disk caching. See [Disk Cache](#disk-cache) |
| `file_mem_bytes` | The size in bytes of the memory cache to use for each group of cache files. Note this size is used for each group, and thus the total memory used is `file_mem_bytes*len(cache_files)+cache_size_bytes`. See [Disk Cache](#disk-cache) |
+| `plugins` | An array of plugins to enable |
# Remap Rules
diff --git a/grove/config/config.go b/grove/config/config.go
index c282e47..857d4f6 100644
--- a/grove/config/config.go
+++ b/grove/config/config.go
@@ -47,6 +47,8 @@ type Config struct {
LogLocationDebug string `json:"log_location_debug"`
LogLocationEvent string `json:"log_location_event"`
+ Plugins []string `json:"plugins"`
+
ReqTimeoutMS int `json:"parent_request_timeout_ms"` // TODO rename "parent_request" to distinguish from client requests
ReqKeepAliveMS int `json:"parent_request_keep_alive_ms"`
ReqMaxIdleConns int `json:"parent_request_max_idle_connections"`
diff --git a/grove/grove.cfg b/grove/grove.cfg
index 3f0a3fe..25ad0cb 100644
--- a/grove/grove.cfg
+++ b/grove/grove.cfg
@@ -2,7 +2,8 @@
"rfc_compliant": false,
"port": 8080,
"cache_size_bytes": 50000,
- "remap_rules_file": "./remap.json"
+ "remap_rules_file": "./remap.json",
+ "plugins": ["ats_log", "http_stats", "if_modified_since", "record_stats"],
"log_location_error": "/var/log/grove/grove.log",
"log_location_event": "/var/log/grove/access.log",
"log_location_warn": "/var/log/grove/grove.log"
diff --git a/grove/grove.go b/grove/grove.go
index a610d46..55dc2ee 100644
--- a/grove/grove.go
+++ b/grove/grove.go
@@ -93,7 +93,7 @@ func main() {
reqIdleConnTimeout := time.Duration(cfg.ReqIdleConnTimeoutMS) * time.Millisecond
baseTransport := remap.NewRemappingTransport(reqTimeout, reqKeepAlive, reqMaxIdleConns, reqIdleConnTimeout)
- plugins := plugin.Get()
+ plugins := plugin.Get(cfg.Plugins)
remapper, err := remap.LoadRemapper(cfg.RemapRulesFile, plugins.LoadFuncs(), caches, baseTransport)
if err != nil {
log.Errorf("starting service: loading remap rules: %v\n", err)
@@ -193,6 +193,7 @@ func main() {
log.Warnln("reloading config: caches changed in new config! Dynamic cache reloading is not supported! Old cache files and sizes will be used, and new cache config will NOT be loaded! Restart service to apply cache changes!")
}
+ plugins = plugin.Get(cfg.Plugins)
oldRemapper := remapper
remapper, err = remap.LoadRemapper(cfg.RemapRulesFile, plugins.LoadFuncs(), caches, baseTransport)
if err != nil {
@@ -254,6 +255,8 @@ func main() {
)
httpsHandler.Set(httpsCacheHandler)
+ plugins.OnStartup(remapper.PluginCfg(), pluginContext, plugin.StartupData{Config: cfg, Shared: remapper.PluginSharedCfg()})
+
if cfg.Port != oldCfg.Port {
ctx, cancel := context.WithTimeout(context.Background(), ShutdownTimeout)
defer cancel()
diff --git a/grove/plugin/hello_context.go b/grove/plugin/hello_context.go
index eb16223..69ffce5 100644
--- a/grove/plugin/hello_context.go
+++ b/grove/plugin/hello_context.go
@@ -19,7 +19,7 @@ import (
)
func init() {
- // AddPlugin(10000, Funcs{startup: helloCtxStart, afterRespond: helloCtxAfterResp})
+ AddPlugin(10000, Funcs{startup: helloCtxStart, afterRespond: helloCtxAfterResp})
}
func helloCtxStart(icfg interface{}, d StartupData) {
diff --git a/grove/plugin/hello_world.go b/grove/plugin/hello_world.go
index 9682a08..6e3f811 100644
--- a/grove/plugin/hello_world.go
+++ b/grove/plugin/hello_world.go
@@ -19,7 +19,7 @@ import (
)
func init() {
- // AddPlugin(10000, Funcs{startup: hello})
+ AddPlugin(10000, Funcs{startup: hello})
}
func hello(icfg interface{}, d StartupData) {
diff --git a/grove/plugin/plugin.go b/grove/plugin/plugin.go
index 140c4e4..b084fef 100644
--- a/grove/plugin/plugin.go
+++ b/grove/plugin/plugin.go
@@ -132,9 +132,20 @@ func (p pluginsSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
var plugins = pluginsSlice{}
-func Get() Plugins {
- sort.Sort(plugins)
- return pluginsSlice(plugins)
+func Get(enabled []string) Plugins {
+ enabledM := map[string]struct{}{}
+ for _, name := range enabled {
+ enabledM[name] = struct{}{}
+ }
+ enabledPlugins := pluginsSlice{}
+ for _, plugin := range plugins {
+ if _, ok := enabledM[plugin.name]; !ok {
+ continue
+ }
+ enabledPlugins = append(enabledPlugins, plugin)
+ }
+ sort.Sort(enabledPlugins)
+ return enabledPlugins
}
type Plugins interface {
--
To stop receiving notification emails like this one, please contact
jvd@apache.org.