-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessor.go
51 lines (41 loc) · 1.07 KB
/
processor.go
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
package main
import (
"compress/gzip"
"fmt"
"io"
"os"
)
type Processor struct {
LogFileReader *LogFileReader
MetricsSubmitter *MetricsSubmitter
}
func NewProcessor() (*Processor, error) {
var processor Processor
config, err := NewConfigFromFile(os.Getenv("CONFIG_PATH"))
if err != nil {
return nil, err
}
processor.LogFileReader = NewLogFileReader(config.PathTransformingRules, config.TargetPaths)
processor.MetricsSubmitter = NewMetricsSubmitter(config.RequestCountMetricName, config.TargetProcessingTimeMetricName, config.CustomTags)
return &processor, nil
}
func (p *Processor) ProcessLogfile(r io.Reader, s3ObjectKey string) error {
zr, err := gzip.NewReader(r)
if err != nil {
return err
}
defer zr.Close()
fmt.Println("start reading log file")
metricsMap, err := p.LogFileReader.Read(zr)
if err != nil {
return err
}
fmt.Println("finish reading log file")
fmt.Println("start submitting metrics")
err = p.MetricsSubmitter.Submit(metricsMap, s3ObjectKey)
if err != nil {
return err
}
fmt.Println("finish submitting metrics")
return nil
}