summaryrefslogtreecommitdiff
path: root/stasherpresent.slide
blob: f9e7abac020251cd02b44b71f6eb66fac64d1828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
Stasher

Prototyping a logstash alternative
23 February 2017

Silvan Jegen
me@sillymon.ch
https://sillymon.ch


* Logstash

.image img/icon-logstash-bb.png
.caption logstash logo from the [[https://www.elastic.co/products/logstash][official logstash site]]


* What is it and what does it do?

"Centralize, Transform & Stash your data"

.image img/logstash-overview.png


* "Centralize, Transform & Stash"

- "Inputs" from Log files, DBs, HTTP
- "Filters" for cleaning and transforming
- "Outputs" for archiving, alerting, monitoring, etc.

Using text-based formats as the data representation


* "Centralize, Transform & Stash"

Plugins

- Inputs: file, syslog, redis, ...
- Filters: grok, mutate, drop, ...
- Outputs: elasticsearch, file, graphite, email, ...


* How does it work?

Custom configuration language

	input { stdin {} }

	filter {
	  anonymize {
		algorithm => "SHA256"
		fields => ["field1", "field2"]
		key => "something"
	  }
	}

	output {
	  elasticsearch {
		hosts => ["localhost:9200"]
	  }

	  csv {
		fields => ["field1", "[nested][field]"]
		path => "./test-%{+YYYY-MM-dd}.txt"
	  }
	}


* Plugins

	filter {
	  anonymize {
		algorithm => "SHA256"
		fields => ["field1", "field2"]
		key => "something"
	  }
	}


* Stasher


* Stasher

Why?

- Apparently Logstash is very slow
- Generality of the work flow
- I like Go

Code available at
.link https://sillymon.ch/cgit/stasher/ https://sillymon.ch/cgit/stasher/


* Implementation


* Implementation

1. Interfaces
2. Manager
3. Especially unfinished stuff: error handling, config parser and the Registry


* Interfaces

{input,filter,output}/interface.go

	type Input interface {
	        Start() chan *work.Work
	}


	type Filter interface {
	        Filter(*work.Work) *work.Work
	}


	type Output interface {
	        Output(*work.Work) error
	}


* Manager

manager/manager.go

	type Manager struct {
	        Input  input.Input
	        Filter filter.Filter
	        Output output.Output
	}


* Manager

	func (m *Manager) Run() {
	        var wg sync.WaitGroup
	        ic := m.Input.Start()
	        for w := range ic {
	                if w.Error() != nil {
	                        fmt.Printf("Got an error when getting Work input: %q\n", w.Error())
	                        continue
	                }
	                wg.Add(1)
	                go func(w *work.Work) {
	                        nw := m.Filter.Filter(w)
	                        err := nw.Error()
	                        if err != nil {
	                                fmt.Printf("Got an error when filtering Work: %q\n", err)
	                        }
	                        err = m.Output.Output(nw)
	                        if err != nil {
	                                fmt.Printf("Got an error when outputting Work: %q\n", err)
	                        }
	                        wg.Done()
	                }(w)
	        }
	        wg.Wait()
	}


* Main advantages over shell script

- Error handling
- Declarative config


* Error handling

        for w := range ic {
                if w.Error() != nil {
                        fmt.Printf("Got an error when getting Work input: %q\n", w.Error())
                        continue
                }
                wg.Add(1)
                go func(w *work.Work) {
                        nw := m.Filter.Filter(w)
                        err := nw.Error()
                        if err != nil {
                                fmt.Printf("Got an error when filtering Work: %q\n", err)
                        }
                        err = m.Output.Output(nw)
                        if err != nil {
                                fmt.Printf("Got an error when outputting Work: %q\n", err)
                        }
                        wg.Done()
                }(w)
        }


* Config parser

- Currently only supports string literals (no arrays)
- Hand-written parser
- Uses the Registry to get the modules


* Registry

registry/registry.go

	var (
	        Inputregistry  map[string]func(map[string]string) input.Input
	        Filterregistry map[string]func(map[string]string) filter.Filter
	        Outputregistry map[string]func(map[string]string) output.Output
	)


* Registry

input/http/http.go

	func init() {
	        registry.Inputregistry["http"] = New
	}


* Registry

conf/init.go

	import (
	        // Initialize the different modules. By importing them in this
	        // way, their constructors are registered in the registry.
	        _ "github.com/Shugyousha/stasher/input/http"
	        _ "github.com/Shugyousha/stasher/input/stdin"

	        _ "github.com/Shugyousha/stasher/filter/http"
	        _ "github.com/Shugyousha/stasher/filter/str"

	        _ "github.com/Shugyousha/stasher/output/http"
	        _ "github.com/Shugyousha/stasher/output/stdout"
	)


* Implemented modules

- input: stdin, http
- filter: str(ing), http
- output: stdout, http


* Demo (a.k.a. "It totally works, I swear!")


* High-level TODOs

- Watch input directories
- Multiple modules for each main module
- Proper (configurable?) error handling


* Considerations & Conclusions

- Generality and error handling
- Use HTTP for everything?
- Level of "declarativeness" in the configuration
- Still better off with shell scripts?