Skip to content

Commit 25e5d49

Browse files
authored
Merge pull request #54 from NETWAYS/fix/optimizations
Some memory optimizations and more tests
2 parents 951d834 + ce486a4 commit 25e5d49

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

cmd/config_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cmd
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestConfig(t *testing.T) {
8+
c := cliConfig.NewClient()
9+
expected := "http://localhost:9600"
10+
if c.Url != "http://localhost:9600" {
11+
t.Error("\nActual: ", c.Url, "\nExpected: ", expected)
12+
}
13+
}

cmd/health.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,16 @@ var healthCmd = &cobra.Command{
144144
output string
145145
summary string
146146
rc int
147-
states []int
148147
stat logstash.Stat
149148
thresholds HealthThreshold
150149
fdstatus string
151150
heapstatus string
152151
cpustatus string
153152
)
154153

154+
// status + fdstatus + heapstatus + cpustatus = 4
155+
states := make([]int, 0, 4)
156+
155157
// Parse the thresholds into a central var since we need them later
156158
thresholds, err := parseHealthThresholds(cliHealthConfig)
157159
if err != nil {

cmd/pipeline.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ var pipelineCmd = &cobra.Command{
6666
output string
6767
summary string
6868
rc int
69-
states []int
7069
pp logstash.Pipeline
7170
thresholds PipelineThreshold
7271
perfList perfdata.PerfdataList
@@ -100,6 +99,8 @@ var pipelineCmd = &cobra.Command{
10099
check.ExitError(err)
101100
}
102101

102+
states := make([]int, 0, len(pp.Pipelines))
103+
103104
// Check status for each pipeline
104105
for name, pipe := range pp.Pipelines {
105106
inflightEvents := pipe.Events.In - pipe.Events.Out

internal/logstash/api_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package logstash
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
)
7+
8+
func TestUmarshallPipeline(t *testing.T) {
9+
10+
j := `{"host":"foobar","version":"7.17.8","http_address":"127.0.0.1:9600","id":"4","name":"test","ephemeral_id":"5","status":"green","snapshot":false,"pipeline":{"workers":2,"batch_size":125,"batch_delay":50},"pipelines":{"ansible-input":{"events":{"filtered":0,"duration_in_millis":0,"queue_push_duration_in_millis":0,"out":50,"in":100},"plugins":{"inputs":[{"id":"b","name":"beats","events":{"queue_push_duration_in_millis":0,"out":0}}],"codecs":[{"id":"plain","name":"plain","decode":{"writes_in":0,"duration_in_millis":0,"out":0},"encode":{"writes_in":0,"duration_in_millis":0}},{"id":"json","name":"json","decode":{"writes_in":0,"duration_in_millis":0,"out":0},"encode":{"writes_in":0,"duration_in_millis":0}}],"filters":[],"outputs":[{"id":"f","name":"redis","events":{"duration_in_millis":18,"out":50,"in":100}}]},"reloads":{"successes":0,"last_success_timestamp":null,"last_error":null,"last_failure_timestamp":null,"failures":0},"queue":{"type":"memory","events_count":0,"queue_size_in_bytes":0,"max_queue_size_in_bytes":0},"hash":"f","ephemeral_id":"f"}}}`
11+
12+
var pl Pipeline
13+
err := json.Unmarshal([]byte(j), &pl)
14+
15+
if err != nil {
16+
t.Error(err)
17+
}
18+
19+
if pl.Host != "foobar" {
20+
t.Error("\nActual: ", pl.Host, "\nExpected: ", "foobar")
21+
}
22+
23+
}
24+
25+
func TestUmarshallStat(t *testing.T) {
26+
27+
j := `{"host":"foobar","version":"7.17.8","status":"green","jvm":{"threads":{"count":50,"peak_count":51},"mem":{"heap_used_percent":20}},"process":{"open_file_descriptors": 120,"peak_open_file_descriptors": 120,"max_file_descriptors":16384,"cpu":{"percent": 1}}}`
28+
29+
var st Stat
30+
err := json.Unmarshal([]byte(j), &st)
31+
32+
if err != nil {
33+
t.Error(err)
34+
}
35+
36+
if st.Host != "foobar" {
37+
t.Error("\nActual: ", st.Host, "\nExpected: ", "foobar")
38+
}
39+
40+
}

0 commit comments

Comments
 (0)