Push special devel branch with enabled logging on query steps

This commit is contained in:
Christoph Kluge 2024-06-25 14:02:27 +02:00
parent 0297e6d20d
commit 5be5c2ed74
2 changed files with 43 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"sync" "sync"
"unsafe" "unsafe"
"log"
) )
// Default buffer capacity. // Default buffer capacity.
@ -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 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. // the range asked for if no data was available.
func (m *MemoryStore) Read(selector Selector, metric string, from, to int64) ([]Float, int64, int64, error) { func (m *MemoryStore) Read(selector Selector, metric string, from, to int64) ([]Float, int64, int64, error) {
log.Printf(">>>> HELLO CCMS READ <<<<")
if from > to { if from > to {
return nil, 0, 0, errors.New("invalid time range") return nil, 0, 0, errors.New("invalid time range")
} }
@ -443,6 +447,8 @@ func (m *MemoryStore) Read(selector Selector, metric string, from, to int64) ([]
return nil, 0, 0, errors.New("unkown metric: " + metric) 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) n, data := 0, make([]Float, (to-from)/minfo.Frequency+1)
err := m.root.findBuffers(selector, minfo.offset, func(b *buffer) error { err := m.root.findBuffers(selector, minfo.offset, func(b *buffer) error {
cdata, cfrom, cto, err := b.read(from, to, data) cdata, cfrom, cto, err := b.read(from, to, data)
@ -452,7 +458,10 @@ func (m *MemoryStore) Read(selector Selector, metric string, from, to int64) ([]
if n == 0 { if n == 0 {
from, to = cfrom, cto 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) { } 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) missingfront, missingback := int((from-cfrom)/minfo.Frequency), int((to-cto)/minfo.Frequency)
if missingfront != 0 { if missingfront != 0 {
return ErrDataDoesNotAlign return ErrDataDoesNotAlign
@ -470,6 +479,7 @@ func (m *MemoryStore) Read(selector Selector, metric string, from, to int64) ([]
from, to = cfrom, cto from, to = cfrom, cto
} }
log.Printf(">>>> CCMS READ >>>> SET DATA")
data = cdata data = cdata
n += 1 n += 1
return nil return nil
@ -478,6 +488,7 @@ func (m *MemoryStore) Read(selector Selector, metric string, from, to int64) ([]
if err != nil { if err != nil {
return nil, 0, 0, err return nil, 0, 0, err
} else if n == 0 { } 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") return nil, 0, 0, errors.New("metric or host not found")
} else if n > 1 { } else if n > 1 {
if minfo.Aggregation == AvgAggregation { if minfo.Aggregation == AvgAggregation {

View File

@ -3,6 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"log"
) )
type SelectorElement struct { type SelectorElement struct {
@ -70,54 +71,85 @@ func (l *level) findBuffers(selector Selector, offset int, f func(b *buffer) err
l.lock.RLock() l.lock.RLock()
defer l.lock.RUnlock() 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 { if len(selector) == 0 {
b := l.metrics[offset] b := l.metrics[offset]
if b != nil { 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) return f(b)
} }
for _, lvl := range l.children { for _, lvl := range l.children {
log.Printf(">>>> FINDBUFFERS : SELECTOR ARRAY EMPTY >>>> ITERATING LEVEL >>>> %v", lvl)
err := lvl.findBuffers(nil, offset, f) err := lvl.findBuffers(nil, offset, f)
if err != nil { if err != nil {
return err return err
} }
} }
log.Printf(">>>> FINDBUFFERS : SELECTOR ARRAY EMPTY >>>> NO BUFFER MATCHED")
log.Printf(">>>> FINDBUFFERS : END RECURSIVE FINDBUFFERS >>>> RETURN NIL")
return nil return nil
} }
sel := selector[0] 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 { if len(sel.String) != 0 && l.children != nil {
// log.Printf(">>>> FINDBUFFERS : NAMED SELECTOR && CHILDREN AVAILABLE")
lvl, ok := l.children[sel.String] lvl, ok := l.children[sel.String]
if ok { if ok {
log.Printf(">>>> FINDBUFFERS : NAMED >>>> LOOKUP CHILDREN")
log.Printf(">>>> FINDBUFFERS : NAMED >>>> DO RECURSIVE FINDBUFFERS")
err := lvl.findBuffers(selector[1:], offset, f) err := lvl.findBuffers(selector[1:], offset, f)
if err != nil { if err != nil {
log.Printf(">>>> FINDBUFFERS : NAMED >>>> RECURSIVE ERROR >>>> $s", err)
return err return err
} }
} }
return nil return nil
} }
log.Printf(">>>> FINDBUFFERS : SELECTOR ELEMENT >>>> GROUP : %v", sel.Group)
if sel.Group != nil && l.children != nil { if sel.Group != nil && l.children != nil {
// log.Printf(">>>> FINDBUFFERS : GROUP && CHILDREN AVAILABLE")
for _, key := range sel.Group { for _, key := range sel.Group {
lvl, ok := l.children[key] lvl, ok := l.children[key]
if ok { 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) err := lvl.findBuffers(selector[1:], offset, f)
if err != nil { if err != nil {
log.Printf(">>>> FINDBUFFERS : GROUP >>>> RECURSIVE ERROR >>>> $s", err)
return err return err
} }
} }
} }
log.Printf(">>>> FINDBUFFERS : GROUP >>>> RETURN NIL")
return nil return nil
} }
log.Printf(">>>> FINDBUFFERS : SELECTOR ELEMENT >>>> IS ANY : %v", sel.Any)
if sel.Any && l.children != nil { if sel.Any && l.children != nil {
// log.Printf(">>>> FINDBUFFERS : ENABLED ANY && CHILDREN AVAILABLE")
for _, lvl := range l.children { for _, lvl := range l.children {
log.Printf(">>>> FINDBUFFERS : ANY >>>> DO RECURSIVE FINDBUFFERS")
if err := lvl.findBuffers(selector[1:], offset, f); err != nil { if err := lvl.findBuffers(selector[1:], offset, f); err != nil {
log.Printf(">>>> FINDBUFFERS : ANY >>>> RECURSIVE ERROR >>>> $s", err)
return err return err
} }
} }
log.Printf(">>>> FINDBUFFERS : ANY >>>> RETURN NIL")
return nil return nil
} }
log.Printf(">>>> FINDBUFFERS : NO MATCHED CASE >>>> RETURN NIL")
return nil return nil
} }