Skip to content

Commit

Permalink
wrote documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
eze-kiel committed Feb 24, 2021
1 parent e748a6a commit eb1ef11
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions slowql.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func init() {
re = regexp.MustCompile(`\[(.*?)\]`)
}

// GetNext returns the next query
// GetNext returns the next query.
func (p Parser) GetNext() (Query, error) {
var q Query
select {
Expand All @@ -58,14 +58,17 @@ func (p Parser) GetNext() (Query, error) {
return q, nil
}

// Fingerprint returns Query.query's MD5 fingerprint
// Fingerprint returns Query.query's MD5 fingerprint.
func (q Query) Fingerprint() string {
h := md5.New()
io.WriteString(h, q.Query)
return fmt.Sprintf("%x", h.Sum(nil))
}

// NewParser creates the stack channel and launches background goroutines
// NewParser returns a new slowql.Parser instance.
// It also starts everything needed to parse logs file, which are 2 goroutines.
// They do what they have to and require no interaction from the user. Once the
// job terminated, they end grace fully.
func NewParser(r io.Reader) *Parser {
var p Parser

Expand Down Expand Up @@ -135,16 +138,12 @@ func (p *Parser) scan() {

// consume consumes the received line to extract the informations, and send the
// Query object to the stack

// TODO(ezekiel): here do excatly the same thing as before, so instead of sending
// bloc, we could conusme the lines and return the query instead
func (p *Parser) consume() {
for {
select {
case bloc := <-p.rawBlocs:
var q Query

// consume each line of the bloc
for _, line := range bloc {
if strings.HasPrefix(line, "#") {
q.parseHeader(line)
Expand Down Expand Up @@ -188,7 +187,7 @@ func (q *Query) parseHeader(line string) {
logrus.Errorf("error converting %s to int: %s", parts[idx+1], err)
}
} else if strings.Contains(part, "id") {
q.ID, err = strconv.Atoi(parts[idx+1]) // TODO(ezekiel): this is gross, need to find an alternative
q.ID, err = strconv.Atoi(parts[idx+1]) // TODO(ezekiel): find an other way to get the ID, as the number of spaces can vary
if err != nil {
logrus.Errorf("error converting %s to int: %s", parts[idx+1], err)
}
Expand Down

0 comments on commit eb1ef11

Please sign in to comment.