Skip to content

Commit

Permalink
Push special devel branch with enabled logging on query steps
Browse files Browse the repository at this point in the history
  • Loading branch information
spacehamster87 committed Jun 25, 2024
1 parent 0297e6d commit 5be5c2e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions memstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"sync"
"unsafe"
"log"
)

// Default buffer capacity.
Expand Down Expand Up @@ -434,6 +435,9 @@ func (m *MemoryStore) WriteToLevel(l *level, selector []string, ts int64, metric
// The second and third return value are the actual from/to for the data. Those can be different from
// the range asked for if no data was available.
func (m *MemoryStore) Read(selector Selector, metric string, from, to int64) ([]Float, int64, int64, error) {

log.Printf(">>>> HELLO CCMS READ <<<<")

if from > to {
return nil, 0, 0, errors.New("invalid time range")
}
Expand All @@ -443,6 +447,8 @@ func (m *MemoryStore) Read(selector Selector, metric string, from, to int64) ([]
return nil, 0, 0, errors.New("unkown metric: " + metric)
}

log.Printf(">>>> CCMS READ : READ METRIC >>>> %s", metric)

n, data := 0, make([]Float, (to-from)/minfo.Frequency+1)
err := m.root.findBuffers(selector, minfo.offset, func(b *buffer) error {
cdata, cfrom, cto, err := b.read(from, to, data)
Expand All @@ -452,7 +458,10 @@ func (m *MemoryStore) Read(selector Selector, metric string, from, to int64) ([]

if n == 0 {
from, to = cfrom, cto
log.Printf(">>>> CCMS READ : SET FROM/TO >>>> %d - %d", from, to)
} else if from != cfrom || to != cto || len(data) != len(cdata) {

log.Printf(">>>> CCMS READ : UNMATCHING DATASIZE/TIMES")
missingfront, missingback := int((from-cfrom)/minfo.Frequency), int((to-cto)/minfo.Frequency)
if missingfront != 0 {
return ErrDataDoesNotAlign
Expand All @@ -470,6 +479,7 @@ func (m *MemoryStore) Read(selector Selector, metric string, from, to int64) ([]
from, to = cfrom, cto
}

log.Printf(">>>> CCMS READ >>>> SET DATA")
data = cdata
n += 1
return nil
Expand All @@ -478,6 +488,7 @@ func (m *MemoryStore) Read(selector Selector, metric string, from, to int64) ([]
if err != nil {
return nil, 0, 0, err
} else if n == 0 {
log.Printf(">>>> CCMS READ : ERROR RETURN >>>> 'n == 0' : %d", n)
return nil, 0, 0, errors.New("metric or host not found")
} else if n > 1 {
if minfo.Aggregation == AvgAggregation {
Expand Down
32 changes: 32 additions & 0 deletions selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"errors"
"log"
)

type SelectorElement struct {
Expand Down Expand Up @@ -70,54 +71,85 @@ func (l *level) findBuffers(selector Selector, offset int, f func(b *buffer) err
l.lock.RLock()
defer l.lock.RUnlock()

log.Printf(">>>> HELLO FINDBUFFERS <<<<")
log.Printf(">>>> FINDBUFFERS : FOR SELECTOR >>>> %v", selector)
// log.Printf(">>>> FINDBUFFERS : FOR OFFSET >>>> %d", offset)

if len(selector) == 0 {
b := l.metrics[offset]
if b != nil {
log.Printf(">>>> FINDBUFFERS : SELECTOR ARRAY EMPTY >>>> FOUND BUFFER AT METRICS OFFSET %d", offset)
log.Printf(">>>> FINDBUFFERS : END RECURSIVE FINDBUFFERS >>>> RETURN BUFFER")
return f(b)
}

for _, lvl := range l.children {
log.Printf(">>>> FINDBUFFERS : SELECTOR ARRAY EMPTY >>>> ITERATING LEVEL >>>> %v", lvl)
err := lvl.findBuffers(nil, offset, f)
if err != nil {
return err
}
}

log.Printf(">>>> FINDBUFFERS : SELECTOR ARRAY EMPTY >>>> NO BUFFER MATCHED")
log.Printf(">>>> FINDBUFFERS : END RECURSIVE FINDBUFFERS >>>> RETURN NIL")
return nil
}

sel := selector[0]

log.Printf(">>>> FINDBUFFERS : LEVEL CHILDREN >>>> NOT NIL : %v", (l.children != nil))
// log.Printf(">>>> FINDBUFFERS : SELECTOR ELEMENT @ INDEX 0 >>>> %v", sel)

log.Printf(">>>> FINDBUFFERS : SELECTOR ELEMENT >>>> STRING : %s", sel.String)
if len(sel.String) != 0 && l.children != nil {
// log.Printf(">>>> FINDBUFFERS : NAMED SELECTOR && CHILDREN AVAILABLE")
lvl, ok := l.children[sel.String]
if ok {
log.Printf(">>>> FINDBUFFERS : NAMED >>>> LOOKUP CHILDREN")
log.Printf(">>>> FINDBUFFERS : NAMED >>>> DO RECURSIVE FINDBUFFERS")
err := lvl.findBuffers(selector[1:], offset, f)
if err != nil {
log.Printf(">>>> FINDBUFFERS : NAMED >>>> RECURSIVE ERROR >>>> $s", err)

Check failure on line 113 in selector.go

View workflow job for this annotation

GitHub Actions / test

log.Printf call has arguments but no formatting directives
return err
}
}
return nil
}

log.Printf(">>>> FINDBUFFERS : SELECTOR ELEMENT >>>> GROUP : %v", sel.Group)
if sel.Group != nil && l.children != nil {
// log.Printf(">>>> FINDBUFFERS : GROUP && CHILDREN AVAILABLE")
for _, key := range sel.Group {
lvl, ok := l.children[key]
if ok {
log.Printf(">>>> FINDBUFFERS : GROUP >>>> LOOKUP CHILDREN FOR GROUPKEY >>>> %s", key)
log.Printf(">>>> FINDBUFFERS : GROUP >>>> DO RECURSIVE FINDBUFFERS")
err := lvl.findBuffers(selector[1:], offset, f)
if err != nil {
log.Printf(">>>> FINDBUFFERS : GROUP >>>> RECURSIVE ERROR >>>> $s", err)

Check failure on line 130 in selector.go

View workflow job for this annotation

GitHub Actions / test

log.Printf call has arguments but no formatting directives
return err
}
}
}
log.Printf(">>>> FINDBUFFERS : GROUP >>>> RETURN NIL")
return nil
}

log.Printf(">>>> FINDBUFFERS : SELECTOR ELEMENT >>>> IS ANY : %v", sel.Any)
if sel.Any && l.children != nil {
// log.Printf(">>>> FINDBUFFERS : ENABLED ANY && CHILDREN AVAILABLE")
for _, lvl := range l.children {
log.Printf(">>>> FINDBUFFERS : ANY >>>> DO RECURSIVE FINDBUFFERS")
if err := lvl.findBuffers(selector[1:], offset, f); err != nil {
log.Printf(">>>> FINDBUFFERS : ANY >>>> RECURSIVE ERROR >>>> $s", err)

Check failure on line 145 in selector.go

View workflow job for this annotation

GitHub Actions / test

log.Printf call has arguments but no formatting directives
return err
}
}
log.Printf(">>>> FINDBUFFERS : ANY >>>> RETURN NIL")
return nil
}

log.Printf(">>>> FINDBUFFERS : NO MATCHED CASE >>>> RETURN NIL")
return nil
}

0 comments on commit 5be5c2e

Please sign in to comment.