repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
grafana/metrictank | mdata/cache/ccache.go | Search | func (c *CCache) Search(ctx context.Context, metric schema.AMKey, from, until uint32) (*CCSearchResult, error) {
if from >= until {
return nil, ErrInvalidRange
}
res := &CCSearchResult{
From: from,
Until: until,
}
if c == nil {
accnt.CacheMetricMiss.Inc()
return res, nil
}
ctx, span := tracing.NewS... | go | func (c *CCache) Search(ctx context.Context, metric schema.AMKey, from, until uint32) (*CCSearchResult, error) {
if from >= until {
return nil, ErrInvalidRange
}
res := &CCSearchResult{
From: from,
Until: until,
}
if c == nil {
accnt.CacheMetricMiss.Inc()
return res, nil
}
ctx, span := tracing.NewS... | [
"func",
"(",
"c",
"*",
"CCache",
")",
"Search",
"(",
"ctx",
"context",
".",
"Context",
",",
"metric",
"schema",
".",
"AMKey",
",",
"from",
",",
"until",
"uint32",
")",
"(",
"*",
"CCSearchResult",
",",
"error",
")",
"{",
"if",
"from",
">=",
"until",
... | // Search looks for the requested metric and returns a complete-as-possible CCSearchResult
// from is inclusive, until is exclusive | [
"Search",
"looks",
"for",
"the",
"requested",
"metric",
"and",
"returns",
"a",
"complete",
"-",
"as",
"-",
"possible",
"CCSearchResult",
"from",
"is",
"inclusive",
"until",
"is",
"exclusive"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/cache/ccache.go#L258-L308 | train |
grafana/metrictank | mdata/aggmetrics.go | GC | func (ms *AggMetrics) GC() {
for {
unix := time.Duration(time.Now().UnixNano())
diff := ms.gcInterval - (unix % ms.gcInterval)
time.Sleep(diff + time.Minute)
log.Info("checking for stale chunks that need persisting.")
now := uint32(time.Now().Unix())
chunkMinTs := now - uint32(ms.chunkMaxStale)
metricMin... | go | func (ms *AggMetrics) GC() {
for {
unix := time.Duration(time.Now().UnixNano())
diff := ms.gcInterval - (unix % ms.gcInterval)
time.Sleep(diff + time.Minute)
log.Info("checking for stale chunks that need persisting.")
now := uint32(time.Now().Unix())
chunkMinTs := now - uint32(ms.chunkMaxStale)
metricMin... | [
"func",
"(",
"ms",
"*",
"AggMetrics",
")",
"GC",
"(",
")",
"{",
"for",
"{",
"unix",
":=",
"time",
".",
"Duration",
"(",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
")",
"\n",
"diff",
":=",
"ms",
".",
"gcInterval",
"-",
"(",
"unix",... | // periodically scan chunks and close any that have not received data in a while | [
"periodically",
"scan",
"chunks",
"and",
"close",
"any",
"that",
"have",
"not",
"received",
"data",
"in",
"a",
"while"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/aggmetrics.go#L47-L119 | train |
grafana/metrictank | cmd/mt-store-cat/chunk.go | printChunkSummary | func printChunkSummary(ctx context.Context, store *cassandra.CassandraStore, tables []cassandra.Table, metrics []Metric, groupTTL string) error {
now := uint32(time.Now().Unix())
endMonth := now / cassandra.Month_sec
for _, tbl := range tables {
// per store.FindExistingTables(), actual TTL may be up to 2x what's... | go | func printChunkSummary(ctx context.Context, store *cassandra.CassandraStore, tables []cassandra.Table, metrics []Metric, groupTTL string) error {
now := uint32(time.Now().Unix())
endMonth := now / cassandra.Month_sec
for _, tbl := range tables {
// per store.FindExistingTables(), actual TTL may be up to 2x what's... | [
"func",
"printChunkSummary",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"*",
"cassandra",
".",
"CassandraStore",
",",
"tables",
"[",
"]",
"cassandra",
".",
"Table",
",",
"metrics",
"[",
"]",
"Metric",
",",
"groupTTL",
"string",
")",
"error",
"{",... | // printChunkSummary prints a summary of chunks in the store matching the given conditions, grouped in buckets of groupTTL size by their TTL | [
"printChunkSummary",
"prints",
"a",
"summary",
"of",
"chunks",
"in",
"the",
"store",
"matching",
"the",
"given",
"conditions",
"grouped",
"in",
"buckets",
"of",
"groupTTL",
"size",
"by",
"their",
"TTL"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-store-cat/chunk.go#L13-L39 | train |
grafana/metrictank | cmd/mt-whisper-importer-reader/main.go | getMetricName | func getMetricName(file string) string {
// remove all leading '/' from file name
file = strings.TrimPrefix(file, *whisperDirectory)
for file[0] == '/' {
file = file[1:]
}
return *namePrefix + strings.Replace(strings.TrimSuffix(file, ".wsp"), "/", ".", -1)
} | go | func getMetricName(file string) string {
// remove all leading '/' from file name
file = strings.TrimPrefix(file, *whisperDirectory)
for file[0] == '/' {
file = file[1:]
}
return *namePrefix + strings.Replace(strings.TrimSuffix(file, ".wsp"), "/", ".", -1)
} | [
"func",
"getMetricName",
"(",
"file",
"string",
")",
"string",
"{",
"// remove all leading '/' from file name",
"file",
"=",
"strings",
".",
"TrimPrefix",
"(",
"file",
",",
"*",
"whisperDirectory",
")",
"\n",
"for",
"file",
"[",
"0",
"]",
"==",
"'/'",
"{",
"... | // generate the metric name based on the file name and given prefix | [
"generate",
"the",
"metric",
"name",
"based",
"on",
"the",
"file",
"name",
"and",
"given",
"prefix"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-whisper-importer-reader/main.go#L231-L239 | train |
grafana/metrictank | cmd/mt-whisper-importer-reader/main.go | getFileListIntoChan | func getFileListIntoChan(pos *posTracker, fileChan chan string) {
filepath.Walk(
*whisperDirectory,
func(path string, info os.FileInfo, err error) error {
if path == *whisperDirectory {
return nil
}
name := getMetricName(path)
if !nameFilter.Match([]byte(getMetricName(name))) {
log.Debugf("Skip... | go | func getFileListIntoChan(pos *posTracker, fileChan chan string) {
filepath.Walk(
*whisperDirectory,
func(path string, info os.FileInfo, err error) error {
if path == *whisperDirectory {
return nil
}
name := getMetricName(path)
if !nameFilter.Match([]byte(getMetricName(name))) {
log.Debugf("Skip... | [
"func",
"getFileListIntoChan",
"(",
"pos",
"*",
"posTracker",
",",
"fileChan",
"chan",
"string",
")",
"{",
"filepath",
".",
"Walk",
"(",
"*",
"whisperDirectory",
",",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
... | // scan a directory and feed the list of whisper files relative to base into the given channel | [
"scan",
"a",
"directory",
"and",
"feed",
"the",
"list",
"of",
"whisper",
"files",
"relative",
"to",
"base",
"into",
"the",
"given",
"channel"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-whisper-importer-reader/main.go#L399-L426 | train |
grafana/metrictank | store/cassandra/cassandra.go | ConvertTimeout | func ConvertTimeout(timeout string, defaultUnit time.Duration) time.Duration {
if timeoutI, err := strconv.Atoi(timeout); err == nil {
log.Warn("cassandra_store: specifying the timeout as integer is deprecated, please use a duration value")
return time.Duration(timeoutI) * defaultUnit
}
timeoutD, err := time.Par... | go | func ConvertTimeout(timeout string, defaultUnit time.Duration) time.Duration {
if timeoutI, err := strconv.Atoi(timeout); err == nil {
log.Warn("cassandra_store: specifying the timeout as integer is deprecated, please use a duration value")
return time.Duration(timeoutI) * defaultUnit
}
timeoutD, err := time.Par... | [
"func",
"ConvertTimeout",
"(",
"timeout",
"string",
",",
"defaultUnit",
"time",
".",
"Duration",
")",
"time",
".",
"Duration",
"{",
"if",
"timeoutI",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"timeout",
")",
";",
"err",
"==",
"nil",
"{",
"log",
".... | // ConvertTimeout provides backwards compatibility for values that used to be specified as integers,
// while also allowing them to be specified as durations. | [
"ConvertTimeout",
"provides",
"backwards",
"compatibility",
"for",
"values",
"that",
"used",
"to",
"be",
"specified",
"as",
"integers",
"while",
"also",
"allowing",
"them",
"to",
"be",
"specified",
"as",
"durations",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/store/cassandra/cassandra.go#L96-L106 | train |
grafana/metrictank | store/cassandra/cassandra.go | Search | func (c *CassandraStore) Search(ctx context.Context, key schema.AMKey, ttl, start, end uint32) ([]chunk.IterGen, error) {
table, ok := c.TTLTables[ttl]
if !ok {
return nil, errTableNotFound
}
return c.SearchTable(ctx, key, table, start, end)
} | go | func (c *CassandraStore) Search(ctx context.Context, key schema.AMKey, ttl, start, end uint32) ([]chunk.IterGen, error) {
table, ok := c.TTLTables[ttl]
if !ok {
return nil, errTableNotFound
}
return c.SearchTable(ctx, key, table, start, end)
} | [
"func",
"(",
"c",
"*",
"CassandraStore",
")",
"Search",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"schema",
".",
"AMKey",
",",
"ttl",
",",
"start",
",",
"end",
"uint32",
")",
"(",
"[",
"]",
"chunk",
".",
"IterGen",
",",
"error",
")",
"{",
... | // Basic search of cassandra in the table for given ttl
// start inclusive, end exclusive | [
"Basic",
"search",
"of",
"cassandra",
"in",
"the",
"table",
"for",
"given",
"ttl",
"start",
"inclusive",
"end",
"exclusive"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/store/cassandra/cassandra.go#L411-L417 | train |
grafana/metrictank | conf/indexrules.go | ReadIndexRules | func ReadIndexRules(file string) (IndexRules, error) {
config, err := configparser.Read(file)
if err != nil {
return IndexRules{}, err
}
sections, err := config.AllSections()
if err != nil {
return IndexRules{}, err
}
result := NewIndexRules()
for _, s := range sections {
item := IndexRule{}
item.Name... | go | func ReadIndexRules(file string) (IndexRules, error) {
config, err := configparser.Read(file)
if err != nil {
return IndexRules{}, err
}
sections, err := config.AllSections()
if err != nil {
return IndexRules{}, err
}
result := NewIndexRules()
for _, s := range sections {
item := IndexRule{}
item.Name... | [
"func",
"ReadIndexRules",
"(",
"file",
"string",
")",
"(",
"IndexRules",
",",
"error",
")",
"{",
"config",
",",
"err",
":=",
"configparser",
".",
"Read",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"IndexRules",
"{",
"}",
",",
"e... | // ReadIndexRules returns the defined index rule from a index-rules.conf file
// and adds the default | [
"ReadIndexRules",
"returns",
"the",
"defined",
"index",
"rule",
"from",
"a",
"index",
"-",
"rules",
".",
"conf",
"file",
"and",
"adds",
"the",
"default"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/indexrules.go#L38-L71 | train |
grafana/metrictank | conf/indexrules.go | Match | func (a IndexRules) Match(metric string) (uint16, IndexRule) {
for i, s := range a.Rules {
if s.Pattern.MatchString(metric) {
return uint16(i), s
}
}
return uint16(len(a.Rules)), a.Default
} | go | func (a IndexRules) Match(metric string) (uint16, IndexRule) {
for i, s := range a.Rules {
if s.Pattern.MatchString(metric) {
return uint16(i), s
}
}
return uint16(len(a.Rules)), a.Default
} | [
"func",
"(",
"a",
"IndexRules",
")",
"Match",
"(",
"metric",
"string",
")",
"(",
"uint16",
",",
"IndexRule",
")",
"{",
"for",
"i",
",",
"s",
":=",
"range",
"a",
".",
"Rules",
"{",
"if",
"s",
".",
"Pattern",
".",
"MatchString",
"(",
"metric",
")",
... | // Match returns the correct index rule setting for the given metric
// it can always find a valid setting, because there's a default catch all
// also returns the index of the setting, to efficiently reference it | [
"Match",
"returns",
"the",
"correct",
"index",
"rule",
"setting",
"for",
"the",
"given",
"metric",
"it",
"can",
"always",
"find",
"a",
"valid",
"setting",
"because",
"there",
"s",
"a",
"default",
"catch",
"all",
"also",
"returns",
"the",
"index",
"of",
"th... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/indexrules.go#L76-L83 | train |
grafana/metrictank | conf/indexrules.go | Get | func (a IndexRules) Get(i uint16) IndexRule {
if i >= uint16(len(a.Rules)) {
return a.Default
}
return a.Rules[i]
} | go | func (a IndexRules) Get(i uint16) IndexRule {
if i >= uint16(len(a.Rules)) {
return a.Default
}
return a.Rules[i]
} | [
"func",
"(",
"a",
"IndexRules",
")",
"Get",
"(",
"i",
"uint16",
")",
"IndexRule",
"{",
"if",
"i",
">=",
"uint16",
"(",
"len",
"(",
"a",
".",
"Rules",
")",
")",
"{",
"return",
"a",
".",
"Default",
"\n",
"}",
"\n",
"return",
"a",
".",
"Rules",
"[... | // Get returns the index rule setting corresponding to the given index | [
"Get",
"returns",
"the",
"index",
"rule",
"setting",
"corresponding",
"to",
"the",
"given",
"index"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/indexrules.go#L86-L91 | train |
grafana/metrictank | conf/indexrules.go | Prunable | func (a IndexRules) Prunable() bool {
for _, r := range a.Rules {
if r.MaxStale > 0 {
return true
}
}
return (a.Default.MaxStale > 0)
} | go | func (a IndexRules) Prunable() bool {
for _, r := range a.Rules {
if r.MaxStale > 0 {
return true
}
}
return (a.Default.MaxStale > 0)
} | [
"func",
"(",
"a",
"IndexRules",
")",
"Prunable",
"(",
")",
"bool",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"a",
".",
"Rules",
"{",
"if",
"r",
".",
"MaxStale",
">",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"(",
"a",
... | // Prunable returns whether there's any entries that require pruning | [
"Prunable",
"returns",
"whether",
"there",
"s",
"any",
"entries",
"that",
"require",
"pruning"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/indexrules.go#L94-L101 | train |
grafana/metrictank | conf/indexrules.go | Cutoffs | func (a IndexRules) Cutoffs(now time.Time) []int64 {
out := make([]int64, len(a.Rules)+1)
for i := 0; i <= len(a.Rules); i++ {
var rule IndexRule
if i < len(a.Rules) {
rule = a.Rules[i]
} else {
rule = a.Default
}
if rule.MaxStale == 0 {
out[i] = 0
} else {
out[i] = int64(now.Add(rule.MaxStale... | go | func (a IndexRules) Cutoffs(now time.Time) []int64 {
out := make([]int64, len(a.Rules)+1)
for i := 0; i <= len(a.Rules); i++ {
var rule IndexRule
if i < len(a.Rules) {
rule = a.Rules[i]
} else {
rule = a.Default
}
if rule.MaxStale == 0 {
out[i] = 0
} else {
out[i] = int64(now.Add(rule.MaxStale... | [
"func",
"(",
"a",
"IndexRules",
")",
"Cutoffs",
"(",
"now",
"time",
".",
"Time",
")",
"[",
"]",
"int64",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"int64",
",",
"len",
"(",
"a",
".",
"Rules",
")",
"+",
"1",
")",
"\n",
"for",
"i",
":=",
"0",
... | // Cutoffs returns a set of cutoffs corresponding to a given timestamp and the set of all rules | [
"Cutoffs",
"returns",
"a",
"set",
"of",
"cutoffs",
"corresponding",
"to",
"a",
"given",
"timestamp",
"and",
"the",
"set",
"of",
"all",
"rules"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/indexrules.go#L104-L120 | train |
grafana/metrictank | expr/plan.go | newplan | func newplan(e *expr, context Context, stable bool, reqs []Req) (GraphiteFunc, []Req, error) {
if e.etype != etFunc && e.etype != etName {
return nil, nil, errors.New("request must be a function call or metric pattern")
}
if e.etype == etName {
req := NewReq(e.str, context.from, context.to, context.consol)
req... | go | func newplan(e *expr, context Context, stable bool, reqs []Req) (GraphiteFunc, []Req, error) {
if e.etype != etFunc && e.etype != etName {
return nil, nil, errors.New("request must be a function call or metric pattern")
}
if e.etype == etName {
req := NewReq(e.str, context.from, context.to, context.consol)
req... | [
"func",
"newplan",
"(",
"e",
"*",
"expr",
",",
"context",
"Context",
",",
"stable",
"bool",
",",
"reqs",
"[",
"]",
"Req",
")",
"(",
"GraphiteFunc",
",",
"[",
"]",
"Req",
",",
"error",
")",
"{",
"if",
"e",
".",
"etype",
"!=",
"etFunc",
"&&",
"e",
... | // newplan adds requests as needed for the given expr, resolving function calls as needed | [
"newplan",
"adds",
"requests",
"as",
"needed",
"for",
"the",
"given",
"expr",
"resolving",
"function",
"calls",
"as",
"needed"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/expr/plan.go#L92-L123 | train |
grafana/metrictank | expr/plan.go | newplanFunc | func newplanFunc(e *expr, fn GraphiteFunc, context Context, stable bool, reqs []Req) ([]Req, error) {
// first comes the interesting task of validating the arguments as specified by the function,
// against the arguments that were parsed.
argsExp, _ := fn.Signature()
var err error
// note:
// * signature may ha... | go | func newplanFunc(e *expr, fn GraphiteFunc, context Context, stable bool, reqs []Req) ([]Req, error) {
// first comes the interesting task of validating the arguments as specified by the function,
// against the arguments that were parsed.
argsExp, _ := fn.Signature()
var err error
// note:
// * signature may ha... | [
"func",
"newplanFunc",
"(",
"e",
"*",
"expr",
",",
"fn",
"GraphiteFunc",
",",
"context",
"Context",
",",
"stable",
"bool",
",",
"reqs",
"[",
"]",
"Req",
")",
"(",
"[",
"]",
"Req",
",",
"error",
")",
"{",
"// first comes the interesting task of validating the... | // newplanFunc adds requests as needed for the given expr, and validates the function input
// provided you already know the expression is a function call to the given function | [
"newplanFunc",
"adds",
"requests",
"as",
"needed",
"for",
"the",
"given",
"expr",
"and",
"validates",
"the",
"function",
"input",
"provided",
"you",
"already",
"know",
"the",
"expression",
"is",
"a",
"function",
"call",
"to",
"the",
"given",
"function"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/expr/plan.go#L127-L216 | train |
grafana/metrictank | mdata/aggregator.go | AggBoundary | func AggBoundary(ts uint32, span uint32) uint32 {
return ts + span - ((ts-1)%span + 1)
} | go | func AggBoundary(ts uint32, span uint32) uint32 {
return ts + span - ((ts-1)%span + 1)
} | [
"func",
"AggBoundary",
"(",
"ts",
"uint32",
",",
"span",
"uint32",
")",
"uint32",
"{",
"return",
"ts",
"+",
"span",
"-",
"(",
"(",
"ts",
"-",
"1",
")",
"%",
"span",
"+",
"1",
")",
"\n",
"}"
] | // AggBoundary returns ts if it is a boundary, or the next boundary otherwise.
// see description for Aggregator and unit tests, for more details | [
"AggBoundary",
"returns",
"ts",
"if",
"it",
"is",
"a",
"boundary",
"or",
"the",
"next",
"boundary",
"otherwise",
".",
"see",
"description",
"for",
"Aggregator",
"and",
"unit",
"tests",
"for",
"more",
"details"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/aggregator.go#L11-L13 | train |
grafana/metrictank | mdata/aggregator.go | flush | func (agg *Aggregator) flush() {
if agg.minMetric != nil {
agg.minMetric.Add(agg.currentBoundary, agg.agg.Min)
}
if agg.maxMetric != nil {
agg.maxMetric.Add(agg.currentBoundary, agg.agg.Max)
}
if agg.sumMetric != nil {
agg.sumMetric.Add(agg.currentBoundary, agg.agg.Sum)
}
if agg.cntMetric != nil {
agg.cn... | go | func (agg *Aggregator) flush() {
if agg.minMetric != nil {
agg.minMetric.Add(agg.currentBoundary, agg.agg.Min)
}
if agg.maxMetric != nil {
agg.maxMetric.Add(agg.currentBoundary, agg.agg.Max)
}
if agg.sumMetric != nil {
agg.sumMetric.Add(agg.currentBoundary, agg.agg.Sum)
}
if agg.cntMetric != nil {
agg.cn... | [
"func",
"(",
"agg",
"*",
"Aggregator",
")",
"flush",
"(",
")",
"{",
"if",
"agg",
".",
"minMetric",
"!=",
"nil",
"{",
"agg",
".",
"minMetric",
".",
"Add",
"(",
"agg",
".",
"currentBoundary",
",",
"agg",
".",
"agg",
".",
"Min",
")",
"\n",
"}",
"\n"... | // flush adds points to the aggregation-series and resets aggregation state | [
"flush",
"adds",
"points",
"to",
"the",
"aggregation",
"-",
"series",
"and",
"resets",
"aggregation",
"state"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/aggregator.go#L78-L96 | train |
grafana/metrictank | mdata/aggregator.go | GC | func (agg *Aggregator) GC(now, chunkMinTs, metricMinTs, lastWriteTime uint32) (uint32, bool) {
var points uint32
stale := true
if lastWriteTime+agg.span > chunkMinTs {
// Last datapoint was less than one aggregation window before chunkMinTs, hold out for more data
return 0, false
}
// Haven't seen datapoints... | go | func (agg *Aggregator) GC(now, chunkMinTs, metricMinTs, lastWriteTime uint32) (uint32, bool) {
var points uint32
stale := true
if lastWriteTime+agg.span > chunkMinTs {
// Last datapoint was less than one aggregation window before chunkMinTs, hold out for more data
return 0, false
}
// Haven't seen datapoints... | [
"func",
"(",
"agg",
"*",
"Aggregator",
")",
"GC",
"(",
"now",
",",
"chunkMinTs",
",",
"metricMinTs",
",",
"lastWriteTime",
"uint32",
")",
"(",
"uint32",
",",
"bool",
")",
"{",
"var",
"points",
"uint32",
"\n",
"stale",
":=",
"true",
"\n\n",
"if",
"lastW... | // GC returns whether all of the associated series are stale and can be removed, and their combined pointcount if so | [
"GC",
"returns",
"whether",
"all",
"of",
"the",
"associated",
"series",
"are",
"stale",
"and",
"can",
"be",
"removed",
"and",
"their",
"combined",
"pointcount",
"if",
"so"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/aggregator.go#L120-L162 | train |
grafana/metrictank | expr/func_aspercent.go | getTotalSeries | func getTotalSeries(totalSeriesLists, include map[string][]models.Series, cache map[Req][]models.Series) map[string]models.Series {
totalSeries := make(map[string]models.Series, len(totalSeriesLists))
for key := range totalSeriesLists {
if _, ok := include[key]; ok {
totalSeries[key] = sumSeries(totalSeriesLists... | go | func getTotalSeries(totalSeriesLists, include map[string][]models.Series, cache map[Req][]models.Series) map[string]models.Series {
totalSeries := make(map[string]models.Series, len(totalSeriesLists))
for key := range totalSeriesLists {
if _, ok := include[key]; ok {
totalSeries[key] = sumSeries(totalSeriesLists... | [
"func",
"getTotalSeries",
"(",
"totalSeriesLists",
",",
"include",
"map",
"[",
"string",
"]",
"[",
"]",
"models",
".",
"Series",
",",
"cache",
"map",
"[",
"Req",
"]",
"[",
"]",
"models",
".",
"Series",
")",
"map",
"[",
"string",
"]",
"models",
".",
"... | // Sums each seriesList in map of seriesLists | [
"Sums",
"each",
"seriesList",
"in",
"map",
"of",
"seriesLists"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/expr/func_aspercent.go#L229-L240 | train |
grafana/metrictank | expr/func_aspercent.go | sumSeries | func sumSeries(series []models.Series, cache map[Req][]models.Series) models.Series {
if len(series) == 1 {
return series[0]
}
out := pointSlicePool.Get().([]schema.Point)
crossSeriesSum(series, &out)
var queryPatts []string
Loop:
for _, v := range series {
// avoid duplicates
for _, qp := range queryPatts... | go | func sumSeries(series []models.Series, cache map[Req][]models.Series) models.Series {
if len(series) == 1 {
return series[0]
}
out := pointSlicePool.Get().([]schema.Point)
crossSeriesSum(series, &out)
var queryPatts []string
Loop:
for _, v := range series {
// avoid duplicates
for _, qp := range queryPatts... | [
"func",
"sumSeries",
"(",
"series",
"[",
"]",
"models",
".",
"Series",
",",
"cache",
"map",
"[",
"Req",
"]",
"[",
"]",
"models",
".",
"Series",
")",
"models",
".",
"Series",
"{",
"if",
"len",
"(",
"series",
")",
"==",
"1",
"{",
"return",
"series",
... | // sumSeries returns a copy-on-write series that is the sum of the inputs | [
"sumSeries",
"returns",
"a",
"copy",
"-",
"on",
"-",
"write",
"series",
"that",
"is",
"the",
"sum",
"of",
"the",
"inputs"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/expr/func_aspercent.go#L243-L274 | train |
grafana/metrictank | expr/func_removeabovebelowpercentile.go | getPercentileValue | func getPercentileValue(datapoints []schema.Point, n float64, sortedDatapointVals []float64) float64 {
sortedDatapointVals = sortedDatapointVals[:0]
for _, p := range datapoints {
if !math.IsNaN(p.Val) {
sortedDatapointVals = append(sortedDatapointVals, p.Val)
}
}
sort.Float64s(sortedDatapointVals)
index ... | go | func getPercentileValue(datapoints []schema.Point, n float64, sortedDatapointVals []float64) float64 {
sortedDatapointVals = sortedDatapointVals[:0]
for _, p := range datapoints {
if !math.IsNaN(p.Val) {
sortedDatapointVals = append(sortedDatapointVals, p.Val)
}
}
sort.Float64s(sortedDatapointVals)
index ... | [
"func",
"getPercentileValue",
"(",
"datapoints",
"[",
"]",
"schema",
".",
"Point",
",",
"n",
"float64",
",",
"sortedDatapointVals",
"[",
"]",
"float64",
")",
"float64",
"{",
"sortedDatapointVals",
"=",
"sortedDatapointVals",
"[",
":",
"0",
"]",
"\n",
"for",
... | // sortedDatapointVals is an empty slice to be used for sorting datapoints.
// n must be > 0. if n > 100, the largest value is returned. | [
"sortedDatapointVals",
"is",
"an",
"empty",
"slice",
"to",
"be",
"used",
"for",
"sorting",
"datapoints",
".",
"n",
"must",
"be",
">",
"0",
".",
"if",
"n",
">",
"100",
"the",
"largest",
"value",
"is",
"returned",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/expr/func_removeabovebelowpercentile.go#L92-L105 | train |
grafana/metrictank | cluster/node.go | MarshalJSON | func (n NodeMode) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(n.String())
buffer.WriteString(`"`)
return buffer.Bytes(), nil
} | go | func (n NodeMode) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(n.String())
buffer.WriteString(`"`)
return buffer.Bytes(), nil
} | [
"func",
"(",
"n",
"NodeMode",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buffer",
":=",
"bytes",
".",
"NewBufferString",
"(",
"`\"`",
")",
"\n",
"buffer",
".",
"WriteString",
"(",
"n",
".",
"String",
"(",
")",
")"... | // MarshalJSON marshals a NodeMode | [
"MarshalJSON",
"marshals",
"a",
"NodeMode"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/node.go#L58-L63 | train |
grafana/metrictank | cluster/node.go | UnmarshalJSON | func (n *NodeMode) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
*n, err = NodeModeFromString(j)
return err
} | go | func (n *NodeMode) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
*n, err = NodeModeFromString(j)
return err
} | [
"func",
"(",
"n",
"*",
"NodeMode",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"j",
"string",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"j",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retur... | // UnmarshalJSON unmashals a NodeMode | [
"UnmarshalJSON",
"unmashals",
"a",
"NodeMode"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/node.go#L66-L74 | train |
grafana/metrictank | cluster/node.go | UnmarshalJSON | func (n *NodeState) UnmarshalJSON(data []byte) error {
s := string(data)
switch s {
case "0", `"NodeNotReady"`:
*n = NodeNotReady
case "1", `"NodeReady"`:
*n = NodeReady
case "2", `"NodeUnreachable"`:
*n = NodeUnreachable
default:
return fmt.Errorf("unrecognized NodeState %q", s)
}
return nil
} | go | func (n *NodeState) UnmarshalJSON(data []byte) error {
s := string(data)
switch s {
case "0", `"NodeNotReady"`:
*n = NodeNotReady
case "1", `"NodeReady"`:
*n = NodeReady
case "2", `"NodeUnreachable"`:
*n = NodeUnreachable
default:
return fmt.Errorf("unrecognized NodeState %q", s)
}
return nil
} | [
"func",
"(",
"n",
"*",
"NodeState",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"s",
":=",
"string",
"(",
"data",
")",
"\n",
"switch",
"s",
"{",
"case",
"\"",
"\"",
",",
"`\"NodeNotReady\"`",
":",
"*",
"n",
"=",
"NodeNot... | // UnmarshalJSON supports unmarshalling according to the older
// integer based, as well as the new string based, representation | [
"UnmarshalJSON",
"supports",
"unmarshalling",
"according",
"to",
"the",
"older",
"integer",
"based",
"as",
"well",
"as",
"the",
"new",
"string",
"based",
"representation"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/node.go#L100-L113 | train |
grafana/metrictank | cluster/node.go | readyStateGCHandler | func (n HTTPNode) readyStateGCHandler() {
if gcPercent == gcPercentNotReady {
return
}
var err error
if n.IsReady() {
prev := debug.SetGCPercent(gcPercent)
if prev != gcPercent {
log.Infof("CLU: node is ready. changing GOGC from %d to %d", prev, gcPercent)
err = os.Setenv("GOGC", strconv.Itoa(gcPercent)... | go | func (n HTTPNode) readyStateGCHandler() {
if gcPercent == gcPercentNotReady {
return
}
var err error
if n.IsReady() {
prev := debug.SetGCPercent(gcPercent)
if prev != gcPercent {
log.Infof("CLU: node is ready. changing GOGC from %d to %d", prev, gcPercent)
err = os.Setenv("GOGC", strconv.Itoa(gcPercent)... | [
"func",
"(",
"n",
"HTTPNode",
")",
"readyStateGCHandler",
"(",
")",
"{",
"if",
"gcPercent",
"==",
"gcPercentNotReady",
"{",
"return",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"if",
"n",
".",
"IsReady",
"(",
")",
"{",
"prev",
":=",
"debug",
".",
... | // readyStateGCHandler adjusts the gcPercent value based on the node ready state | [
"readyStateGCHandler",
"adjusts",
"the",
"gcPercent",
"value",
"based",
"on",
"the",
"node",
"ready",
"state"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/node.go#L192-L213 | train |
grafana/metrictank | cluster/node.go | SetState | func (n *HTTPNode) SetState(state NodeState) bool {
if n.State == state {
return false
}
n.State = state
now := time.Now()
n.Updated = now
n.StateChange = now
n.readyStateGCHandler()
return true
} | go | func (n *HTTPNode) SetState(state NodeState) bool {
if n.State == state {
return false
}
n.State = state
now := time.Now()
n.Updated = now
n.StateChange = now
n.readyStateGCHandler()
return true
} | [
"func",
"(",
"n",
"*",
"HTTPNode",
")",
"SetState",
"(",
"state",
"NodeState",
")",
"bool",
"{",
"if",
"n",
".",
"State",
"==",
"state",
"{",
"return",
"false",
"\n",
"}",
"\n",
"n",
".",
"State",
"=",
"state",
"\n",
"now",
":=",
"time",
".",
"No... | // SetState sets the state of the node and returns whether the state changed | [
"SetState",
"sets",
"the",
"state",
"of",
"the",
"node",
"and",
"returns",
"whether",
"the",
"state",
"changed"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/node.go#L216-L226 | train |
grafana/metrictank | cluster/node.go | SetPriority | func (n *HTTPNode) SetPriority(prio int) bool {
if n.Priority == prio {
return false
}
n.Priority = prio
n.Updated = time.Now()
n.readyStateGCHandler()
return true
} | go | func (n *HTTPNode) SetPriority(prio int) bool {
if n.Priority == prio {
return false
}
n.Priority = prio
n.Updated = time.Now()
n.readyStateGCHandler()
return true
} | [
"func",
"(",
"n",
"*",
"HTTPNode",
")",
"SetPriority",
"(",
"prio",
"int",
")",
"bool",
"{",
"if",
"n",
".",
"Priority",
"==",
"prio",
"{",
"return",
"false",
"\n",
"}",
"\n",
"n",
".",
"Priority",
"=",
"prio",
"\n",
"n",
".",
"Updated",
"=",
"ti... | // SetPriority sets the priority of the node and returns whether it changed | [
"SetPriority",
"sets",
"the",
"priority",
"of",
"the",
"node",
"and",
"returns",
"whether",
"it",
"changed"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/node.go#L229-L237 | train |
grafana/metrictank | cluster/node.go | SetPrimary | func (n *HTTPNode) SetPrimary(primary bool) bool {
if n.Primary == primary {
return false
}
now := time.Now()
n.Primary = primary
n.Updated = now
n.PrimaryChange = now
return true
} | go | func (n *HTTPNode) SetPrimary(primary bool) bool {
if n.Primary == primary {
return false
}
now := time.Now()
n.Primary = primary
n.Updated = now
n.PrimaryChange = now
return true
} | [
"func",
"(",
"n",
"*",
"HTTPNode",
")",
"SetPrimary",
"(",
"primary",
"bool",
")",
"bool",
"{",
"if",
"n",
".",
"Primary",
"==",
"primary",
"{",
"return",
"false",
"\n",
"}",
"\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"n",
".",
"Prima... | // SetPrimary sets the primary state of the node and returns whether it changed | [
"SetPrimary",
"sets",
"the",
"primary",
"state",
"of",
"the",
"node",
"and",
"returns",
"whether",
"it",
"changed"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/node.go#L240-L249 | train |
grafana/metrictank | cluster/node.go | SetPartitions | func (n *HTTPNode) SetPartitions(part []int32) {
n.Partitions = part
n.Updated = time.Now()
} | go | func (n *HTTPNode) SetPartitions(part []int32) {
n.Partitions = part
n.Updated = time.Now()
} | [
"func",
"(",
"n",
"*",
"HTTPNode",
")",
"SetPartitions",
"(",
"part",
"[",
"]",
"int32",
")",
"{",
"n",
".",
"Partitions",
"=",
"part",
"\n",
"n",
".",
"Updated",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"}"
] | // SetPartitions sets the partitions that this node is handling | [
"SetPartitions",
"sets",
"the",
"partitions",
"that",
"this",
"node",
"is",
"handling"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/node.go#L252-L255 | train |
grafana/metrictank | kafka/partitions.go | DiffPartitions | func DiffPartitions(a []int32, b []int32) []int32 {
var diff []int32
Iter:
for _, eA := range a {
for _, eB := range b {
if eA == eB {
continue Iter
}
}
diff = append(diff, eA)
}
return diff
} | go | func DiffPartitions(a []int32, b []int32) []int32 {
var diff []int32
Iter:
for _, eA := range a {
for _, eB := range b {
if eA == eB {
continue Iter
}
}
diff = append(diff, eA)
}
return diff
} | [
"func",
"DiffPartitions",
"(",
"a",
"[",
"]",
"int32",
",",
"b",
"[",
"]",
"int32",
")",
"[",
"]",
"int32",
"{",
"var",
"diff",
"[",
"]",
"int32",
"\n",
"Iter",
":",
"for",
"_",
",",
"eA",
":=",
"range",
"a",
"{",
"for",
"_",
",",
"eB",
":=",... | // returns elements that are in a but not in b | [
"returns",
"elements",
"that",
"are",
"in",
"a",
"but",
"not",
"in",
"b"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/kafka/partitions.go#L10-L22 | train |
grafana/metrictank | api/models/series.go | MarshalJSONFast | func (series SeriesByTarget) MarshalJSONFast(b []byte) ([]byte, error) {
b = append(b, '[')
for _, s := range series {
b = append(b, `{"target":`...)
b = strconv.AppendQuoteToASCII(b, s.Target)
if len(s.Tags) != 0 {
b = append(b, `,"tags":{`...)
for name, value := range s.Tags {
b = strconv.AppendQuot... | go | func (series SeriesByTarget) MarshalJSONFast(b []byte) ([]byte, error) {
b = append(b, '[')
for _, s := range series {
b = append(b, `{"target":`...)
b = strconv.AppendQuoteToASCII(b, s.Target)
if len(s.Tags) != 0 {
b = append(b, `,"tags":{`...)
for name, value := range s.Tags {
b = strconv.AppendQuot... | [
"func",
"(",
"series",
"SeriesByTarget",
")",
"MarshalJSONFast",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"'['",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"series",
... | // regular graphite output | [
"regular",
"graphite",
"output"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/models/series.go#L100-L138 | train |
grafana/metrictank | idx/memory/time_limit.go | NewTimeLimiter | func NewTimeLimiter(window, limit time.Duration, now time.Time) *TimeLimiter {
l := TimeLimiter{
since: now,
next: now.Add(window),
window: window,
limit: limit,
factor: float64(window) / float64(limit),
}
return &l
} | go | func NewTimeLimiter(window, limit time.Duration, now time.Time) *TimeLimiter {
l := TimeLimiter{
since: now,
next: now.Add(window),
window: window,
limit: limit,
factor: float64(window) / float64(limit),
}
return &l
} | [
"func",
"NewTimeLimiter",
"(",
"window",
",",
"limit",
"time",
".",
"Duration",
",",
"now",
"time",
".",
"Time",
")",
"*",
"TimeLimiter",
"{",
"l",
":=",
"TimeLimiter",
"{",
"since",
":",
"now",
",",
"next",
":",
"now",
".",
"Add",
"(",
"window",
")"... | // NewTimeLimiter creates a new TimeLimiter.
// limit must <= window | [
"NewTimeLimiter",
"creates",
"a",
"new",
"TimeLimiter",
".",
"limit",
"must",
"<",
"=",
"window"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/time_limit.go#L25-L34 | train |
grafana/metrictank | idx/memory/time_limit.go | Add | func (l *TimeLimiter) Add(d time.Duration) {
l.add(time.Now(), d)
} | go | func (l *TimeLimiter) Add(d time.Duration) {
l.add(time.Now(), d)
} | [
"func",
"(",
"l",
"*",
"TimeLimiter",
")",
"Add",
"(",
"d",
"time",
".",
"Duration",
")",
"{",
"l",
".",
"add",
"(",
"time",
".",
"Now",
"(",
")",
",",
"d",
")",
"\n",
"}"
] | // Add increments the "time spent" counter by "d" | [
"Add",
"increments",
"the",
"time",
"spent",
"counter",
"by",
"d"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/time_limit.go#L37-L39 | train |
grafana/metrictank | idx/memory/time_limit.go | add | func (l *TimeLimiter) add(now time.Time, d time.Duration) {
if now.After(l.next) {
l.timeSpent = d
l.since = now.Add(-d)
l.next = l.since.Add(l.window)
return
}
l.timeSpent += d
} | go | func (l *TimeLimiter) add(now time.Time, d time.Duration) {
if now.After(l.next) {
l.timeSpent = d
l.since = now.Add(-d)
l.next = l.since.Add(l.window)
return
}
l.timeSpent += d
} | [
"func",
"(",
"l",
"*",
"TimeLimiter",
")",
"add",
"(",
"now",
"time",
".",
"Time",
",",
"d",
"time",
".",
"Duration",
")",
"{",
"if",
"now",
".",
"After",
"(",
"l",
".",
"next",
")",
"{",
"l",
".",
"timeSpent",
"=",
"d",
"\n",
"l",
".",
"sinc... | // add increments the "time spent" counter by "d" at a given time | [
"add",
"increments",
"the",
"time",
"spent",
"counter",
"by",
"d",
"at",
"a",
"given",
"time"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/time_limit.go#L42-L50 | train |
grafana/metrictank | idx/memory/memory.go | AddOrUpdate | func (m *UnpartitionedMemoryIdx) AddOrUpdate(mkey schema.MKey, data *schema.MetricData, partition int32) (idx.Archive, int32, bool) {
pre := time.Now()
// Optimistically read lock
m.RLock()
existing, ok := m.defById[mkey]
if ok {
if log.IsLevelEnabled(log.DebugLevel) {
log.Debugf("memory-idx: metricDef with... | go | func (m *UnpartitionedMemoryIdx) AddOrUpdate(mkey schema.MKey, data *schema.MetricData, partition int32) (idx.Archive, int32, bool) {
pre := time.Now()
// Optimistically read lock
m.RLock()
existing, ok := m.defById[mkey]
if ok {
if log.IsLevelEnabled(log.DebugLevel) {
log.Debugf("memory-idx: metricDef with... | [
"func",
"(",
"m",
"*",
"UnpartitionedMemoryIdx",
")",
"AddOrUpdate",
"(",
"mkey",
"schema",
".",
"MKey",
",",
"data",
"*",
"schema",
".",
"MetricData",
",",
"partition",
"int32",
")",
"(",
"idx",
".",
"Archive",
",",
"int32",
",",
"bool",
")",
"{",
"pr... | // AddOrUpdate returns the corresponding Archive for the MetricData.
// if it is existing -> updates lastUpdate based on .Time, and partition
// if was new -> adds new MetricDefinition to index | [
"AddOrUpdate",
"returns",
"the",
"corresponding",
"Archive",
"for",
"the",
"MetricData",
".",
"if",
"it",
"is",
"existing",
"-",
">",
"updates",
"lastUpdate",
"based",
"on",
".",
"Time",
"and",
"partition",
"if",
"was",
"new",
"-",
">",
"adds",
"new",
"Met... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/memory.go#L320-L354 | train |
grafana/metrictank | idx/memory/memory.go | indexTags | func (m *UnpartitionedMemoryIdx) indexTags(def *schema.MetricDefinition) {
tags, ok := m.tags[def.OrgId]
if !ok {
tags = make(TagIndex)
m.tags[def.OrgId] = tags
}
for _, tag := range def.Tags {
tagSplits := strings.SplitN(tag, "=", 2)
if len(tagSplits) < 2 {
// should never happen because every tag in t... | go | func (m *UnpartitionedMemoryIdx) indexTags(def *schema.MetricDefinition) {
tags, ok := m.tags[def.OrgId]
if !ok {
tags = make(TagIndex)
m.tags[def.OrgId] = tags
}
for _, tag := range def.Tags {
tagSplits := strings.SplitN(tag, "=", 2)
if len(tagSplits) < 2 {
// should never happen because every tag in t... | [
"func",
"(",
"m",
"*",
"UnpartitionedMemoryIdx",
")",
"indexTags",
"(",
"def",
"*",
"schema",
".",
"MetricDefinition",
")",
"{",
"tags",
",",
"ok",
":=",
"m",
".",
"tags",
"[",
"def",
".",
"OrgId",
"]",
"\n",
"if",
"!",
"ok",
"{",
"tags",
"=",
"mak... | // indexTags reads the tags of a given metric definition and creates the
// corresponding tag index entries to refer to it. It assumes a lock is
// already held. | [
"indexTags",
"reads",
"the",
"tags",
"of",
"a",
"given",
"metric",
"definition",
"and",
"creates",
"the",
"corresponding",
"tag",
"index",
"entries",
"to",
"refer",
"to",
"it",
".",
"It",
"assumes",
"a",
"lock",
"is",
"already",
"held",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/memory.go#L369-L393 | train |
grafana/metrictank | idx/memory/memory.go | deindexTags | func (m *UnpartitionedMemoryIdx) deindexTags(tags TagIndex, def *schema.MetricDefinition) bool {
for _, tag := range def.Tags {
tagSplits := strings.SplitN(tag, "=", 2)
if len(tagSplits) < 2 {
// should never happen because every tag in the index
// must have a valid format
invalidTag.Inc()
log.Errorf(... | go | func (m *UnpartitionedMemoryIdx) deindexTags(tags TagIndex, def *schema.MetricDefinition) bool {
for _, tag := range def.Tags {
tagSplits := strings.SplitN(tag, "=", 2)
if len(tagSplits) < 2 {
// should never happen because every tag in the index
// must have a valid format
invalidTag.Inc()
log.Errorf(... | [
"func",
"(",
"m",
"*",
"UnpartitionedMemoryIdx",
")",
"deindexTags",
"(",
"tags",
"TagIndex",
",",
"def",
"*",
"schema",
".",
"MetricDefinition",
")",
"bool",
"{",
"for",
"_",
",",
"tag",
":=",
"range",
"def",
".",
"Tags",
"{",
"tagSplits",
":=",
"string... | // deindexTags takes a given metric definition and removes all references
// to it from the tag index. It assumes a lock is already held.
// a return value of "false" means there was an error and the deindexing was
// unsuccessful, "true" means the indexing was at least partially or completely
// successful | [
"deindexTags",
"takes",
"a",
"given",
"metric",
"definition",
"and",
"removes",
"all",
"references",
"to",
"it",
"from",
"the",
"tag",
"index",
".",
"It",
"assumes",
"a",
"lock",
"is",
"already",
"held",
".",
"a",
"return",
"value",
"of",
"false",
"means",... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/memory.go#L400-L421 | train |
grafana/metrictank | idx/memory/memory.go | LoadPartition | func (m *UnpartitionedMemoryIdx) LoadPartition(partition int32, defs []schema.MetricDefinition) int {
// UnpartitionedMemoryIdx isnt partitioned, so just ignore the partition passed and call Load()
return m.Load(defs)
} | go | func (m *UnpartitionedMemoryIdx) LoadPartition(partition int32, defs []schema.MetricDefinition) int {
// UnpartitionedMemoryIdx isnt partitioned, so just ignore the partition passed and call Load()
return m.Load(defs)
} | [
"func",
"(",
"m",
"*",
"UnpartitionedMemoryIdx",
")",
"LoadPartition",
"(",
"partition",
"int32",
",",
"defs",
"[",
"]",
"schema",
".",
"MetricDefinition",
")",
"int",
"{",
"// UnpartitionedMemoryIdx isnt partitioned, so just ignore the partition passed and call Load()",
"r... | // Used to rebuild the index from an existing set of metricDefinitions for a specific paritition. | [
"Used",
"to",
"rebuild",
"the",
"index",
"from",
"an",
"existing",
"set",
"of",
"metricDefinitions",
"for",
"a",
"specific",
"paritition",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/memory.go#L424-L427 | train |
grafana/metrictank | idx/memory/memory.go | GetPath | func (m *UnpartitionedMemoryIdx) GetPath(orgId uint32, path string) []idx.Archive {
m.RLock()
defer m.RUnlock()
tree, ok := m.tree[orgId]
if !ok {
return nil
}
node := tree.Items[path]
if node == nil {
return nil
}
archives := make([]idx.Archive, len(node.Defs))
for i, def := range node.Defs {
archive :... | go | func (m *UnpartitionedMemoryIdx) GetPath(orgId uint32, path string) []idx.Archive {
m.RLock()
defer m.RUnlock()
tree, ok := m.tree[orgId]
if !ok {
return nil
}
node := tree.Items[path]
if node == nil {
return nil
}
archives := make([]idx.Archive, len(node.Defs))
for i, def := range node.Defs {
archive :... | [
"func",
"(",
"m",
"*",
"UnpartitionedMemoryIdx",
")",
"GetPath",
"(",
"orgId",
"uint32",
",",
"path",
"string",
")",
"[",
"]",
"idx",
".",
"Archive",
"{",
"m",
".",
"RLock",
"(",
")",
"\n",
"defer",
"m",
".",
"RUnlock",
"(",
")",
"\n",
"tree",
",",... | // GetPath returns the node under the given org and path.
// this is an alternative to Find for when you have a path, not a pattern, and want to lookup in a specific org tree only. | [
"GetPath",
"returns",
"the",
"node",
"under",
"the",
"given",
"org",
"and",
"path",
".",
"this",
"is",
"an",
"alternative",
"to",
"Find",
"for",
"when",
"you",
"have",
"a",
"path",
"not",
"a",
"pattern",
"and",
"want",
"to",
"lookup",
"in",
"a",
"speci... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/memory.go#L575-L592 | train |
grafana/metrictank | idx/memory/memory.go | Tags | func (m *UnpartitionedMemoryIdx) Tags(orgId uint32, filter string, from int64) ([]string, error) {
if !TagSupport {
log.Warn("memory-idx: received tag query, but tag support is disabled")
return nil, nil
}
var re *regexp.Regexp
if len(filter) > 0 {
if filter[0] != byte('^') {
filter = "^(?:" + filter + ")... | go | func (m *UnpartitionedMemoryIdx) Tags(orgId uint32, filter string, from int64) ([]string, error) {
if !TagSupport {
log.Warn("memory-idx: received tag query, but tag support is disabled")
return nil, nil
}
var re *regexp.Regexp
if len(filter) > 0 {
if filter[0] != byte('^') {
filter = "^(?:" + filter + ")... | [
"func",
"(",
"m",
"*",
"UnpartitionedMemoryIdx",
")",
"Tags",
"(",
"orgId",
"uint32",
",",
"filter",
"string",
",",
"from",
"int64",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"!",
"TagSupport",
"{",
"log",
".",
"Warn",
"(",
"\"",
... | // Tags returns a list of all tag keys associated with the metrics of a given
// organization. The return values are filtered by the regex in the second parameter.
// If the third parameter is >0 then only metrics will be accounted of which the
// LastUpdate time is >= the given value. | [
"Tags",
"returns",
"a",
"list",
"of",
"all",
"tag",
"keys",
"associated",
"with",
"the",
"metrics",
"of",
"a",
"given",
"organization",
".",
"The",
"return",
"values",
"are",
"filtered",
"by",
"the",
"regex",
"in",
"the",
"second",
"parameter",
".",
"If",
... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/memory.go#L852-L900 | train |
grafana/metrictank | idx/memory/memory.go | deleteTaggedByIdSet | func (m *UnpartitionedMemoryIdx) deleteTaggedByIdSet(orgId uint32, ids IdSet) []idx.Archive {
tags, ok := m.tags[orgId]
if !ok {
return nil
}
deletedDefs := make([]idx.Archive, 0, len(ids))
for id := range ids {
idStr := id
def, ok := m.defById[idStr]
if !ok {
// not necessarily a corruption, the id co... | go | func (m *UnpartitionedMemoryIdx) deleteTaggedByIdSet(orgId uint32, ids IdSet) []idx.Archive {
tags, ok := m.tags[orgId]
if !ok {
return nil
}
deletedDefs := make([]idx.Archive, 0, len(ids))
for id := range ids {
idStr := id
def, ok := m.defById[idStr]
if !ok {
// not necessarily a corruption, the id co... | [
"func",
"(",
"m",
"*",
"UnpartitionedMemoryIdx",
")",
"deleteTaggedByIdSet",
"(",
"orgId",
"uint32",
",",
"ids",
"IdSet",
")",
"[",
"]",
"idx",
".",
"Archive",
"{",
"tags",
",",
"ok",
":=",
"m",
".",
"tags",
"[",
"orgId",
"]",
"\n",
"if",
"!",
"ok",
... | // deleteTaggedByIdSet deletes a map of ids from the tag index and also the DefByIds
// it is important that only IDs of series with tags get passed in here, because
// otherwise the result might be inconsistencies between DefByIDs and the tree index. | [
"deleteTaggedByIdSet",
"deletes",
"a",
"map",
"of",
"ids",
"from",
"the",
"tag",
"index",
"and",
"also",
"the",
"DefByIds",
"it",
"is",
"important",
"that",
"only",
"IDs",
"of",
"series",
"with",
"tags",
"get",
"passed",
"in",
"here",
"because",
"otherwise",... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/memory.go#L1212-L1237 | train |
grafana/metrictank | util/util.go | Lcm | func Lcm(vals []uint32) uint32 {
out := vals[0]
for i := 1; i < len(vals); i++ {
max := Max(uint32(vals[i]), out)
min := Min(uint32(vals[i]), out)
r := max % min
if r != 0 {
for j := uint32(2); j <= min; j++ {
if (j*max)%min == 0 {
out = j * max
break
}
}
} else {
out = max
}
}... | go | func Lcm(vals []uint32) uint32 {
out := vals[0]
for i := 1; i < len(vals); i++ {
max := Max(uint32(vals[i]), out)
min := Min(uint32(vals[i]), out)
r := max % min
if r != 0 {
for j := uint32(2); j <= min; j++ {
if (j*max)%min == 0 {
out = j * max
break
}
}
} else {
out = max
}
}... | [
"func",
"Lcm",
"(",
"vals",
"[",
"]",
"uint32",
")",
"uint32",
"{",
"out",
":=",
"vals",
"[",
"0",
"]",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"vals",
")",
";",
"i",
"++",
"{",
"max",
":=",
"Max",
"(",
"uint32",
"(",
"vals"... | // Lcm returns the least common multiple | [
"Lcm",
"returns",
"the",
"least",
"common",
"multiple"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/util/util.go#L25-L43 | train |
grafana/metrictank | input/input.go | ProcessMetricPoint | func (in DefaultHandler) ProcessMetricPoint(point schema.MetricPoint, format msg.Format, partition int32) {
if format == msg.FormatMetricPoint {
in.receivedMP.Inc()
} else {
in.receivedMPNO.Inc()
}
// in cassandra we store timestamps as 32bit signed integers.
// math.MaxInt32 = Jan 19 03:14:07 UTC 2038
if !po... | go | func (in DefaultHandler) ProcessMetricPoint(point schema.MetricPoint, format msg.Format, partition int32) {
if format == msg.FormatMetricPoint {
in.receivedMP.Inc()
} else {
in.receivedMPNO.Inc()
}
// in cassandra we store timestamps as 32bit signed integers.
// math.MaxInt32 = Jan 19 03:14:07 UTC 2038
if !po... | [
"func",
"(",
"in",
"DefaultHandler",
")",
"ProcessMetricPoint",
"(",
"point",
"schema",
".",
"MetricPoint",
",",
"format",
"msg",
".",
"Format",
",",
"partition",
"int32",
")",
"{",
"if",
"format",
"==",
"msg",
".",
"FormatMetricPoint",
"{",
"in",
".",
"re... | // ProcessMetricPoint updates the index if possible, and stores the data if we have an index entry
// concurrency-safe. | [
"ProcessMetricPoint",
"updates",
"the",
"index",
"if",
"possible",
"and",
"stores",
"the",
"data",
"if",
"we",
"have",
"an",
"index",
"entry",
"concurrency",
"-",
"safe",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/input/input.go#L72-L97 | train |
grafana/metrictank | input/input.go | ProcessMetricData | func (in DefaultHandler) ProcessMetricData(md *schema.MetricData, partition int32) {
in.receivedMD.Inc()
err := md.Validate()
if err != nil {
in.invalidMD.Inc()
log.Debugf("in: Invalid metric %v: %s", md, err)
var reason string
switch err {
case schema.ErrInvalidIntervalzero:
reason = invalidInterval
... | go | func (in DefaultHandler) ProcessMetricData(md *schema.MetricData, partition int32) {
in.receivedMD.Inc()
err := md.Validate()
if err != nil {
in.invalidMD.Inc()
log.Debugf("in: Invalid metric %v: %s", md, err)
var reason string
switch err {
case schema.ErrInvalidIntervalzero:
reason = invalidInterval
... | [
"func",
"(",
"in",
"DefaultHandler",
")",
"ProcessMetricData",
"(",
"md",
"*",
"schema",
".",
"MetricData",
",",
"partition",
"int32",
")",
"{",
"in",
".",
"receivedMD",
".",
"Inc",
"(",
")",
"\n",
"err",
":=",
"md",
".",
"Validate",
"(",
")",
"\n",
... | // ProcessMetricData assures the data is stored and the metadata is in the index
// concurrency-safe. | [
"ProcessMetricData",
"assures",
"the",
"data",
"is",
"stored",
"and",
"the",
"metadata",
"is",
"in",
"the",
"index",
"concurrency",
"-",
"safe",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/input/input.go#L101-L152 | train |
grafana/metrictank | idx/bigtable/schema.go | FormatRowKey | func FormatRowKey(mkey schema.MKey, partition int32) string {
return strconv.Itoa(int(partition)) + "_" + mkey.String()
} | go | func FormatRowKey(mkey schema.MKey, partition int32) string {
return strconv.Itoa(int(partition)) + "_" + mkey.String()
} | [
"func",
"FormatRowKey",
"(",
"mkey",
"schema",
".",
"MKey",
",",
"partition",
"int32",
")",
"string",
"{",
"return",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"partition",
")",
")",
"+",
"\"",
"\"",
"+",
"mkey",
".",
"String",
"(",
")",
"\n",
"}"
] | // FormatRowKey formats an MKey and partition into a rowKey | [
"FormatRowKey",
"formats",
"an",
"MKey",
"and",
"partition",
"into",
"a",
"rowKey"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/bigtable/schema.go#L16-L18 | train |
grafana/metrictank | idx/bigtable/schema.go | SchemaToRow | func SchemaToRow(def *schema.MetricDefinition) (string, map[string][]byte) {
row := map[string][]byte{
//"Id" omitted as it is part of the rowKey
"OrgId": make([]byte, 8),
"Name": []byte(def.Name),
"Interval": make([]byte, 8),
"Unit": []byte(def.Unit),
"Mtype": []byte(def.Mtype),
... | go | func SchemaToRow(def *schema.MetricDefinition) (string, map[string][]byte) {
row := map[string][]byte{
//"Id" omitted as it is part of the rowKey
"OrgId": make([]byte, 8),
"Name": []byte(def.Name),
"Interval": make([]byte, 8),
"Unit": []byte(def.Unit),
"Mtype": []byte(def.Mtype),
... | [
"func",
"SchemaToRow",
"(",
"def",
"*",
"schema",
".",
"MetricDefinition",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
")",
"{",
"row",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
"{",
"//\"Id\" omitted as it is part of t... | // SchemaToRow takes a metricDefintion and returns a rowKey and column data. | [
"SchemaToRow",
"takes",
"a",
"metricDefintion",
"and",
"returns",
"a",
"rowKey",
"and",
"column",
"data",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/bigtable/schema.go#L21-L37 | train |
grafana/metrictank | idx/bigtable/schema.go | DecodeRowKey | func DecodeRowKey(key string) (schema.MKey, int32, error) {
parts := strings.SplitN(key, "_", 2)
partition, err := strconv.Atoi(parts[0])
if err != nil {
return schema.MKey{}, 0, err
}
mkey, err := schema.MKeyFromString(parts[1])
if err != nil {
return schema.MKey{}, 0, err
}
return mkey, int32(partition), ... | go | func DecodeRowKey(key string) (schema.MKey, int32, error) {
parts := strings.SplitN(key, "_", 2)
partition, err := strconv.Atoi(parts[0])
if err != nil {
return schema.MKey{}, 0, err
}
mkey, err := schema.MKeyFromString(parts[1])
if err != nil {
return schema.MKey{}, 0, err
}
return mkey, int32(partition), ... | [
"func",
"DecodeRowKey",
"(",
"key",
"string",
")",
"(",
"schema",
".",
"MKey",
",",
"int32",
",",
"error",
")",
"{",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"key",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"partition",
",",
"err",
":=",
"strconv"... | // DecodeRowKey takes a rowKey string and returns the corresponding MKey and partition | [
"DecodeRowKey",
"takes",
"a",
"rowKey",
"string",
"and",
"returns",
"the",
"corresponding",
"MKey",
"and",
"partition"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/bigtable/schema.go#L40-L51 | train |
grafana/metrictank | idx/bigtable/schema.go | RowToSchema | func RowToSchema(row bigtable.Row, def *schema.MetricDefinition) error {
if def == nil {
return fmt.Errorf("cant write row to nil MetricDefinition")
}
columns, ok := row[COLUMN_FAMILY]
if !ok {
return fmt.Errorf("no columns in columnFamly %s", COLUMN_FAMILY)
}
*def = schema.MetricDefinition{}
var err error
... | go | func RowToSchema(row bigtable.Row, def *schema.MetricDefinition) error {
if def == nil {
return fmt.Errorf("cant write row to nil MetricDefinition")
}
columns, ok := row[COLUMN_FAMILY]
if !ok {
return fmt.Errorf("no columns in columnFamly %s", COLUMN_FAMILY)
}
*def = schema.MetricDefinition{}
var err error
... | [
"func",
"RowToSchema",
"(",
"row",
"bigtable",
".",
"Row",
",",
"def",
"*",
"schema",
".",
"MetricDefinition",
")",
"error",
"{",
"if",
"def",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"columns",
",",
... | // RowToSchema takes a row and unmarshals the data into the provided MetricDefinition. | [
"RowToSchema",
"takes",
"a",
"row",
"and",
"unmarshals",
"the",
"data",
"into",
"the",
"provided",
"MetricDefinition",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/bigtable/schema.go#L54-L110 | train |
grafana/metrictank | consolidation/consolidation.go | String | func (c Consolidator) String() string {
switch c {
case None:
return "NoneConsolidator"
case Avg:
return "AverageConsolidator"
case Cnt:
return "CountConsolidator"
case Lst:
return "LastConsolidator"
case Min:
return "MinimumConsolidator"
case Max:
return "MaximumConsolidator"
case Mult:
return "M... | go | func (c Consolidator) String() string {
switch c {
case None:
return "NoneConsolidator"
case Avg:
return "AverageConsolidator"
case Cnt:
return "CountConsolidator"
case Lst:
return "LastConsolidator"
case Min:
return "MinimumConsolidator"
case Max:
return "MaximumConsolidator"
case Mult:
return "M... | [
"func",
"(",
"c",
"Consolidator",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"c",
"{",
"case",
"None",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Avg",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Cnt",
":",
"return",
"\"",
"\"",
"\n",
"case",
... | // String provides human friendly names | [
"String",
"provides",
"human",
"friendly",
"names"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/consolidation/consolidation.go#L36-L64 | train |
grafana/metrictank | consolidation/consolidation.go | Archive | func (c Consolidator) Archive() schema.Method {
switch c {
case None:
panic("cannot get an archive for no consolidation")
case Avg:
panic("avg consolidator has no matching Archive(). you need sum and cnt")
case Cnt:
return schema.Cnt
case Lst:
return schema.Lst
case Min:
return schema.Min
case Max:
r... | go | func (c Consolidator) Archive() schema.Method {
switch c {
case None:
panic("cannot get an archive for no consolidation")
case Avg:
panic("avg consolidator has no matching Archive(). you need sum and cnt")
case Cnt:
return schema.Cnt
case Lst:
return schema.Lst
case Min:
return schema.Min
case Max:
r... | [
"func",
"(",
"c",
"Consolidator",
")",
"Archive",
"(",
")",
"schema",
".",
"Method",
"{",
"switch",
"c",
"{",
"case",
"None",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"case",
"Avg",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"case",
"Cnt",
":",
... | // provide the name of a stored archive
// see aggregator.go for which archives are available | [
"provide",
"the",
"name",
"of",
"a",
"stored",
"archive",
"see",
"aggregator",
".",
"go",
"for",
"which",
"archives",
"are",
"available"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/consolidation/consolidation.go#L68-L86 | train |
grafana/metrictank | consolidation/consolidation.go | GetAggFunc | func GetAggFunc(consolidator Consolidator) batch.AggFunc {
var consFunc batch.AggFunc
switch consolidator {
case Avg:
consFunc = batch.Avg
case Cnt:
consFunc = batch.Cnt
case Lst:
consFunc = batch.Lst
case Min:
consFunc = batch.Min
case Max:
consFunc = batch.Max
case Mult:
consFunc = batch.Mult
cas... | go | func GetAggFunc(consolidator Consolidator) batch.AggFunc {
var consFunc batch.AggFunc
switch consolidator {
case Avg:
consFunc = batch.Avg
case Cnt:
consFunc = batch.Cnt
case Lst:
consFunc = batch.Lst
case Min:
consFunc = batch.Min
case Max:
consFunc = batch.Max
case Mult:
consFunc = batch.Mult
cas... | [
"func",
"GetAggFunc",
"(",
"consolidator",
"Consolidator",
")",
"batch",
".",
"AggFunc",
"{",
"var",
"consFunc",
"batch",
".",
"AggFunc",
"\n",
"switch",
"consolidator",
"{",
"case",
"Avg",
":",
"consFunc",
"=",
"batch",
".",
"Avg",
"\n",
"case",
"Cnt",
":... | // map the consolidation to the respective aggregation function, if applicable. | [
"map",
"the",
"consolidation",
"to",
"the",
"respective",
"aggregation",
"function",
"if",
"applicable",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/consolidation/consolidation.go#L133-L160 | train |
grafana/metrictank | idx/bigtable/bigtable.go | updateBigtable | func (b *BigtableIdx) updateBigtable(now uint32, inMemory bool, archive idx.Archive, partition int32) idx.Archive {
// if the entry has not been saved for 1.5x updateInterval
// then perform a blocking save.
if archive.LastSave < (now - b.cfg.updateInterval32 - (b.cfg.updateInterval32 / 2)) {
log.Debugf("bigtable-... | go | func (b *BigtableIdx) updateBigtable(now uint32, inMemory bool, archive idx.Archive, partition int32) idx.Archive {
// if the entry has not been saved for 1.5x updateInterval
// then perform a blocking save.
if archive.LastSave < (now - b.cfg.updateInterval32 - (b.cfg.updateInterval32 / 2)) {
log.Debugf("bigtable-... | [
"func",
"(",
"b",
"*",
"BigtableIdx",
")",
"updateBigtable",
"(",
"now",
"uint32",
",",
"inMemory",
"bool",
",",
"archive",
"idx",
".",
"Archive",
",",
"partition",
"int32",
")",
"idx",
".",
"Archive",
"{",
"// if the entry has not been saved for 1.5x updateInterv... | // updateBigtable saves the archive to bigtable and
// updates the memory index with the updated fields. | [
"updateBigtable",
"saves",
"the",
"archive",
"to",
"bigtable",
"and",
"updates",
"the",
"memory",
"index",
"with",
"the",
"updated",
"fields",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/bigtable/bigtable.go#L282-L308 | train |
grafana/metrictank | mdata/cache/ccache_metric.go | NewCCacheMetric | func NewCCacheMetric(mkey schema.MKey) *CCacheMetric {
return &CCacheMetric{
MKey: mkey,
chunks: make(map[uint32]*CCacheChunk),
}
} | go | func NewCCacheMetric(mkey schema.MKey) *CCacheMetric {
return &CCacheMetric{
MKey: mkey,
chunks: make(map[uint32]*CCacheChunk),
}
} | [
"func",
"NewCCacheMetric",
"(",
"mkey",
"schema",
".",
"MKey",
")",
"*",
"CCacheMetric",
"{",
"return",
"&",
"CCacheMetric",
"{",
"MKey",
":",
"mkey",
",",
"chunks",
":",
"make",
"(",
"map",
"[",
"uint32",
"]",
"*",
"CCacheChunk",
")",
",",
"}",
"\n",
... | // NewCCacheMetric creates a CCacheMetric | [
"NewCCacheMetric",
"creates",
"a",
"CCacheMetric"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/cache/ccache_metric.go#L29-L34 | train |
grafana/metrictank | mdata/cache/ccache_metric.go | Del | func (mc *CCacheMetric) Del(ts uint32) int {
mc.Lock()
defer mc.Unlock()
if _, ok := mc.chunks[ts]; !ok {
return len(mc.chunks)
}
prev := mc.chunks[ts].Prev
next := mc.chunks[ts].Next
if prev != 0 {
if _, ok := mc.chunks[prev]; ok {
mc.chunks[prev].Next = 0
}
}
if next != 0 {
if _, ok := mc.chun... | go | func (mc *CCacheMetric) Del(ts uint32) int {
mc.Lock()
defer mc.Unlock()
if _, ok := mc.chunks[ts]; !ok {
return len(mc.chunks)
}
prev := mc.chunks[ts].Prev
next := mc.chunks[ts].Next
if prev != 0 {
if _, ok := mc.chunks[prev]; ok {
mc.chunks[prev].Next = 0
}
}
if next != 0 {
if _, ok := mc.chun... | [
"func",
"(",
"mc",
"*",
"CCacheMetric",
")",
"Del",
"(",
"ts",
"uint32",
")",
"int",
"{",
"mc",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mc",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"mc",
".",
"chunks",
"[",
"ts",
"]",
";",... | // Del deletes chunks for the given timestamp | [
"Del",
"deletes",
"chunks",
"for",
"the",
"given",
"timestamp"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/cache/ccache_metric.go#L37-L68 | train |
grafana/metrictank | mdata/cache/ccache_metric.go | Add | func (mc *CCacheMetric) Add(prev uint32, itergen chunk.IterGen) {
ts := itergen.T0
mc.Lock()
defer mc.Unlock()
if _, ok := mc.chunks[ts]; ok {
// chunk is already present. no need to error on that, just ignore it
return
}
mc.chunks[ts] = &CCacheChunk{
Ts: ts,
Prev: 0,
Next: 0,
Itgen: itergen,
... | go | func (mc *CCacheMetric) Add(prev uint32, itergen chunk.IterGen) {
ts := itergen.T0
mc.Lock()
defer mc.Unlock()
if _, ok := mc.chunks[ts]; ok {
// chunk is already present. no need to error on that, just ignore it
return
}
mc.chunks[ts] = &CCacheChunk{
Ts: ts,
Prev: 0,
Next: 0,
Itgen: itergen,
... | [
"func",
"(",
"mc",
"*",
"CCacheMetric",
")",
"Add",
"(",
"prev",
"uint32",
",",
"itergen",
"chunk",
".",
"IterGen",
")",
"{",
"ts",
":=",
"itergen",
".",
"T0",
"\n\n",
"mc",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mc",
".",
"Unlock",
"(",
")",
"\n... | // Add adds a chunk to the cache | [
"Add",
"adds",
"a",
"chunk",
"to",
"the",
"cache"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/cache/ccache_metric.go#L192-L255 | train |
grafana/metrictank | mdata/cache/ccache_metric.go | generateKeys | func (mc *CCacheMetric) generateKeys() {
keys := make([]uint32, 0, len(mc.chunks))
for k := range mc.chunks {
keys = append(keys, k)
}
sort.Sort(accnt.Uint32Asc(keys))
mc.keys = keys
} | go | func (mc *CCacheMetric) generateKeys() {
keys := make([]uint32, 0, len(mc.chunks))
for k := range mc.chunks {
keys = append(keys, k)
}
sort.Sort(accnt.Uint32Asc(keys))
mc.keys = keys
} | [
"func",
"(",
"mc",
"*",
"CCacheMetric",
")",
"generateKeys",
"(",
")",
"{",
"keys",
":=",
"make",
"(",
"[",
"]",
"uint32",
",",
"0",
",",
"len",
"(",
"mc",
".",
"chunks",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"mc",
".",
"chunks",
"{",
"key... | // generateKeys generates sorted slice of all chunk timestamps
// assumes we have at least read lock | [
"generateKeys",
"generates",
"sorted",
"slice",
"of",
"all",
"chunk",
"timestamps",
"assumes",
"we",
"have",
"at",
"least",
"read",
"lock"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/cache/ccache_metric.go#L259-L266 | train |
grafana/metrictank | mdata/cache/ccache_metric.go | lastTs | func (mc *CCacheMetric) lastTs() uint32 {
mc.RLock()
defer mc.RUnlock()
return mc.nextTs(mc.keys[len(mc.keys)-1])
} | go | func (mc *CCacheMetric) lastTs() uint32 {
mc.RLock()
defer mc.RUnlock()
return mc.nextTs(mc.keys[len(mc.keys)-1])
} | [
"func",
"(",
"mc",
"*",
"CCacheMetric",
")",
"lastTs",
"(",
")",
"uint32",
"{",
"mc",
".",
"RLock",
"(",
")",
"\n",
"defer",
"mc",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"mc",
".",
"nextTs",
"(",
"mc",
".",
"keys",
"[",
"len",
"(",
"mc",
"."... | // lastTs returns the last Ts of this metric cache
// since ranges are exclusive at the end this is actually the first Ts that is not cached | [
"lastTs",
"returns",
"the",
"last",
"Ts",
"of",
"this",
"metric",
"cache",
"since",
"ranges",
"are",
"exclusive",
"at",
"the",
"end",
"this",
"is",
"actually",
"the",
"first",
"Ts",
"that",
"is",
"not",
"cached"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/cache/ccache_metric.go#L299-L303 | train |
grafana/metrictank | mdata/cache/ccache_metric.go | seekAsc | func (mc *CCacheMetric) seekAsc(ts uint32) (uint32, bool) {
log.Debugf("CCacheMetric seekAsc: seeking for %d in the keys %+d", ts, mc.keys)
for i := 0; i < len(mc.keys) && mc.keys[i] <= ts; i++ {
if mc.nextTs(mc.keys[i]) > ts {
log.Debugf("CCacheMetric seekAsc: seek found ts %d is between %d and %d", ts, mc.key... | go | func (mc *CCacheMetric) seekAsc(ts uint32) (uint32, bool) {
log.Debugf("CCacheMetric seekAsc: seeking for %d in the keys %+d", ts, mc.keys)
for i := 0; i < len(mc.keys) && mc.keys[i] <= ts; i++ {
if mc.nextTs(mc.keys[i]) > ts {
log.Debugf("CCacheMetric seekAsc: seek found ts %d is between %d and %d", ts, mc.key... | [
"func",
"(",
"mc",
"*",
"CCacheMetric",
")",
"seekAsc",
"(",
"ts",
"uint32",
")",
"(",
"uint32",
",",
"bool",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"ts",
",",
"mc",
".",
"keys",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<... | // seekAsc finds the t0 of the chunk that contains ts, by searching from old to recent
// if not found or can't be sure returns 0, false
// assumes we already have at least a read lock | [
"seekAsc",
"finds",
"the",
"t0",
"of",
"the",
"chunk",
"that",
"contains",
"ts",
"by",
"searching",
"from",
"old",
"to",
"recent",
"if",
"not",
"found",
"or",
"can",
"t",
"be",
"sure",
"returns",
"0",
"false",
"assumes",
"we",
"already",
"have",
"at",
... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/cache/ccache_metric.go#L308-L320 | train |
grafana/metrictank | stats/out_graphite.go | writer | func (g *Graphite) writer() {
var conn net.Conn
var err error
var wg sync.WaitGroup
assureConn := func() {
connected.Set(conn != nil)
for conn == nil {
time.Sleep(time.Second)
conn, err = net.Dial("tcp", g.addr)
if err == nil {
log.Infof("stats now connected to %s", g.addr)
wg.Add(1)
go g.... | go | func (g *Graphite) writer() {
var conn net.Conn
var err error
var wg sync.WaitGroup
assureConn := func() {
connected.Set(conn != nil)
for conn == nil {
time.Sleep(time.Second)
conn, err = net.Dial("tcp", g.addr)
if err == nil {
log.Infof("stats now connected to %s", g.addr)
wg.Add(1)
go g.... | [
"func",
"(",
"g",
"*",
"Graphite",
")",
"writer",
"(",
")",
"{",
"var",
"conn",
"net",
".",
"Conn",
"\n",
"var",
"err",
"error",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n\n",
"assureConn",
":=",
"func",
"(",
")",
"{",
"connected",
".",
"Set"... | // writer connects to graphite and submits all pending data to it | [
"writer",
"connects",
"to",
"graphite",
"and",
"submits",
"all",
"pending",
"data",
"to",
"it"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/stats/out_graphite.go#L87-L127 | train |
grafana/metrictank | mdata/reorder_buffer.go | Add | func (rob *ReorderBuffer) Add(ts uint32, val float64) ([]schema.Point, error) {
ts = AggBoundary(ts, rob.interval)
// out of order and too old
if rob.buf[rob.newest].Ts != 0 && ts <= rob.buf[rob.newest].Ts-(uint32(cap(rob.buf))*rob.interval) {
return nil, errors.ErrMetricTooOld
}
var res []schema.Point
oldest... | go | func (rob *ReorderBuffer) Add(ts uint32, val float64) ([]schema.Point, error) {
ts = AggBoundary(ts, rob.interval)
// out of order and too old
if rob.buf[rob.newest].Ts != 0 && ts <= rob.buf[rob.newest].Ts-(uint32(cap(rob.buf))*rob.interval) {
return nil, errors.ErrMetricTooOld
}
var res []schema.Point
oldest... | [
"func",
"(",
"rob",
"*",
"ReorderBuffer",
")",
"Add",
"(",
"ts",
"uint32",
",",
"val",
"float64",
")",
"(",
"[",
"]",
"schema",
".",
"Point",
",",
"error",
")",
"{",
"ts",
"=",
"AggBoundary",
"(",
"ts",
",",
"rob",
".",
"interval",
")",
"\n\n",
"... | // Add adds the point if it falls within the window.
// it returns points that have been purged out of the buffer, as well as whether the add succeeded. | [
"Add",
"adds",
"the",
"point",
"if",
"it",
"falls",
"within",
"the",
"window",
".",
"it",
"returns",
"points",
"that",
"have",
"been",
"purged",
"out",
"of",
"the",
"buffer",
"as",
"well",
"as",
"whether",
"the",
"add",
"succeeded",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/reorder_buffer.go#L31-L67 | train |
grafana/metrictank | mdata/reorder_buffer.go | Get | func (rob *ReorderBuffer) Get() []schema.Point {
res := make([]schema.Point, 0, cap(rob.buf))
oldest := (rob.newest + 1) % uint32(cap(rob.buf))
for {
if rob.buf[oldest].Ts != 0 {
res = append(res, rob.buf[oldest])
}
if oldest == rob.newest {
break
}
oldest = (oldest + 1) % uint32(cap(rob.buf))
}
... | go | func (rob *ReorderBuffer) Get() []schema.Point {
res := make([]schema.Point, 0, cap(rob.buf))
oldest := (rob.newest + 1) % uint32(cap(rob.buf))
for {
if rob.buf[oldest].Ts != 0 {
res = append(res, rob.buf[oldest])
}
if oldest == rob.newest {
break
}
oldest = (oldest + 1) % uint32(cap(rob.buf))
}
... | [
"func",
"(",
"rob",
"*",
"ReorderBuffer",
")",
"Get",
"(",
")",
"[",
"]",
"schema",
".",
"Point",
"{",
"res",
":=",
"make",
"(",
"[",
"]",
"schema",
".",
"Point",
",",
"0",
",",
"cap",
"(",
"rob",
".",
"buf",
")",
")",
"\n",
"oldest",
":=",
"... | // Get returns the points in the buffer | [
"Get",
"returns",
"the",
"points",
"in",
"the",
"buffer"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/reorder_buffer.go#L70-L85 | train |
grafana/metrictank | cmd/mt-whisper-importer-reader/conversion.go | incResolution | func incResolution(points []whisper.Point, method string, inRes, outRes, rawRes uint32) map[string][]whisper.Point {
out := make(map[string][]whisper.Point)
resFactor := float64(outRes) / float64(rawRes)
for _, inPoint := range points {
if inPoint.Timestamp == 0 {
continue
}
// inPoints are guaranteed to b... | go | func incResolution(points []whisper.Point, method string, inRes, outRes, rawRes uint32) map[string][]whisper.Point {
out := make(map[string][]whisper.Point)
resFactor := float64(outRes) / float64(rawRes)
for _, inPoint := range points {
if inPoint.Timestamp == 0 {
continue
}
// inPoints are guaranteed to b... | [
"func",
"incResolution",
"(",
"points",
"[",
"]",
"whisper",
".",
"Point",
",",
"method",
"string",
",",
"inRes",
",",
"outRes",
",",
"rawRes",
"uint32",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"whisper",
".",
"Point",
"{",
"out",
":=",
"make",
"("... | // increase resolution of given points according to defined specs by generating
// additional datapoints to bridge the gaps between the given points. depending
// on what aggregation method is specified, those datapoints may be generated in
// slightly different ways. | [
"increase",
"resolution",
"of",
"given",
"points",
"according",
"to",
"defined",
"specs",
"by",
"generating",
"additional",
"datapoints",
"to",
"bridge",
"the",
"gaps",
"between",
"the",
"given",
"points",
".",
"depending",
"on",
"what",
"aggregation",
"method",
... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-whisper-importer-reader/conversion.go#L135-L176 | train |
grafana/metrictank | cmd/mt-whisper-importer-reader/conversion.go | decResolution | func decResolution(points []whisper.Point, method string, inRes, outRes, rawRes uint32) map[string][]whisper.Point {
out := make(map[string][]whisper.Point)
agg := mdata.NewAggregation()
currentBoundary := uint32(0)
flush := func() {
if agg.Cnt == 0 {
return
}
var value float64
switch method {
case "... | go | func decResolution(points []whisper.Point, method string, inRes, outRes, rawRes uint32) map[string][]whisper.Point {
out := make(map[string][]whisper.Point)
agg := mdata.NewAggregation()
currentBoundary := uint32(0)
flush := func() {
if agg.Cnt == 0 {
return
}
var value float64
switch method {
case "... | [
"func",
"decResolution",
"(",
"points",
"[",
"]",
"whisper",
".",
"Point",
",",
"method",
"string",
",",
"inRes",
",",
"outRes",
",",
"rawRes",
"uint32",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"whisper",
".",
"Point",
"{",
"out",
":=",
"make",
"("... | // decreases the resolution of given points by using the aggregation method specified
// in the second argument. emulates the way metrictank aggregates data when it generates
// rollups of the raw data. | [
"decreases",
"the",
"resolution",
"of",
"given",
"points",
"by",
"using",
"the",
"aggregation",
"method",
"specified",
"in",
"the",
"second",
"argument",
".",
"emulates",
"the",
"way",
"metrictank",
"aggregates",
"data",
"when",
"it",
"generates",
"rollups",
"of... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-whisper-importer-reader/conversion.go#L181-L259 | train |
grafana/metrictank | mdata/store_mock.go | Add | func (c *MockStore) Add(cwr *ChunkWriteRequest) {
if !c.Drop {
intervalHint := cwr.Key.Archive.Span()
itgen, err := chunk.NewIterGen(cwr.Chunk.Series.T0, intervalHint, cwr.Chunk.Encode(cwr.Span))
if err != nil {
panic(err)
}
c.results[cwr.Key] = append(c.results[cwr.Key], itgen)
c.items++
}
} | go | func (c *MockStore) Add(cwr *ChunkWriteRequest) {
if !c.Drop {
intervalHint := cwr.Key.Archive.Span()
itgen, err := chunk.NewIterGen(cwr.Chunk.Series.T0, intervalHint, cwr.Chunk.Encode(cwr.Span))
if err != nil {
panic(err)
}
c.results[cwr.Key] = append(c.results[cwr.Key], itgen)
c.items++
}
} | [
"func",
"(",
"c",
"*",
"MockStore",
")",
"Add",
"(",
"cwr",
"*",
"ChunkWriteRequest",
")",
"{",
"if",
"!",
"c",
".",
"Drop",
"{",
"intervalHint",
":=",
"cwr",
".",
"Key",
".",
"Archive",
".",
"Span",
"(",
")",
"\n",
"itgen",
",",
"err",
":=",
"ch... | // Add adds a chunk to the store | [
"Add",
"adds",
"a",
"chunk",
"to",
"the",
"store"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/store_mock.go#L40-L50 | train |
grafana/metrictank | mdata/chunk/encode.go | encode | func encode(span uint32, format Format, data []byte) []byte {
switch format {
case FormatStandardGoTszWithSpan, FormatGoTszLongWithSpan:
buf := new(bytes.Buffer)
binary.Write(buf, binary.LittleEndian, format)
spanCode, ok := RevChunkSpans[span]
if !ok {
// it's probably better to panic than to persist the... | go | func encode(span uint32, format Format, data []byte) []byte {
switch format {
case FormatStandardGoTszWithSpan, FormatGoTszLongWithSpan:
buf := new(bytes.Buffer)
binary.Write(buf, binary.LittleEndian, format)
spanCode, ok := RevChunkSpans[span]
if !ok {
// it's probably better to panic than to persist the... | [
"func",
"encode",
"(",
"span",
"uint32",
",",
"format",
"Format",
",",
"data",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"switch",
"format",
"{",
"case",
"FormatStandardGoTszWithSpan",
",",
"FormatGoTszLongWithSpan",
":",
"buf",
":=",
"new",
"(",
"byte... | // encode is a helper function to encode a chunk of data into various formats
// input data is copied | [
"encode",
"is",
"a",
"helper",
"function",
"to",
"encode",
"a",
"chunk",
"of",
"data",
"into",
"various",
"formats",
"input",
"data",
"is",
"copied"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/chunk/encode.go#L11-L32 | train |
grafana/metrictank | idx/memory/tag_query.go | parseExpression | func parseExpression(expr string) (expression, error) {
var pos int
prefix, regex, not := false, false, false
res := expression{}
// scan up to operator to get key
FIND_OPERATOR:
for ; pos < len(expr); pos++ {
switch expr[pos] {
case '=':
break FIND_OPERATOR
case '!':
not = true
break FIND_OPERATOR... | go | func parseExpression(expr string) (expression, error) {
var pos int
prefix, regex, not := false, false, false
res := expression{}
// scan up to operator to get key
FIND_OPERATOR:
for ; pos < len(expr); pos++ {
switch expr[pos] {
case '=':
break FIND_OPERATOR
case '!':
not = true
break FIND_OPERATOR... | [
"func",
"parseExpression",
"(",
"expr",
"string",
")",
"(",
"expression",
",",
"error",
")",
"{",
"var",
"pos",
"int",
"\n",
"prefix",
",",
"regex",
",",
"not",
":=",
"false",
",",
"false",
",",
"false",
"\n",
"res",
":=",
"expression",
"{",
"}",
"\n... | // parseExpression returns an expression that's been generated from the given
// string, in case of error the operator will be PARSING_ERROR. | [
"parseExpression",
"returns",
"an",
"expression",
"that",
"s",
"been",
"generated",
"from",
"the",
"given",
"string",
"in",
"case",
"of",
"error",
"the",
"operator",
"will",
"be",
"PARSING_ERROR",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/tag_query.go#L125-L218 | train |
grafana/metrictank | idx/memory/tag_query.go | getInitialByEqual | func (q *TagQuery) getInitialByEqual(expr kv, idCh chan schema.MKey, stopCh chan struct{}) {
defer q.wg.Done()
KEYS:
for k := range q.index[expr.key][expr.value] {
select {
case <-stopCh:
break KEYS
case idCh <- k:
}
}
close(idCh)
} | go | func (q *TagQuery) getInitialByEqual(expr kv, idCh chan schema.MKey, stopCh chan struct{}) {
defer q.wg.Done()
KEYS:
for k := range q.index[expr.key][expr.value] {
select {
case <-stopCh:
break KEYS
case idCh <- k:
}
}
close(idCh)
} | [
"func",
"(",
"q",
"*",
"TagQuery",
")",
"getInitialByEqual",
"(",
"expr",
"kv",
",",
"idCh",
"chan",
"schema",
".",
"MKey",
",",
"stopCh",
"chan",
"struct",
"{",
"}",
")",
"{",
"defer",
"q",
".",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"KEYS",
":",
... | // getInitialByEqual generates the initial resultset by executing the given equal expression | [
"getInitialByEqual",
"generates",
"the",
"initial",
"resultset",
"by",
"executing",
"the",
"given",
"equal",
"expression"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/tag_query.go#L338-L351 | train |
grafana/metrictank | idx/memory/tag_query.go | getInitialByPrefix | func (q *TagQuery) getInitialByPrefix(expr kv, idCh chan schema.MKey, stopCh chan struct{}) {
defer q.wg.Done()
VALUES:
for v, ids := range q.index[expr.key] {
if !strings.HasPrefix(v, expr.value) {
continue
}
for id := range ids {
select {
case <-stopCh:
break VALUES
case idCh <- id:
}
}... | go | func (q *TagQuery) getInitialByPrefix(expr kv, idCh chan schema.MKey, stopCh chan struct{}) {
defer q.wg.Done()
VALUES:
for v, ids := range q.index[expr.key] {
if !strings.HasPrefix(v, expr.value) {
continue
}
for id := range ids {
select {
case <-stopCh:
break VALUES
case idCh <- id:
}
}... | [
"func",
"(",
"q",
"*",
"TagQuery",
")",
"getInitialByPrefix",
"(",
"expr",
"kv",
",",
"idCh",
"chan",
"schema",
".",
"MKey",
",",
"stopCh",
"chan",
"struct",
"{",
"}",
")",
"{",
"defer",
"q",
".",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"VALUES",
":",... | // getInitialByPrefix generates the initial resultset by executing the given prefix match expression | [
"getInitialByPrefix",
"generates",
"the",
"initial",
"resultset",
"by",
"executing",
"the",
"given",
"prefix",
"match",
"expression"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/tag_query.go#L354-L373 | train |
grafana/metrictank | idx/memory/tag_query.go | getInitialByMatch | func (q *TagQuery) getInitialByMatch(expr kvRe, idCh chan schema.MKey, stopCh chan struct{}) {
defer q.wg.Done()
// shortcut if value == nil.
// this will simply match any value, like ^.+. since we know that every value
// in the index must not be empty, we can skip the matching.
if expr.value == nil {
VALUES1:
... | go | func (q *TagQuery) getInitialByMatch(expr kvRe, idCh chan schema.MKey, stopCh chan struct{}) {
defer q.wg.Done()
// shortcut if value == nil.
// this will simply match any value, like ^.+. since we know that every value
// in the index must not be empty, we can skip the matching.
if expr.value == nil {
VALUES1:
... | [
"func",
"(",
"q",
"*",
"TagQuery",
")",
"getInitialByMatch",
"(",
"expr",
"kvRe",
",",
"idCh",
"chan",
"schema",
".",
"MKey",
",",
"stopCh",
"chan",
"struct",
"{",
"}",
")",
"{",
"defer",
"q",
".",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"// shortcut if... | // getInitialByMatch generates the initial resultset by executing the given match expression | [
"getInitialByMatch",
"generates",
"the",
"initial",
"resultset",
"by",
"executing",
"the",
"given",
"match",
"expression"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/tag_query.go#L376-L413 | train |
grafana/metrictank | idx/memory/tag_query.go | getInitialByTagPrefix | func (q *TagQuery) getInitialByTagPrefix(idCh chan schema.MKey, stopCh chan struct{}) {
defer q.wg.Done()
TAGS:
for tag, values := range q.index {
if !strings.HasPrefix(tag, q.tagPrefix) {
continue
}
for _, ids := range values {
for id := range ids {
select {
case <-stopCh:
break TAGS
c... | go | func (q *TagQuery) getInitialByTagPrefix(idCh chan schema.MKey, stopCh chan struct{}) {
defer q.wg.Done()
TAGS:
for tag, values := range q.index {
if !strings.HasPrefix(tag, q.tagPrefix) {
continue
}
for _, ids := range values {
for id := range ids {
select {
case <-stopCh:
break TAGS
c... | [
"func",
"(",
"q",
"*",
"TagQuery",
")",
"getInitialByTagPrefix",
"(",
"idCh",
"chan",
"schema",
".",
"MKey",
",",
"stopCh",
"chan",
"struct",
"{",
"}",
")",
"{",
"defer",
"q",
".",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"TAGS",
":",
"for",
"tag",
","... | // getInitialByTagPrefix generates the initial resultset by creating a list of
// metric IDs of which at least one tag starts with the defined prefix | [
"getInitialByTagPrefix",
"generates",
"the",
"initial",
"resultset",
"by",
"creating",
"a",
"list",
"of",
"metric",
"IDs",
"of",
"which",
"at",
"least",
"one",
"tag",
"starts",
"with",
"the",
"defined",
"prefix"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/tag_query.go#L417-L438 | train |
grafana/metrictank | idx/memory/tag_query.go | getInitialByTagMatch | func (q *TagQuery) getInitialByTagMatch(idCh chan schema.MKey, stopCh chan struct{}) {
defer q.wg.Done()
TAGS:
for tag, values := range q.index {
if q.tagMatch.value.MatchString(tag) {
for _, ids := range values {
for id := range ids {
select {
case <-stopCh:
break TAGS
case idCh <- id:... | go | func (q *TagQuery) getInitialByTagMatch(idCh chan schema.MKey, stopCh chan struct{}) {
defer q.wg.Done()
TAGS:
for tag, values := range q.index {
if q.tagMatch.value.MatchString(tag) {
for _, ids := range values {
for id := range ids {
select {
case <-stopCh:
break TAGS
case idCh <- id:... | [
"func",
"(",
"q",
"*",
"TagQuery",
")",
"getInitialByTagMatch",
"(",
"idCh",
"chan",
"schema",
".",
"MKey",
",",
"stopCh",
"chan",
"struct",
"{",
"}",
")",
"{",
"defer",
"q",
".",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"TAGS",
":",
"for",
"tag",
",",... | // getInitialByTagMatch generates the initial resultset by creating a list of
// metric IDs of which at least one tag matches the defined regex | [
"getInitialByTagMatch",
"generates",
"the",
"initial",
"resultset",
"by",
"creating",
"a",
"list",
"of",
"metric",
"IDs",
"of",
"which",
"at",
"least",
"one",
"tag",
"matches",
"the",
"defined",
"regex"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/tag_query.go#L442-L461 | train |
grafana/metrictank | idx/memory/tag_query.go | filterIdsFromChan | func (q *TagQuery) filterIdsFromChan(idCh, resCh chan schema.MKey) {
for id := range idCh {
var def *idx.Archive
var ok bool
if def, ok = q.byId[id]; !ok {
// should never happen because every ID in the tag index
// must be present in the byId lookup table
corruptIndex.Inc()
log.Errorf("memory-idx: ... | go | func (q *TagQuery) filterIdsFromChan(idCh, resCh chan schema.MKey) {
for id := range idCh {
var def *idx.Archive
var ok bool
if def, ok = q.byId[id]; !ok {
// should never happen because every ID in the tag index
// must be present in the byId lookup table
corruptIndex.Inc()
log.Errorf("memory-idx: ... | [
"func",
"(",
"q",
"*",
"TagQuery",
")",
"filterIdsFromChan",
"(",
"idCh",
",",
"resCh",
"chan",
"schema",
".",
"MKey",
")",
"{",
"for",
"id",
":=",
"range",
"idCh",
"{",
"var",
"def",
"*",
"idx",
".",
"Archive",
"\n",
"var",
"ok",
"bool",
"\n\n",
"... | // filterIdsFromChan takes a channel of metric ids and runs them through the
// required tests to decide whether a metric should be part of the final
// result set or not
// it returns the final result set via the given resCh parameter | [
"filterIdsFromChan",
"takes",
"a",
"channel",
"of",
"metric",
"ids",
"and",
"runs",
"them",
"through",
"the",
"required",
"tests",
"to",
"decide",
"whether",
"a",
"metric",
"should",
"be",
"part",
"of",
"the",
"final",
"result",
"set",
"or",
"not",
"it",
"... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/tag_query.go#L727-L747 | train |
grafana/metrictank | idx/memory/tag_query.go | sortByCost | func (q *TagQuery) sortByCost() {
for i, kv := range q.equal {
q.equal[i].cost = uint(len(q.index[kv.key][kv.value]))
}
// for prefix and match clauses we can't determine the actual cost
// without actually evaluating them, so we estimate based on
// cardinality of the key
for i, kv := range q.prefix {
q.pre... | go | func (q *TagQuery) sortByCost() {
for i, kv := range q.equal {
q.equal[i].cost = uint(len(q.index[kv.key][kv.value]))
}
// for prefix and match clauses we can't determine the actual cost
// without actually evaluating them, so we estimate based on
// cardinality of the key
for i, kv := range q.prefix {
q.pre... | [
"func",
"(",
"q",
"*",
"TagQuery",
")",
"sortByCost",
"(",
")",
"{",
"for",
"i",
",",
"kv",
":=",
"range",
"q",
".",
"equal",
"{",
"q",
".",
"equal",
"[",
"i",
"]",
".",
"cost",
"=",
"uint",
"(",
"len",
"(",
"q",
".",
"index",
"[",
"kv",
".... | // sortByCost tries to estimate the cost of different expressions and sort them
// in increasing order
// this is to reduce the result set cheaply and only apply expensive tests to an
// already reduced set of results | [
"sortByCost",
"tries",
"to",
"estimate",
"the",
"cost",
"of",
"different",
"expressions",
"and",
"sort",
"them",
"in",
"increasing",
"order",
"this",
"is",
"to",
"reduce",
"the",
"result",
"set",
"cheaply",
"and",
"only",
"apply",
"expensive",
"tests",
"to",
... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/tag_query.go#L753-L774 | train |
grafana/metrictank | idx/memory/tag_query.go | Run | func (q *TagQuery) Run(index TagIndex, byId map[schema.MKey]*idx.Archive) IdSet {
q.index = index
q.byId = byId
q.sortByCost()
idCh, _ := q.getInitialIds()
resCh := make(chan schema.MKey)
// start the tag query workers. they'll consume the ids on the idCh and
// evaluate for each of them whether it satisfies ... | go | func (q *TagQuery) Run(index TagIndex, byId map[schema.MKey]*idx.Archive) IdSet {
q.index = index
q.byId = byId
q.sortByCost()
idCh, _ := q.getInitialIds()
resCh := make(chan schema.MKey)
// start the tag query workers. they'll consume the ids on the idCh and
// evaluate for each of them whether it satisfies ... | [
"func",
"(",
"q",
"*",
"TagQuery",
")",
"Run",
"(",
"index",
"TagIndex",
",",
"byId",
"map",
"[",
"schema",
".",
"MKey",
"]",
"*",
"idx",
".",
"Archive",
")",
"IdSet",
"{",
"q",
".",
"index",
"=",
"index",
"\n",
"q",
".",
"byId",
"=",
"byId",
"... | // Run executes the tag query on the given index and returns a list of ids | [
"Run",
"executes",
"the",
"tag",
"query",
"on",
"the",
"given",
"index",
"and",
"returns",
"a",
"list",
"of",
"ids"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/tag_query.go#L777-L807 | train |
grafana/metrictank | idx/memory/tag_query.go | filterTagsFromChan | func (q *TagQuery) filterTagsFromChan(idCh chan schema.MKey, tagCh chan string, stopCh chan struct{}, omitTagFilters bool) {
// used to prevent that this worker thread will push the same result into
// the chan twice
resultsCache := make(map[string]struct{})
IDS:
for id := range idCh {
var def *idx.Archive
var... | go | func (q *TagQuery) filterTagsFromChan(idCh chan schema.MKey, tagCh chan string, stopCh chan struct{}, omitTagFilters bool) {
// used to prevent that this worker thread will push the same result into
// the chan twice
resultsCache := make(map[string]struct{})
IDS:
for id := range idCh {
var def *idx.Archive
var... | [
"func",
"(",
"q",
"*",
"TagQuery",
")",
"filterTagsFromChan",
"(",
"idCh",
"chan",
"schema",
".",
"MKey",
",",
"tagCh",
"chan",
"string",
",",
"stopCh",
"chan",
"struct",
"{",
"}",
",",
"omitTagFilters",
"bool",
")",
"{",
"// used to prevent that this worker t... | // filterTagsFromChan takes a channel of metric IDs and evaluates each of them
// according to the criteria associated with this query
// those that pass all the tests will have their relevant tags extracted, which
// are then pushed into the given tag channel | [
"filterTagsFromChan",
"takes",
"a",
"channel",
"of",
"metric",
"IDs",
"and",
"evaluates",
"each",
"of",
"them",
"according",
"to",
"the",
"criteria",
"associated",
"with",
"this",
"query",
"those",
"that",
"pass",
"all",
"the",
"tests",
"will",
"have",
"their"... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/tag_query.go#L841-L928 | train |
grafana/metrictank | idx/memory/tag_query.go | RunGetTags | func (q *TagQuery) RunGetTags(index TagIndex, byId map[schema.MKey]*idx.Archive) map[string]struct{} {
q.index = index
q.byId = byId
maxTagCount := int32(math.MaxInt32)
// start a thread to calculate the maximum possible number of tags.
// this might not always complete before the query execution, but in most
/... | go | func (q *TagQuery) RunGetTags(index TagIndex, byId map[schema.MKey]*idx.Archive) map[string]struct{} {
q.index = index
q.byId = byId
maxTagCount := int32(math.MaxInt32)
// start a thread to calculate the maximum possible number of tags.
// this might not always complete before the query execution, but in most
/... | [
"func",
"(",
"q",
"*",
"TagQuery",
")",
"RunGetTags",
"(",
"index",
"TagIndex",
",",
"byId",
"map",
"[",
"schema",
".",
"MKey",
"]",
"*",
"idx",
".",
"Archive",
")",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"q",
".",
"index",
"=",
"ind... | // RunGetTags executes the tag query and returns all the tags of the
// resulting metrics | [
"RunGetTags",
"executes",
"the",
"tag",
"query",
"and",
"returns",
"all",
"the",
"tags",
"of",
"the",
"resulting",
"metrics"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/tag_query.go#L958-L1012 | train |
grafana/metrictank | mdata/chunk/tsz/tsz.go | NewSeries4h | func NewSeries4h(t0 uint32) *Series4h {
s := Series4h{
T0: t0,
leading: ^uint8(0),
}
// block header
s.bw.writeBits(uint64(t0), 32)
return &s
} | go | func NewSeries4h(t0 uint32) *Series4h {
s := Series4h{
T0: t0,
leading: ^uint8(0),
}
// block header
s.bw.writeBits(uint64(t0), 32)
return &s
} | [
"func",
"NewSeries4h",
"(",
"t0",
"uint32",
")",
"*",
"Series4h",
"{",
"s",
":=",
"Series4h",
"{",
"T0",
":",
"t0",
",",
"leading",
":",
"^",
"uint8",
"(",
"0",
")",
",",
"}",
"\n\n",
"// block header",
"s",
".",
"bw",
".",
"writeBits",
"(",
"uint6... | // NewSeries4h creates a new Series4h | [
"NewSeries4h",
"creates",
"a",
"new",
"Series4h"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/chunk/tsz/tsz.go#L39-L50 | train |
grafana/metrictank | mdata/chunk/tsz/tsz.go | Push | func (s *Series4h) Push(t uint32, v float64) {
s.Lock()
defer s.Unlock()
if s.t == 0 {
// first point
s.t = t
s.val = v
s.tDelta = t - s.T0
s.bw.writeBits(uint64(s.tDelta), 14)
s.bw.writeBits(math.Float64bits(v), 64)
return
}
tDelta := t - s.t
dod := int32(tDelta - s.tDelta)
switch {
case dod =... | go | func (s *Series4h) Push(t uint32, v float64) {
s.Lock()
defer s.Unlock()
if s.t == 0 {
// first point
s.t = t
s.val = v
s.tDelta = t - s.T0
s.bw.writeBits(uint64(s.tDelta), 14)
s.bw.writeBits(math.Float64bits(v), 64)
return
}
tDelta := t - s.t
dod := int32(tDelta - s.tDelta)
switch {
case dod =... | [
"func",
"(",
"s",
"*",
"Series4h",
")",
"Push",
"(",
"t",
"uint32",
",",
"v",
"float64",
")",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"s",
".",
"t",
"==",
"0",
"{",
"// first point",
"s",
".... | // Push a timestamp and value to the series | [
"Push",
"a",
"timestamp",
"and",
"value",
"to",
"the",
"series"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/chunk/tsz/tsz.go#L70-L142 | train |
grafana/metrictank | mdata/chunk/tsz/tsz.go | Iter | func (s *Series4h) Iter(intervalHint uint32) *Iter4h {
s.Lock()
w := s.bw.clone()
s.Unlock()
finishV1(w)
iter, _ := bstreamIterator4h(w, intervalHint)
return iter
} | go | func (s *Series4h) Iter(intervalHint uint32) *Iter4h {
s.Lock()
w := s.bw.clone()
s.Unlock()
finishV1(w)
iter, _ := bstreamIterator4h(w, intervalHint)
return iter
} | [
"func",
"(",
"s",
"*",
"Series4h",
")",
"Iter",
"(",
"intervalHint",
"uint32",
")",
"*",
"Iter4h",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"w",
":=",
"s",
".",
"bw",
".",
"clone",
"(",
")",
"\n",
"s",
".",
"Unlock",
"(",
")",
"\n\n",
"finishV1",... | // Iter4h lets you iterate over a series. It is not concurrency-safe. | [
"Iter4h",
"lets",
"you",
"iterate",
"over",
"a",
"series",
".",
"It",
"is",
"not",
"concurrency",
"-",
"safe",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/chunk/tsz/tsz.go#L145-L153 | train |
grafana/metrictank | mdata/chunk/tsz/tsz.go | NewIterator4h | func NewIterator4h(b []byte, intervalHint uint32) (*Iter4h, error) {
return bstreamIterator4h(newBReader(b), intervalHint)
} | go | func NewIterator4h(b []byte, intervalHint uint32) (*Iter4h, error) {
return bstreamIterator4h(newBReader(b), intervalHint)
} | [
"func",
"NewIterator4h",
"(",
"b",
"[",
"]",
"byte",
",",
"intervalHint",
"uint32",
")",
"(",
"*",
"Iter4h",
",",
"error",
")",
"{",
"return",
"bstreamIterator4h",
"(",
"newBReader",
"(",
"b",
")",
",",
"intervalHint",
")",
"\n",
"}"
] | // NewIterator4h creates an Iter4h | [
"NewIterator4h",
"creates",
"an",
"Iter4h"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/chunk/tsz/tsz.go#L191-L193 | train |
grafana/metrictank | cluster/manager.go | clusterStats | func (c *MemberlistManager) clusterStats() {
primReady := 0
primNotReady := 0
secReady := 0
secNotReady := 0
queryReady := 0
queryNotReady := 0
partitions := make(map[int32]int)
for _, p := range c.members {
if p.Primary {
if p.IsReady() {
primReady++
} else {
primNotReady++
}
} else if p.M... | go | func (c *MemberlistManager) clusterStats() {
primReady := 0
primNotReady := 0
secReady := 0
secNotReady := 0
queryReady := 0
queryNotReady := 0
partitions := make(map[int32]int)
for _, p := range c.members {
if p.Primary {
if p.IsReady() {
primReady++
} else {
primNotReady++
}
} else if p.M... | [
"func",
"(",
"c",
"*",
"MemberlistManager",
")",
"clusterStats",
"(",
")",
"{",
"primReady",
":=",
"0",
"\n",
"primNotReady",
":=",
"0",
"\n",
"secReady",
":=",
"0",
"\n",
"secNotReady",
":=",
"0",
"\n",
"queryReady",
":=",
"0",
"\n",
"queryNotReady",
":... | // report the cluster stats every time there is a change to the cluster state.
// it is assumed that the lock is acquired before calling this method. | [
"report",
"the",
"cluster",
"stats",
"every",
"time",
"there",
"is",
"a",
"change",
"to",
"the",
"cluster",
"state",
".",
"it",
"is",
"assumed",
"that",
"the",
"lock",
"is",
"acquired",
"before",
"calling",
"this",
"method",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/manager.go#L190-L231 | train |
grafana/metrictank | cluster/manager.go | NodeMeta | func (c *MemberlistManager) NodeMeta(limit int) []byte {
c.RLock()
meta, err := json.Marshal(c.members[c.nodeName])
c.RUnlock()
if err != nil {
log.Fatalf("CLU manager: %s", err.Error())
}
return meta
} | go | func (c *MemberlistManager) NodeMeta(limit int) []byte {
c.RLock()
meta, err := json.Marshal(c.members[c.nodeName])
c.RUnlock()
if err != nil {
log.Fatalf("CLU manager: %s", err.Error())
}
return meta
} | [
"func",
"(",
"c",
"*",
"MemberlistManager",
")",
"NodeMeta",
"(",
"limit",
"int",
")",
"[",
"]",
"byte",
"{",
"c",
".",
"RLock",
"(",
")",
"\n",
"meta",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"c",
".",
"members",
"[",
"c",
".",
"nodeName"... | // NodeMeta is used to retrieve meta-data about the current node
// when broadcasting an alive message. It's length is limited to
// the given byte size. This metadata is available in the HTTPNode structure. | [
"NodeMeta",
"is",
"used",
"to",
"retrieve",
"meta",
"-",
"data",
"about",
"the",
"current",
"node",
"when",
"broadcasting",
"an",
"alive",
"message",
".",
"It",
"s",
"length",
"is",
"limited",
"to",
"the",
"given",
"byte",
"size",
".",
"This",
"metadata",
... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/manager.go#L331-L339 | train |
grafana/metrictank | cluster/manager.go | IsReady | func (c *MemberlistManager) IsReady() bool {
c.RLock()
defer c.RUnlock()
return c.members[c.nodeName].IsReady()
} | go | func (c *MemberlistManager) IsReady() bool {
c.RLock()
defer c.RUnlock()
return c.members[c.nodeName].IsReady()
} | [
"func",
"(",
"c",
"*",
"MemberlistManager",
")",
"IsReady",
"(",
")",
"bool",
"{",
"c",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"c",
".",
"members",
"[",
"c",
".",
"nodeName",
"]",
".",
"IsReady",
"("... | // Returns true if this node is a ready to accept requests
// from users. | [
"Returns",
"true",
"if",
"this",
"node",
"is",
"a",
"ready",
"to",
"accept",
"requests",
"from",
"users",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/manager.go#L377-L381 | train |
grafana/metrictank | cluster/manager.go | SetState | func (c *MemberlistManager) SetState(state NodeState) {
c.Lock()
node := c.members[c.nodeName]
if !node.SetState(state) {
c.Unlock()
return
}
c.members[c.nodeName] = node
c.Unlock()
nodeReady.Set(state == NodeReady)
c.BroadcastUpdate()
} | go | func (c *MemberlistManager) SetState(state NodeState) {
c.Lock()
node := c.members[c.nodeName]
if !node.SetState(state) {
c.Unlock()
return
}
c.members[c.nodeName] = node
c.Unlock()
nodeReady.Set(state == NodeReady)
c.BroadcastUpdate()
} | [
"func",
"(",
"c",
"*",
"MemberlistManager",
")",
"SetState",
"(",
"state",
"NodeState",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"node",
":=",
"c",
".",
"members",
"[",
"c",
".",
"nodeName",
"]",
"\n",
"if",
"!",
"node",
".",
"SetState",
"(",
... | // Set the state of this node. | [
"Set",
"the",
"state",
"of",
"this",
"node",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/manager.go#L389-L400 | train |
grafana/metrictank | cluster/manager.go | IsPrimary | func (c *MemberlistManager) IsPrimary() bool {
c.RLock()
defer c.RUnlock()
return c.members[c.nodeName].Primary
} | go | func (c *MemberlistManager) IsPrimary() bool {
c.RLock()
defer c.RUnlock()
return c.members[c.nodeName].Primary
} | [
"func",
"(",
"c",
"*",
"MemberlistManager",
")",
"IsPrimary",
"(",
")",
"bool",
"{",
"c",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"c",
".",
"members",
"[",
"c",
".",
"nodeName",
"]",
".",
"Primary",
"... | // Returns true if the this node is a set as a primary node that should write data to cassandra. | [
"Returns",
"true",
"if",
"the",
"this",
"node",
"is",
"a",
"set",
"as",
"a",
"primary",
"node",
"that",
"should",
"write",
"data",
"to",
"cassandra",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/manager.go#L403-L407 | train |
grafana/metrictank | cluster/manager.go | SetPrimary | func (c *MemberlistManager) SetPrimary(primary bool) {
c.Lock()
node := c.members[c.nodeName]
if !node.SetPrimary(primary) {
c.Unlock()
return
}
c.members[c.nodeName] = node
c.Unlock()
nodePrimary.Set(primary)
c.BroadcastUpdate()
} | go | func (c *MemberlistManager) SetPrimary(primary bool) {
c.Lock()
node := c.members[c.nodeName]
if !node.SetPrimary(primary) {
c.Unlock()
return
}
c.members[c.nodeName] = node
c.Unlock()
nodePrimary.Set(primary)
c.BroadcastUpdate()
} | [
"func",
"(",
"c",
"*",
"MemberlistManager",
")",
"SetPrimary",
"(",
"primary",
"bool",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"node",
":=",
"c",
".",
"members",
"[",
"c",
".",
"nodeName",
"]",
"\n",
"if",
"!",
"node",
".",
"SetPrimary",
"(",
... | // SetPrimary sets the primary status of this node | [
"SetPrimary",
"sets",
"the",
"primary",
"status",
"of",
"this",
"node"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cluster/manager.go#L410-L421 | train |
grafana/metrictank | expr/func_movingaverage.go | Signature | func (s *FuncMovingAverage) Signature() ([]Arg, []Arg) {
return []Arg{
ArgSeriesList{val: &s.in},
// this could be an int OR a string.
// we need to figure out the interval of the data we will consume
// and request from -= interval * points
// interestingly the from adjustment might mean the archive TTL is ... | go | func (s *FuncMovingAverage) Signature() ([]Arg, []Arg) {
return []Arg{
ArgSeriesList{val: &s.in},
// this could be an int OR a string.
// we need to figure out the interval of the data we will consume
// and request from -= interval * points
// interestingly the from adjustment might mean the archive TTL is ... | [
"func",
"(",
"s",
"*",
"FuncMovingAverage",
")",
"Signature",
"(",
")",
"(",
"[",
"]",
"Arg",
",",
"[",
"]",
"Arg",
")",
"{",
"return",
"[",
"]",
"Arg",
"{",
"ArgSeriesList",
"{",
"val",
":",
"&",
"s",
".",
"in",
"}",
",",
"// this could be an int ... | // note if input is 1 series, then output is too. not sure how to communicate that | [
"note",
"if",
"input",
"is",
"1",
"series",
"then",
"output",
"is",
"too",
".",
"not",
"sure",
"how",
"to",
"communicate",
"that"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/expr/func_movingaverage.go#L18-L28 | train |
grafana/metrictank | expr/func_aggregate.go | NewAggregateConstructor | func NewAggregateConstructor(aggDescription string, aggFunc crossSeriesAggFunc) func() GraphiteFunc {
return func() GraphiteFunc {
return &FuncAggregate{agg: seriesAggregator{function: aggFunc, name: aggDescription}}
}
} | go | func NewAggregateConstructor(aggDescription string, aggFunc crossSeriesAggFunc) func() GraphiteFunc {
return func() GraphiteFunc {
return &FuncAggregate{agg: seriesAggregator{function: aggFunc, name: aggDescription}}
}
} | [
"func",
"NewAggregateConstructor",
"(",
"aggDescription",
"string",
",",
"aggFunc",
"crossSeriesAggFunc",
")",
"func",
"(",
")",
"GraphiteFunc",
"{",
"return",
"func",
"(",
")",
"GraphiteFunc",
"{",
"return",
"&",
"FuncAggregate",
"{",
"agg",
":",
"seriesAggregato... | // NewAggregateConstructor takes an agg string and returns a constructor function | [
"NewAggregateConstructor",
"takes",
"an",
"agg",
"string",
"and",
"returns",
"a",
"constructor",
"function"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/expr/func_aggregate.go#L16-L20 | train |
grafana/metrictank | input/kafkamdm/kafkamdm.go | tryGetOffset | func (k *KafkaMdm) tryGetOffset(topic string, partition int32, offset int64, attempts int, sleep time.Duration) (int64, error) {
var val int64
var err error
var offsetStr string
switch offset {
case sarama.OffsetNewest:
offsetStr = "newest"
case sarama.OffsetOldest:
offsetStr = "oldest"
default:
offsetSt... | go | func (k *KafkaMdm) tryGetOffset(topic string, partition int32, offset int64, attempts int, sleep time.Duration) (int64, error) {
var val int64
var err error
var offsetStr string
switch offset {
case sarama.OffsetNewest:
offsetStr = "newest"
case sarama.OffsetOldest:
offsetStr = "oldest"
default:
offsetSt... | [
"func",
"(",
"k",
"*",
"KafkaMdm",
")",
"tryGetOffset",
"(",
"topic",
"string",
",",
"partition",
"int32",
",",
"offset",
"int64",
",",
"attempts",
"int",
",",
"sleep",
"time",
".",
"Duration",
")",
"(",
"int64",
",",
"error",
")",
"{",
"var",
"val",
... | // tryGetOffset will to query kafka repeatedly for the requested offset and give up after attempts unsuccesfull attempts
// an error is returned when it had to give up | [
"tryGetOffset",
"will",
"to",
"query",
"kafka",
"repeatedly",
"for",
"the",
"requested",
"offset",
"and",
"give",
"up",
"after",
"attempts",
"unsuccesfull",
"attempts",
"an",
"error",
"is",
"returned",
"when",
"it",
"had",
"to",
"give",
"up"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/input/kafkamdm/kafkamdm.go#L218-L249 | train |
grafana/metrictank | input/kafkamdm/kafkamdm.go | consumePartition | func (k *KafkaMdm) consumePartition(topic string, partition int32, currentOffset int64) {
defer k.wg.Done()
// determine the pos of the topic and the initial offset of our consumer
newest, err := k.tryGetOffset(topic, partition, sarama.OffsetNewest, 7, time.Second*10)
if err != nil {
log.Errorf("kafkamdm: %s", e... | go | func (k *KafkaMdm) consumePartition(topic string, partition int32, currentOffset int64) {
defer k.wg.Done()
// determine the pos of the topic and the initial offset of our consumer
newest, err := k.tryGetOffset(topic, partition, sarama.OffsetNewest, 7, time.Second*10)
if err != nil {
log.Errorf("kafkamdm: %s", e... | [
"func",
"(",
"k",
"*",
"KafkaMdm",
")",
"consumePartition",
"(",
"topic",
"string",
",",
"partition",
"int32",
",",
"currentOffset",
"int64",
")",
"{",
"defer",
"k",
".",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"// determine the pos of the topic and the initial off... | // consumePartition consumes from the topic until k.shutdown is triggered. | [
"consumePartition",
"consumes",
"from",
"the",
"topic",
"until",
"k",
".",
"shutdown",
"is",
"triggered",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/input/kafkamdm/kafkamdm.go#L252-L307 | train |
grafana/metrictank | idx/cassandra/cassandra.go | InitBare | func (c *CasIdx) InitBare() error {
var err error
tmpSession, err := c.cluster.CreateSession()
if err != nil {
return fmt.Errorf("failed to create cassandra session: %s", err)
}
// read templates
schemaKeyspace := util.ReadEntry(c.cfg.schemaFile, "schema_keyspace").(string)
schemaTable := util.ReadEntry(c.cfg... | go | func (c *CasIdx) InitBare() error {
var err error
tmpSession, err := c.cluster.CreateSession()
if err != nil {
return fmt.Errorf("failed to create cassandra session: %s", err)
}
// read templates
schemaKeyspace := util.ReadEntry(c.cfg.schemaFile, "schema_keyspace").(string)
schemaTable := util.ReadEntry(c.cfg... | [
"func",
"(",
"c",
"*",
"CasIdx",
")",
"InitBare",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"tmpSession",
",",
"err",
":=",
"c",
".",
"cluster",
".",
"CreateSession",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
... | // InitBare makes sure the keyspace, tables, and index exists in cassandra and creates a session | [
"InitBare",
"makes",
"sure",
"the",
"keyspace",
"tables",
"and",
"index",
"exists",
"in",
"cassandra",
"and",
"creates",
"a",
"session"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/cassandra/cassandra.go#L113-L171 | train |
grafana/metrictank | idx/cassandra/cassandra.go | EnsureArchiveTableExists | func (c *CasIdx) EnsureArchiveTableExists(session *gocql.Session) error {
var err error
if session == nil {
session, err = c.cluster.CreateSession()
if err != nil {
return fmt.Errorf("failed to create cassandra session: %s", err)
}
}
schemaArchiveTable := util.ReadEntry(c.cfg.schemaFile, "schema_archive_t... | go | func (c *CasIdx) EnsureArchiveTableExists(session *gocql.Session) error {
var err error
if session == nil {
session, err = c.cluster.CreateSession()
if err != nil {
return fmt.Errorf("failed to create cassandra session: %s", err)
}
}
schemaArchiveTable := util.ReadEntry(c.cfg.schemaFile, "schema_archive_t... | [
"func",
"(",
"c",
"*",
"CasIdx",
")",
"EnsureArchiveTableExists",
"(",
"session",
"*",
"gocql",
".",
"Session",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"session",
"==",
"nil",
"{",
"session",
",",
"err",
"=",
"c",
".",
"cluster",
".",
"... | // EnsureArchiveTableExists checks if the index archive table exists or not. If it does not exist and
// the create-keyspace flag is true, then it will create it, if it doesn't exist and the create-keyspace
// flag is false, then it will return an error. If the table exists then it just returns nil.
// The index archiv... | [
"EnsureArchiveTableExists",
"checks",
"if",
"the",
"index",
"archive",
"table",
"exists",
"or",
"not",
".",
"If",
"it",
"does",
"not",
"exist",
"and",
"the",
"create",
"-",
"keyspace",
"flag",
"is",
"true",
"then",
"it",
"will",
"create",
"it",
"if",
"it",... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/cassandra/cassandra.go#L178-L206 | train |
grafana/metrictank | idx/cassandra/cassandra.go | Init | func (c *CasIdx) Init() error {
log.Infof("initializing cassandra-idx. Hosts=%s", c.cfg.hosts)
if err := c.MemoryIndex.Init(); err != nil {
return err
}
if err := c.InitBare(); err != nil {
return err
}
if c.cfg.updateCassIdx {
c.wg.Add(c.cfg.numConns)
for i := 0; i < c.cfg.numConns; i++ {
go c.proce... | go | func (c *CasIdx) Init() error {
log.Infof("initializing cassandra-idx. Hosts=%s", c.cfg.hosts)
if err := c.MemoryIndex.Init(); err != nil {
return err
}
if err := c.InitBare(); err != nil {
return err
}
if c.cfg.updateCassIdx {
c.wg.Add(c.cfg.numConns)
for i := 0; i < c.cfg.numConns; i++ {
go c.proce... | [
"func",
"(",
"c",
"*",
"CasIdx",
")",
"Init",
"(",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"c",
".",
"cfg",
".",
"hosts",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"MemoryIndex",
".",
"Init",
"(",
")",
";",
"err",
"!=",
... | // Init makes sure the needed keyspace, table, index in cassandra exists, creates the session,
// rebuilds the in-memory index, sets up write queues, metrics and pruning routines | [
"Init",
"makes",
"sure",
"the",
"needed",
"keyspace",
"table",
"index",
"in",
"cassandra",
"exists",
"creates",
"the",
"session",
"rebuilds",
"the",
"in",
"-",
"memory",
"index",
"sets",
"up",
"write",
"queues",
"metrics",
"and",
"pruning",
"routines"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/cassandra/cassandra.go#L210-L235 | train |
grafana/metrictank | idx/cassandra/cassandra.go | updateCassandra | func (c *CasIdx) updateCassandra(now uint32, inMemory bool, archive idx.Archive, partition int32) idx.Archive {
// if the entry has not been saved for 1.5x updateInterval
// then perform a blocking save.
if archive.LastSave < (now - c.updateInterval32 - c.updateInterval32/2) {
log.Debugf("cassandra-idx: updating d... | go | func (c *CasIdx) updateCassandra(now uint32, inMemory bool, archive idx.Archive, partition int32) idx.Archive {
// if the entry has not been saved for 1.5x updateInterval
// then perform a blocking save.
if archive.LastSave < (now - c.updateInterval32 - c.updateInterval32/2) {
log.Debugf("cassandra-idx: updating d... | [
"func",
"(",
"c",
"*",
"CasIdx",
")",
"updateCassandra",
"(",
"now",
"uint32",
",",
"inMemory",
"bool",
",",
"archive",
"idx",
".",
"Archive",
",",
"partition",
"int32",
")",
"idx",
".",
"Archive",
"{",
"// if the entry has not been saved for 1.5x updateInterval",... | // updateCassandra saves the archive to cassandra and
// updates the memory index with the updated fields. | [
"updateCassandra",
"saves",
"the",
"archive",
"to",
"cassandra",
"and",
"updates",
"the",
"memory",
"index",
"with",
"the",
"updated",
"fields",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/cassandra/cassandra.go#L316-L342 | train |
grafana/metrictank | idx/cassandra/cassandra.go | LoadPartitions | func (c *CasIdx) LoadPartitions(partitions []int32, defs []schema.MetricDefinition, now time.Time) []schema.MetricDefinition {
placeholders := make([]string, len(partitions))
for i, p := range partitions {
placeholders[i] = strconv.Itoa(int(p))
}
q := fmt.Sprintf("SELECT id, orgid, partition, name, interval, unit... | go | func (c *CasIdx) LoadPartitions(partitions []int32, defs []schema.MetricDefinition, now time.Time) []schema.MetricDefinition {
placeholders := make([]string, len(partitions))
for i, p := range partitions {
placeholders[i] = strconv.Itoa(int(p))
}
q := fmt.Sprintf("SELECT id, orgid, partition, name, interval, unit... | [
"func",
"(",
"c",
"*",
"CasIdx",
")",
"LoadPartitions",
"(",
"partitions",
"[",
"]",
"int32",
",",
"defs",
"[",
"]",
"schema",
".",
"MetricDefinition",
",",
"now",
"time",
".",
"Time",
")",
"[",
"]",
"schema",
".",
"MetricDefinition",
"{",
"placeholders"... | // LoadPartitions appends MetricDefinitions from the given partitions to defs and returns the modified defs, honoring pruning settings relative to now | [
"LoadPartitions",
"appends",
"MetricDefinitions",
"from",
"the",
"given",
"partitions",
"to",
"defs",
"and",
"returns",
"the",
"modified",
"defs",
"honoring",
"pruning",
"settings",
"relative",
"to",
"now"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/cassandra/cassandra.go#L379-L387 | train |
grafana/metrictank | idx/cassandra/cassandra.go | load | func (c *CasIdx) load(defs []schema.MetricDefinition, iter cqlIterator, now time.Time) []schema.MetricDefinition {
defsByNames := make(map[string][]*schema.MetricDefinition)
var id, name, unit, mtype string
var orgId, interval int
var partition int32
var lastupdate int64
var tags []string
for iter.Scan(&id, &org... | go | func (c *CasIdx) load(defs []schema.MetricDefinition, iter cqlIterator, now time.Time) []schema.MetricDefinition {
defsByNames := make(map[string][]*schema.MetricDefinition)
var id, name, unit, mtype string
var orgId, interval int
var partition int32
var lastupdate int64
var tags []string
for iter.Scan(&id, &org... | [
"func",
"(",
"c",
"*",
"CasIdx",
")",
"load",
"(",
"defs",
"[",
"]",
"schema",
".",
"MetricDefinition",
",",
"iter",
"cqlIterator",
",",
"now",
"time",
".",
"Time",
")",
"[",
"]",
"schema",
".",
"MetricDefinition",
"{",
"defsByNames",
":=",
"make",
"("... | // load appends MetricDefinitions from the iterator to defs and returns the modified defs, honoring pruning settings relative to now | [
"load",
"appends",
"MetricDefinitions",
"from",
"the",
"iterator",
"to",
"defs",
"and",
"returns",
"the",
"modified",
"defs",
"honoring",
"pruning",
"settings",
"relative",
"to",
"now"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/cassandra/cassandra.go#L390-L445 | train |
grafana/metrictank | idx/cassandra/cassandra.go | ArchiveDefs | func (c *CasIdx) ArchiveDefs(defs []schema.MetricDefinition) (int, error) {
defChan := make(chan *schema.MetricDefinition, c.cfg.numConns)
g, ctx := errgroup.WithContext(context.Background())
// keep track of how many defs were successfully archived.
success := make([]int, c.cfg.numConns)
for i := 0; i < c.cfg.n... | go | func (c *CasIdx) ArchiveDefs(defs []schema.MetricDefinition) (int, error) {
defChan := make(chan *schema.MetricDefinition, c.cfg.numConns)
g, ctx := errgroup.WithContext(context.Background())
// keep track of how many defs were successfully archived.
success := make([]int, c.cfg.numConns)
for i := 0; i < c.cfg.n... | [
"func",
"(",
"c",
"*",
"CasIdx",
")",
"ArchiveDefs",
"(",
"defs",
"[",
"]",
"schema",
".",
"MetricDefinition",
")",
"(",
"int",
",",
"error",
")",
"{",
"defChan",
":=",
"make",
"(",
"chan",
"*",
"schema",
".",
"MetricDefinition",
",",
"c",
".",
"cfg"... | // ArchiveDefs writes each of the provided defs to the archive table and
// then deletes the defs from the metric_idx table. | [
"ArchiveDefs",
"writes",
"each",
"of",
"the",
"provided",
"defs",
"to",
"the",
"archive",
"table",
"and",
"then",
"deletes",
"the",
"defs",
"from",
"the",
"metric_idx",
"table",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/cassandra/cassandra.go#L449-L507 | train |
grafana/metrictank | mdata/notifierKafka/notifierKafka.go | flush | func (c *NotifierKafka) flush() {
if len(c.buf) == 0 {
return
}
// In order to correctly route the saveMessages to the correct partition,
// we can't send them in batches anymore.
payload := make([]*sarama.ProducerMessage, 0, len(c.buf))
var pMsg mdata.PersistMessageBatch
for i, msg := range c.buf {
amkey, ... | go | func (c *NotifierKafka) flush() {
if len(c.buf) == 0 {
return
}
// In order to correctly route the saveMessages to the correct partition,
// we can't send them in batches anymore.
payload := make([]*sarama.ProducerMessage, 0, len(c.buf))
var pMsg mdata.PersistMessageBatch
for i, msg := range c.buf {
amkey, ... | [
"func",
"(",
"c",
"*",
"NotifierKafka",
")",
"flush",
"(",
")",
"{",
"if",
"len",
"(",
"c",
".",
"buf",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"// In order to correctly route the saveMessages to the correct partition,",
"// we can't send them in batches a... | // flush makes sure the batch gets sent, asynchronously. | [
"flush",
"makes",
"sure",
"the",
"batch",
"gets",
"sent",
"asynchronously",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/notifierKafka/notifierKafka.go#L201-L259 | train |
grafana/metrictank | api/cluster.go | indexFind | func (s *Server) indexFind(ctx *middleware.Context, req models.IndexFind) {
resp := models.NewIndexFindResp()
// query nodes don't own any data
if s.MetricIndex == nil {
response.Write(ctx, response.NewMsgp(200, resp))
return
}
for _, pattern := range req.Patterns {
nodes, err := s.MetricIndex.Find(req.Org... | go | func (s *Server) indexFind(ctx *middleware.Context, req models.IndexFind) {
resp := models.NewIndexFindResp()
// query nodes don't own any data
if s.MetricIndex == nil {
response.Write(ctx, response.NewMsgp(200, resp))
return
}
for _, pattern := range req.Patterns {
nodes, err := s.MetricIndex.Find(req.Org... | [
"func",
"(",
"s",
"*",
"Server",
")",
"indexFind",
"(",
"ctx",
"*",
"middleware",
".",
"Context",
",",
"req",
"models",
".",
"IndexFind",
")",
"{",
"resp",
":=",
"models",
".",
"NewIndexFindResp",
"(",
")",
"\n\n",
"// query nodes don't own any data",
"if",
... | // IndexFind returns a sequence of msgp encoded idx.Node's | [
"IndexFind",
"returns",
"a",
"sequence",
"of",
"msgp",
"encoded",
"idx",
".",
"Node",
"s"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/cluster.go#L114-L132 | train |
grafana/metrictank | api/cluster.go | indexGet | func (s *Server) indexGet(ctx *middleware.Context, req models.IndexGet) {
// query nodes don't own any data.
if s.MetricIndex == nil {
response.Write(ctx, response.NewMsgp(404, nil))
return
}
def, ok := s.MetricIndex.Get(req.MKey)
if !ok {
response.Write(ctx, response.NewError(http.StatusNotFound, "Not Fou... | go | func (s *Server) indexGet(ctx *middleware.Context, req models.IndexGet) {
// query nodes don't own any data.
if s.MetricIndex == nil {
response.Write(ctx, response.NewMsgp(404, nil))
return
}
def, ok := s.MetricIndex.Get(req.MKey)
if !ok {
response.Write(ctx, response.NewError(http.StatusNotFound, "Not Fou... | [
"func",
"(",
"s",
"*",
"Server",
")",
"indexGet",
"(",
"ctx",
"*",
"middleware",
".",
"Context",
",",
"req",
"models",
".",
"IndexGet",
")",
"{",
"// query nodes don't own any data.",
"if",
"s",
".",
"MetricIndex",
"==",
"nil",
"{",
"response",
".",
"Write... | // IndexGet returns a msgp encoded schema.MetricDefinition | [
"IndexGet",
"returns",
"a",
"msgp",
"encoded",
"schema",
".",
"MetricDefinition"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/cluster.go#L236-L251 | train |
grafana/metrictank | api/cluster.go | indexList | func (s *Server) indexList(ctx *middleware.Context, req models.IndexList) {
// query nodes don't own any data.
if s.MetricIndex == nil {
response.Write(ctx, response.NewMsgpArray(200, nil))
return
}
defs := s.MetricIndex.List(req.OrgId)
resp := make([]msgp.Marshaler, len(defs))
for i := range defs {
d := ... | go | func (s *Server) indexList(ctx *middleware.Context, req models.IndexList) {
// query nodes don't own any data.
if s.MetricIndex == nil {
response.Write(ctx, response.NewMsgpArray(200, nil))
return
}
defs := s.MetricIndex.List(req.OrgId)
resp := make([]msgp.Marshaler, len(defs))
for i := range defs {
d := ... | [
"func",
"(",
"s",
"*",
"Server",
")",
"indexList",
"(",
"ctx",
"*",
"middleware",
".",
"Context",
",",
"req",
"models",
".",
"IndexList",
")",
"{",
"// query nodes don't own any data.",
"if",
"s",
".",
"MetricIndex",
"==",
"nil",
"{",
"response",
".",
"Wri... | // IndexList returns msgp encoded schema.MetricDefinition's | [
"IndexList",
"returns",
"msgp",
"encoded",
"schema",
".",
"MetricDefinition",
"s"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/cluster.go#L254-L269 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.