summaryrefslogtreecommitdiff
path: root/stasherpresent.slide
blob: f293fb7ab8e19964ec6a89164e668f74c719e9a2 (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
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

- Interfaces
- "Manager"
- Error handling
- Config parser
- "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) {
				defer wg.Done()
				nw := m.Filter.Filter(w)
				err := nw.Error()
				if err != nil {
					fmt.Printf("Got an error when filtering Work: %q\n", err)
					return
				}
				err = m.Output.Output(nw)
				if err != nil {
					fmt.Printf("Got an error when outputting Work: %q\n", err)
				}
			}(w)
		}
		wg.Wait()
	}


* 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) {
			defer wg.Done()
			nw := m.Filter.Filter(w)
			err := nw.Error()
			if err != nil {
				fmt.Printf("Got an error when filtering Work: %q\n", err)
				return
			}
			err = m.Output.Output(nw)
			if err != nil {
				fmt.Printf("Got an error when outputting Work: %q\n", err)
			}
		}(w)
	}


* Config parser

- Hand-written parser
- Currently only supports string literals (no arrays)
- 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
	}


* Implemented modules

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


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


* TODOs

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


* Considerations & Conclusions

- Error handling and logging are important
- Use HTTP for everything?
- Level of "declarativeness" in the configuration
- Still better off with shell scripts and pipes?