Created
July 11, 2018 09:53
-
-
Save develar/fdba772411cb2391f466a8723982c772 to your computer and use it in GitHub Desktop.
logspout-several-file-name-filters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: httpstream/httpstream.go | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- httpstream/httpstream.go (date 1531296303000) | |
+++ httpstream/httpstream.go (date 1531295667000) | |
@@ -38,7 +38,7 @@ | |
route.FilterID = route.FilterID[:12] | |
} | |
case "name": | |
- route.FilterName = params["value"] | |
+ route.FilterNames = []string{params["value"]} | |
} | |
} | |
Index: logspout.go | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- logspout.go (date 1531296303000) | |
+++ logspout.go (date 1531295977000) | |
@@ -61,7 +61,7 @@ | |
fmt.Fprintf(w, "# %s\t%s\t%s\t%s\t%s\n", | |
route.Adapter, | |
route.Address, | |
- route.FilterID+route.FilterName+strings.Join(route.FilterLabels, ","), | |
+ route.FilterID+strings.Join(route.FilterNames, ",")+strings.Join(route.FilterLabels, ","), | |
strings.Join(route.FilterSources, ","), | |
route.Options) | |
} | |
Index: router/routes.go | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- router/routes.go (date 1531296303000) | |
+++ router/routes.go (date 1531298004000) | |
@@ -98,13 +98,19 @@ | |
if err != nil { | |
return err | |
} | |
+ | |
+ filterNames := params["filter.name"] | |
+ if filterNames == nil { | |
+ r.FilterNames = make([]string, 0) | |
+ } else { | |
+ r.FilterNames = filterNames | |
+ } | |
+ | |
for key := range params { | |
value := params.Get(key) | |
switch key { | |
case "filter.id": | |
r.FilterID = value | |
- case "filter.name": | |
- r.FilterName = value | |
case "filter.labels": | |
r.FilterLabels = strings.Split(value, ",") | |
case "filter.sources": | |
Index: router/pump_test.go | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- router/pump_test.go (date 1531296303000) | |
+++ router/pump_test.go (date 1531298884000) | |
@@ -74,6 +74,54 @@ | |
} | |
} | |
+func TestPumpIgnoreContainerByExactName(t *testing.T) { | |
+ containers := []struct { | |
+ name string | |
+ out bool | |
+ }{ | |
+ {"bar", false}, | |
+ {"foo", true}, | |
+ } | |
+ | |
+ route := &Route{ | |
+ ID: "abc", | |
+ Address: "someUrl", | |
+ Adapter: "syslog", | |
+ FilterNames: []string{"foo"}, | |
+ } | |
+ | |
+ labels := make(map[string]string) | |
+ for _, conf := range containers { | |
+ if actual := route.MatchContainer("container-id", conf.name, labels); actual != conf.out { | |
+ t.Errorf("expected %v got %v", conf.out, actual) | |
+ } | |
+ } | |
+} | |
+ | |
+func TestPumpIgnoreContainerByNamePattern(t *testing.T) { | |
+ containers := []struct { | |
+ name string | |
+ out bool | |
+ }{ | |
+ {"bar-79c6", false}, | |
+ {"foo-87f5", true}, | |
+ } | |
+ | |
+ route := &Route{ | |
+ ID: "abc", | |
+ Address: "someUrl", | |
+ Adapter: "syslog", | |
+ FilterNames: []string{"foo-*"}, | |
+ } | |
+ | |
+ labels := make(map[string]string) | |
+ for _, conf := range containers { | |
+ if actual := route.MatchContainer("container-id", conf.name, labels); actual != conf.out { | |
+ t.Errorf("expected %v got %v", conf.out, actual) | |
+ } | |
+ } | |
+} | |
+ | |
func TestPumpIgnoreContainerAllowTTYDefault(t *testing.T) { | |
containers := []struct { | |
in *docker.Config | |
Index: router/types.go | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- router/types.go (date 1531296303000) | |
+++ router/types.go (date 1531298465000) | |
@@ -60,14 +60,14 @@ | |
type Route struct { | |
ID string `json:"id"` | |
FilterID string `json:"filter_id,omitempty"` | |
- FilterName string `json:"filter_name,omitempty"` | |
+ FilterNames []string `json:"filter_names,omitempty"` | |
FilterSources []string `json:"filter_sources,omitempty"` | |
FilterLabels []string `json:"filter_labels,omitempty"` | |
Adapter string `json:"adapter"` | |
Address string `json:"address"` | |
Options map[string]string `json:"options,omitempty"` | |
adapter LogAdapter | |
- closed bool | |
+ closed bool | |
closer chan bool | |
closerRcv <-chan bool // used instead of closer when set | |
} | |
@@ -105,7 +105,7 @@ | |
} | |
func (r *Route) matchAll() bool { | |
- if r.FilterID == "" && r.FilterName == "" && len(r.FilterSources) == 0 && len(r.FilterLabels) == 0 { | |
+ if r.FilterID == "" && len(r.FilterNames) == 0 && len(r.FilterSources) == 0 && len(r.FilterLabels) == 0 { | |
return true | |
} | |
return false | |
@@ -113,7 +113,12 @@ | |
// MultiContainer returns whether the Route is matching multiple containers or not | |
func (r *Route) MultiContainer() bool { | |
- return r.matchAll() || strings.Contains(r.FilterName, "*") | |
+ for _, name := range r.FilterNames { | |
+ if strings.Contains(name, "*") { | |
+ return true | |
+ } | |
+ } | |
+ return r.matchAll() | |
} | |
// MatchContainer returns whether the Route is responsible for a given container | |
@@ -124,10 +129,17 @@ | |
if r.FilterID != "" && !strings.HasPrefix(id, r.FilterID) { | |
return false | |
} | |
- match, err := path.Match(r.FilterName, name) | |
- if err != nil || (r.FilterName != "" && !match) { | |
+ | |
+ if len(r.FilterNames) > 0 { | |
+ for _, pattern := range r.FilterNames { | |
+ match, _ := path.Match(pattern, name) | |
+ if match { | |
+ return true | |
+ } | |
+ } | |
return false | |
} | |
+ | |
for _, label := range r.FilterLabels { | |
labelParts := strings.SplitN(label, ":", 2) | |
if len(labelParts) > 1 { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment