Skip to content

Commit

Permalink
Merge pull request vmware-archive#58 from ocadotechnology/namespacing
Browse files Browse the repository at this point in the history
feat: add stdout namespacing
  • Loading branch information
timothysc authored May 16, 2018
2 parents c426e1e + 290dcaa commit e585d5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
4 changes: 3 additions & 1 deletion sinks/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func ManufactureSink() (e EventSinkInterface) {
case "glog":
e = NewGlogSink()
case "stdout":
e = NewStdoutSink()
viper.SetDefault("stdoutJSONNamespace", "")
stdoutNamespace := viper.GetString("stdoutJSONNamespace")
e = NewStdoutSink(stdoutNamespace)
case "http":
url := viper.GetString("httpSinkUrl")
if url == "" {
Expand Down
25 changes: 19 additions & 6 deletions sinks/stdoutsink.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,34 @@ import (
// can be queried in Kibana.
type StdoutSink struct {
// TODO: create a channel and buffer for scaling
namespace string
}


// NewStdoutSink will create a new StdoutSink with default options, returned as
// an EventSinkInterface
func NewStdoutSink() EventSinkInterface {
return &StdoutSink{}
func NewStdoutSink(namespace string) EventSinkInterface {
return &StdoutSink{
namespace: namespace}
}

// UpdateEvents implements the EventSinkInterface
func (gs *StdoutSink) UpdateEvents(eNew *v1.Event, eOld *v1.Event) {
eData := NewEventData(eNew, eOld)

if eJSONBytes, err := json.Marshal(eData); err == nil {
fmt.Println(string(eJSONBytes))

if len(gs.namespace) > 0 {
namespacedData := map[string]interface{}{}
namespacedData[gs.namespace] = eData
if eJSONBytes, err := json.Marshal(namespacedData); err == nil {
fmt.Println(string(eJSONBytes))
} else {
fmt.Fprintf(os.Stderr, "Failed to json serialize event: %v", err)
}
} else {
fmt.Fprintf(os.Stderr, "Failed to json serialize event: %v", err)
if eJSONBytes, err := json.Marshal(eData); err == nil {
fmt.Println(string(eJSONBytes))
} else {
fmt.Fprintf(os.Stderr, "Failed to json serialize event: %v", err)
}
}
}

0 comments on commit e585d5d

Please sign in to comment.