Skip to content

Commit 18ed55b

Browse files
luckyj5rockb1017
andauthored
Metadata config filter (#251)
* add metadata fields configuration * app metadata filter Co-authored-by: Rock Baek <[email protected]>
1 parent 98f1e23 commit 18ed55b

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

eventrouter/default.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import (
99
"github.com/cloudfoundry/sonde-go/events"
1010
)
1111

12-
type Config struct {
13-
SelectedEvents string
14-
}
12+
type Config = fevents.Config
1513

1614
type router struct {
1715
appCache cache.Cache
1816
sink eventsink.Sink
1917
selectedEvents map[string]bool
18+
config *Config
2019
}
2120

2221
func New(appCache cache.Cache, sink eventsink.Sink, config *Config) (Router, error) {
@@ -30,6 +29,7 @@ func New(appCache cache.Cache, sink eventsink.Sink, config *Config) (Router, err
3029
appCache: appCache,
3130
sink: sink,
3231
selectedEvents: selectedEvents,
32+
config: config,
3333
}, nil
3434
}
3535

@@ -64,7 +64,7 @@ func (r *router) Route(msg *events.Envelope) error {
6464
event.AnnotateWithCFMetaData()
6565

6666
if _, hasAppId := event.Fields["cf_app_id"]; hasAppId {
67-
event.AnnotateWithAppData(r.appCache)
67+
event.AnnotateWithAppData(r.appCache, r.config)
6868
}
6969

7070
if ignored, ok := event.Fields["cf_ignored_app"]; ok {

events/events.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ type Event struct {
1818
Type string
1919
}
2020

21+
type Config struct {
22+
SelectedEvents string
23+
AddOrgName bool
24+
AddOrgGuid bool
25+
AddSpaceName bool
26+
AddSpaceGuid bool
27+
}
28+
2129
func HttpStartStop(msg *events.Envelope) *Event {
2230
httpStartStop := msg.GetHttpStartStop()
2331

@@ -125,7 +133,7 @@ func ContainerMetric(msg *events.Envelope) *Event {
125133
}
126134
}
127135

128-
func (e *Event) AnnotateWithAppData(appCache cache.Cache) {
136+
func (e *Event) AnnotateWithAppData(appCache cache.Cache, config *Config) {
129137
cf_app_id := e.Fields["cf_app_id"]
130138
appGuid := fmt.Sprintf("%s", cf_app_id)
131139

@@ -149,19 +157,19 @@ func (e *Event) AnnotateWithAppData(appCache cache.Cache) {
149157
e.Fields["cf_app_name"] = cf_app_name
150158
}
151159

152-
if cf_space_id != "" {
160+
if cf_space_id != "" && config.AddSpaceGuid {
153161
e.Fields["cf_space_id"] = cf_space_id
154162
}
155163

156-
if cf_space_name != "" {
164+
if cf_space_name != "" && config.AddSpaceName {
157165
e.Fields["cf_space_name"] = cf_space_name
158166
}
159167

160-
if cf_org_id != "" {
168+
if cf_org_id != "" && config.AddOrgGuid {
161169
e.Fields["cf_org_id"] = cf_org_id
162170
}
163171

164-
if cf_org_name != "" {
172+
if cf_org_name != "" && config.AddOrgName {
165173
e.Fields["cf_org_name"] = cf_org_name
166174
}
167175

events/events_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ var _ = Describe("Events", func() {
116116
Context("given Application Metadata", func() {
117117
It("Should give us the right Application metadata", func() {
118118
fcache.SetIgnoreApp(true)
119-
event.AnnotateWithAppData(fcache)
119+
var config = &fevents.Config {
120+
AddOrgName: true,
121+
AddOrgGuid: true,
122+
AddSpaceName: true,
123+
AddSpaceGuid: true,
124+
}
125+
event.AnnotateWithAppData(fcache, config)
120126
Expect(event.Fields["cf_app_name"]).To(Equal("testing-app"))
121127
Expect(event.Fields["cf_space_id"]).To(Equal("f964a41c-76ac-42c1-b2ba-663da3ec22d6"))
122128
Expect(event.Fields["cf_space_name"]).To(Equal("testing-space"))
@@ -127,7 +133,13 @@ var _ = Describe("Events", func() {
127133
})
128134

129135
It("HttpStartStop", func() {
130-
event.AnnotateWithAppData(fcache)
136+
var config = &fevents.Config {
137+
AddOrgName: true,
138+
AddOrgGuid: true,
139+
AddSpaceName: true,
140+
AddSpaceGuid: true,
141+
}
142+
event.AnnotateWithAppData(fcache, config)
131143
Expect(event.Fields["cf_app_name"]).To(Equal("testing-app"))
132144
Expect(event.Fields["cf_space_id"]).To(Equal("f964a41c-76ac-42c1-b2ba-663da3ec22d6"))
133145
Expect(event.Fields["cf_space_name"]).To(Equal("testing-space"))

splunknozzle/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ type Config struct {
3838
OrgSpaceCacheTTL time.Duration `json:"org-space-cache-ttl"`
3939
AppLimits int `json:"app-limits"`
4040

41+
// Add configuration option to filter/ choose from AppInfo
42+
AddOrgName bool `json:"add-org-name"`
43+
AddOrgGuid bool `json:"add-org-guid"`
44+
AddSpaceName bool `json:"add-space-name"`
45+
AddSpaceGuid bool `json:"add-space-guid"`
46+
4147
BoltDBPath string `json:"boltdb-path"`
4248
WantedEvents string `json:"wanted-events"`
4349
ExtraFields string `json:"extra-fields"`
@@ -106,6 +112,15 @@ func NewConfigFromCmdFlags(version, branch, commit, buildos string) *Config {
106112

107113
kingpin.Flag("add-app-info", "Query API to fetch app details").
108114
OverrideDefaultFromEnvar("ADD_APP_INFO").Default("false").BoolVar(&c.AddAppInfo)
115+
kingpin.Flag("add-org-name", "Add org name from app cache").
116+
OverrideDefaultFromEnvar("ADD_ORG_NAME").Default("true").BoolVar(&c.AddOrgName)
117+
kingpin.Flag("add-org-guid", "Add org guid from app cache").
118+
OverrideDefaultFromEnvar("ADD_ORG_GUID").Default("true").BoolVar(&c.AddOrgGuid)
119+
kingpin.Flag("add-space-name", "Add space name from app cache").
120+
OverrideDefaultFromEnvar("ADD_SPACE_NAME").Default("true").BoolVar(&c.AddSpaceName)
121+
kingpin.Flag("add-space-guid", "Add space guid from app cache").
122+
OverrideDefaultFromEnvar("ADD_SPACE_GUID").Default("true").BoolVar(&c.AddSpaceGuid)
123+
109124
kingpin.Flag("ignore-missing-app", "If app is missing, stop repeatedly querying app info from PCF").
110125
OverrideDefaultFromEnvar("IGNORE_MISSING_APP").Default("true").BoolVar(&c.IgnoreMissingApps)
111126
kingpin.Flag("missing-app-cache-invalidate-ttl", "How frequently the missing app info cache invalidates").
@@ -145,6 +160,7 @@ func NewConfigFromCmdFlags(version, branch, commit, buildos string) *Config {
145160
OverrideDefaultFromEnvar("DEBUG").Default("false").BoolVar(&c.Debug)
146161
kingpin.Flag("status-monitor-interval", "Print information for monitoring at every interval").
147162
OverrideDefaultFromEnvar("STATUS_MONITOR_INTERVAL").Default("0s").DurationVar(&c.StatusMonitorInterval)
163+
148164
kingpin.Parse()
149165
return c
150166
}

splunknozzle/nozzle.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func NewSplunkFirehoseNozzle(config *Config, logger lager.Logger) *SplunkFirehos
4141
func (s *SplunkFirehoseNozzle) EventRouter(cache cache.Cache, eventSink eventsink.Sink) (eventrouter.Router, error) {
4242
config := &eventrouter.Config{
4343
SelectedEvents: s.config.WantedEvents,
44+
AddOrgName: s.config.AddOrgName,
45+
AddOrgGuid: s.config.AddOrgGuid,
46+
AddSpaceName: s.config.AddSpaceName,
47+
AddSpaceGuid: s.config.AddSpaceGuid,
4448
}
4549
return eventrouter.New(cache, eventSink, config)
4650
}

0 commit comments

Comments
 (0)