func (s *TestSuite) aggregateSlowLog(input, output string, utcOffset time.Duration) (got event.Result, expect event.Result) {
	bytes, err := ioutil.ReadFile(path.Join(s.result, "/", output))
	if err != nil {
		l.Fatal(err)
	}
	expect = event.Result{}
	if err := json.Unmarshal(bytes, &expect); err != nil {
		l.Fatal(err)
	}

	file, err := os.Open(path.Join(s.sample, "/", input))
	if err != nil {
		l.Fatal(err)
	}
	p := parser.NewSlowLogParser(file, log.Options{})
	if err != nil {
		l.Fatal(err)
	}
	go p.Start()
	a := event.NewAggregator(s.examples, utcOffset, 10)
	for e := range p.EventChan() {
		f := query.Fingerprint(e.Query)
		id := query.Id(f)
		a.AddEvent(e, id, f)
	}
	got = a.Finalize()
	return got, expect
}
Exemple #2
0
func (s *TestSuite) parseSlowLog(filename string, o log.Options) []log.Event {
	file, err := os.Open(path.Join(s.sample, "/", filename))
	if err != nil {
		l.Fatal(err)
	}
	p := parser.NewSlowLogParser(file, o)
	if err != nil {
		l.Fatal(err)
	}
	got := []log.Event{}
	go p.Start()
	for e := range p.EventChan() {
		got = append(got, *e)
	}
	return got
}
Exemple #3
0
func (s *TestSuite) TestParseSlow023A(t *C) {
	filename := "slow023.log"
	o := log.Options{Debug: false}

	file, err := os.Open(path.Join(s.sample, "/", filename))
	if err != nil {
		l.Fatal(err)
	}
	p := parser.NewSlowLogParser(file, o)
	if err != nil {
		l.Fatal(err)
	}
	go p.Start()
	lastQuery := ""
	for e := range p.EventChan() {
		if e.Query == "" {
			t.Errorf("Empty query at offset: %d. Last valid query: %s\n", e.Offset, lastQuery)
		} else {
			lastQuery = e.Query
		}
	}
}