Skip to content

Commit d6796d7

Browse files
Release 1.2.4 (#308)
* added 'drop_warn_threshold' config in tile (#300) * Upgrading the OAuth dependency to resolve the auth issue * Added a troubleshooting item for the auth issue with special characters * Drain the response buffer to reuse the connection with HEC * Changed eventwriter to write events on stdout in debug mode * Added a test for debug mode * Added/updated testcases to increase coverage * updated eventsink tests * fixed race condition in eventsink test * Updated the nozzle version set in HEC req header * Corrected version in test * Updated version in readme Co-authored-by: harshit-splunk <[email protected]>
1 parent 1c57b52 commit d6796d7

File tree

194 files changed

+34669
-12318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+34669
-12318
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ Each instance of the Splunk Firehose Nozzle will run with a randomly generated U
398398
index=main | stats count as total_events, min(nozzle-event-counter) as min_number, max(nozzle-event-counter) as max_number by uuid | eval event_number = max_number - min_number | eval success_percentage = total_events/event_number*100 | stats max(success_percentage) by uuid
399399
</pre>
400400
401+
### 6. Authentication is not working even if correct CF Client ID/secret is configured: (applicable in v1.2.3)
402+
403+
Due to a known issue in an indirect dependency (an OAuth library), if the client secret has any special characters (eg. *!#$&@^) then it will not work. For now, user has to configure a client secret without any of this characters. Once the library in question is updated in the next release it will work even with the special characters.
404+
401405
#### Searching Events
402406
403407
Here are two short Splunk queries to start exploring some of the Cloud Foundry events in Splunk.
@@ -442,7 +446,7 @@ $ chmod +x tools/nozzle.sh
442446
Build project:
443447
444448
```
445-
$ make VERSION=1.2.3
449+
$ make VERSION=1.2.4
446450
```
447451
448452
Run tests with [Ginkgo](http://onsi.github.io/ginkgo/)

cache/cache_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var _ = Describe("Cache", func() {
3232
MissingAppCacheTTL: missingAppCacheTTL,
3333
OrgSpaceCacheTTL: orgSpaceCacheTTL,
3434
Logger: lager.NewLogger("test"),
35+
AppLimits: n,
3536
}
3637

3738
client *testing.AppClientMock = nil
@@ -104,6 +105,22 @@ var _ = Describe("Cache", func() {
104105
})
105106
})
106107

108+
Context("When orphan app is requested", func() {
109+
110+
It("Should found app in cache", func() {
111+
app_guid := "orphan_app_id"
112+
client.CreateApp(app_guid, "orphan_space_id")
113+
Ω(cache.GetApp(app_guid)).NotTo(Equal(nil))
114+
client.DeleteApp(app_guid)
115+
cache.ManuallyInvalidateCaches()
116+
117+
app, err := cache.GetApp(app_guid)
118+
Ω(err).ShouldNot(HaveOccurred())
119+
Expect(app).NotTo(Equal(nil))
120+
Expect(app.Guid).To(Equal(app_guid))
121+
})
122+
})
123+
107124
Context("Cache invalidation", func() {
108125
BeforeEach(func() {
109126
// close the cache created in the outer BeforeEach

eventsink/splunk_test.go

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package eventsink_test
22

33
import (
4+
"fmt"
5+
"os"
46
"strconv"
57
"time"
68

@@ -32,6 +34,7 @@ var _ = Describe("Splunk", func() {
3234

3335
memSink *testing.MemorySinkMock
3436
sink *eventsink.Splunk
37+
config *eventsink.SplunkConfig
3538

3639
event map[string]interface{}
3740
logger lager.Logger
@@ -68,18 +71,63 @@ var _ = Describe("Splunk", func() {
6871
mockClient2 = &testing.EventWriterMock{}
6972

7073
logger = lager.NewLogger("test")
71-
config := &eventsink.SplunkConfig{
72-
FlushInterval: time.Millisecond,
73-
QueueSize: 1000,
74-
BatchSize: 1,
75-
Retries: 1,
76-
Hostname: "localhost",
77-
ExtraFields: map[string]string{"env": "dev", "test": "field"},
78-
UUID: "0a956421-f2e1-4215-9d88-d15633bb3023",
79-
Logger: logger,
74+
config = &eventsink.SplunkConfig{
75+
FlushInterval: time.Millisecond,
76+
QueueSize: 1000,
77+
BatchSize: 1,
78+
Retries: 1,
79+
Hostname: "localhost",
80+
ExtraFields: map[string]string{"env": "dev", "test": "field"},
81+
UUID: "0a956421-f2e1-4215-9d88-d15633bb3023",
82+
Logger: logger,
83+
DropWarnThreshold: 1000,
8084
}
8185
sink = eventsink.NewSplunk([]eventwriter.Writer{mockClient, mockClient2}, config)
8286
})
87+
Context("When LogStatus is executed", func() {
88+
BeforeEach(func() {
89+
config.StatusMonitorInterval = time.Second * 1
90+
flushInterval := time.Second * 2
91+
config.FlushInterval = flushInterval
92+
file, _ := os.OpenFile("lager.log", os.O_CREATE|os.O_RDWR, 0600)
93+
loggerSink := lager.NewReconfigurableSink(lager.NewWriterSink(file, lager.DEBUG), lager.DEBUG)
94+
myLogger := lager.NewLogger("LogStatus")
95+
myLogger.RegisterSink(loggerSink)
96+
config.Logger = myLogger
97+
defer file.Close()
98+
go sink.LogStatus()
99+
// low pressure
100+
for i := 0; i < int(float64(config.QueueSize)*0.12); i++ {
101+
sink.Write(make(map[string]interface{}), fmt.Sprintf("event %d", i))
102+
}
103+
// medium pressure
104+
time.Sleep(flushInterval)
105+
for i := 0; i < int(float64(config.QueueSize)*0.40); i++ {
106+
sink.Write(make(map[string]interface{}), fmt.Sprintf("event %d", i))
107+
}
108+
time.Sleep(flushInterval)
109+
// high pressure
110+
for i := 0; i < int(float64(config.QueueSize)*0.40); i++ {
111+
sink.Write(make(map[string]interface{}), fmt.Sprintf("event %d", i))
112+
}
113+
time.Sleep(flushInterval)
114+
// too high pressure
115+
for i := 0; i < int(float64(config.QueueSize)*0.08); i++ {
116+
sink.Write(make(map[string]interface{}), fmt.Sprintf("event %d", i))
117+
}
118+
time.Sleep(flushInterval)
119+
})
120+
121+
It("tests pressure status", func() {
122+
data, _ := os.ReadFile("lager.log")
123+
log := string(data)
124+
Expect(log).Should(ContainSubstring("status\":\"too high"))
125+
Expect(log).Should(ContainSubstring("status\":\"high"))
126+
Expect(log).Should(ContainSubstring("status\":\"medium"))
127+
Expect(log).Should(ContainSubstring("status\":\"low"))
128+
os.Remove("lager.log")
129+
})
130+
})
83131

84132
It("sends events to client", func() {
85133
eventType = events.Envelope_Error

eventwriter/splunk.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9+
"io"
910
"io/ioutil"
1011
"net/http"
1112

@@ -19,6 +20,7 @@ type SplunkConfig struct {
1920
Index string
2021
Fields map[string]string
2122
SkipSSL bool
23+
Debug bool
2224

2325
Logger lager.Logger
2426
}
@@ -70,9 +72,14 @@ func (s *splunkClient) Write(events []map[string]interface{}) (error, uint64) {
7072
)
7173
}
7274
}
73-
bodyBytes := bodyBuffer.Bytes()
7475

75-
return s.send(&bodyBytes), count
76+
if s.config.Debug {
77+
bodyString := bodyBuffer.String()
78+
return s.dump(bodyString), count
79+
} else {
80+
bodyBytes := bodyBuffer.Bytes()
81+
return s.send(&bodyBytes), count
82+
}
7683
}
7784

7885
func (s *splunkClient) send(postBody *[]byte) error {
@@ -87,7 +94,7 @@ func (s *splunkClient) send(postBody *[]byte) error {
8794
//Add app headers for HEC telemetry
8895
//Todo: update static values with appName and appVersion variables
8996
req.Header.Set("__splunk_app_name", "Splunk Firehose Nozzle")
90-
req.Header.Set("__splunk_app_version", "1.2.2")
97+
req.Header.Set("__splunk_app_version", "1.2.4")
9198

9299
resp, err := s.httpClient.Do(req)
93100
if err != nil {
@@ -98,7 +105,17 @@ func (s *splunkClient) send(postBody *[]byte) error {
98105
if resp.StatusCode > 299 {
99106
responseBody, _ := ioutil.ReadAll(resp.Body)
100107
return errors.New(fmt.Sprintf("Non-ok response code [%d] from splunk: %s", resp.StatusCode, responseBody))
108+
} else {
109+
//Draining the response buffer, so that the same connection can be reused the next time
110+
io.Copy(ioutil.Discard, resp.Body)
101111
}
102112

103113
return nil
104114
}
115+
116+
//To dump the event on stdout instead of Splunk, in case of 'debug' mode
117+
func (s *splunkClient) dump(eventString string) error {
118+
fmt.Println(string(eventString))
119+
120+
return nil
121+
}

eventwriter/splunk_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ var _ = Describe("Splunk", func() {
104104
})
105105

106106
It("sets app appVersion", func() {
107-
appVersion := "1.2.2"
107+
appVersion := "1.2.4"
108108

109109
client := NewSplunk(config)
110110
events := []map[string]interface{}{}
@@ -209,6 +209,15 @@ var _ = Describe("Splunk", func() {
209209
Expect(err).To(BeNil())
210210
Expect(capturedRequest.URL.Path).To(Equal("/services/collector"))
211211
})
212+
213+
It("Writes to stdout in debug without error", func() {
214+
config.Debug = true
215+
client := NewSplunk(config)
216+
events := []map[string]interface{}{}
217+
err, _ := client.Write(events)
218+
219+
Expect(err).To(BeNil())
220+
})
212221
})
213222

214223
It("returns error on bad splunk host", func() {

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/cloudfoundry/sonde-go v0.0.0-20160804000546-81c3f6be579c
1212
github.com/gogo/protobuf v1.3.2
1313
github.com/google/uuid v0.0.0-20170728174318-281f560d28af
14-
github.com/gorilla/websocket v1.0.1-0.20160802133203-a69d25be2fe2
14+
github.com/gorilla/websocket v1.4.2
1515
github.com/mailru/easyjson v0.0.0-20160816214844-3d7eb5818bd5
1616
github.com/onsi/ginkgo v1.6.0
1717
github.com/onsi/gomega v1.4.3
@@ -32,18 +32,19 @@ require (
3232
github.com/davecgh/go-spew v1.1.1 // indirect
3333
github.com/elazarl/goproxy v0.0.0-20210801061803-8e322dfb79c4 // indirect
3434
github.com/elazarl/goproxy/ext v0.0.0-20210801061803-8e322dfb79c4 // indirect
35-
github.com/golang/protobuf v1.3.2 // indirect
35+
github.com/golang/protobuf v1.4.2 // indirect
3636
github.com/hpcloud/tail v1.0.0 // indirect
3737
github.com/mattn/go-isatty v0.0.14 // indirect
3838
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
3939
github.com/pkg/errors v0.8.1 // indirect
4040
github.com/sergi/go-diff v1.2.0 // indirect
4141
github.com/stretchr/testify v1.7.0 // indirect
4242
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect
43-
golang.org/x/oauth2 v0.0.0-20190130055435-99b60b757ec1 // indirect
43+
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1 // indirect
4444
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
4545
golang.org/x/text v0.3.6 // indirect
46-
google.golang.org/appengine v1.4.0 // indirect
46+
google.golang.org/appengine v1.6.6 // indirect
47+
google.golang.org/protobuf v1.25.0 // indirect
4748
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
4849
gopkg.in/fsnotify.v1 v1.4.7 // indirect
4950
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect

0 commit comments

Comments
 (0)