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
golang/tour
tour.go
findPlayCode
func findPlayCode(e present.Elem) []*present.Code { var r []*present.Code switch v := e.(type) { case present.Code: if v.Play { r = append(r, &v) } case present.Section: for _, s := range v.Elem { r = append(r, findPlayCode(s)...) } } return r }
go
func findPlayCode(e present.Elem) []*present.Code { var r []*present.Code switch v := e.(type) { case present.Code: if v.Play { r = append(r, &v) } case present.Section: for _, s := range v.Elem { r = append(r, findPlayCode(s)...) } } return r }
[ "func", "findPlayCode", "(", "e", "present", ".", "Elem", ")", "[", "]", "*", "present", ".", "Code", "{", "var", "r", "[", "]", "*", "present", ".", "Code", "\n", "switch", "v", ":=", "e", ".", "(", "type", ")", "{", "case", "present", ".", "C...
// findPlayCode returns a slide with all the Code elements in the given // Elem with Play set to true.
[ "findPlayCode", "returns", "a", "slide", "with", "all", "the", "Code", "elements", "in", "the", "given", "Elem", "with", "Play", "set", "to", "true", "." ]
db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77
https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/tour.go#L165-L178
train
golang/tour
tour.go
writeLesson
func writeLesson(name string, w io.Writer) error { if uiContent == nil { panic("writeLesson called before successful initTour") } if len(name) == 0 { return writeAllLessons(w) } l, ok := lessons[name] if !ok { return lessonNotFound } _, err := w.Write(l) return err }
go
func writeLesson(name string, w io.Writer) error { if uiContent == nil { panic("writeLesson called before successful initTour") } if len(name) == 0 { return writeAllLessons(w) } l, ok := lessons[name] if !ok { return lessonNotFound } _, err := w.Write(l) return err }
[ "func", "writeLesson", "(", "name", "string", ",", "w", "io", ".", "Writer", ")", "error", "{", "if", "uiContent", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "name", ")", "==", "0", "{", "return", "writeAl...
// writeLesson writes the tour content to the provided Writer.
[ "writeLesson", "writes", "the", "tour", "content", "to", "the", "provided", "Writer", "." ]
db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77
https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/tour.go#L181-L194
train
golang/tour
tour.go
renderUI
func renderUI(w io.Writer) error { if uiContent == nil { panic("renderUI called before successful initTour") } _, err := w.Write(uiContent) return err }
go
func renderUI(w io.Writer) error { if uiContent == nil { panic("renderUI called before successful initTour") } _, err := w.Write(uiContent) return err }
[ "func", "renderUI", "(", "w", "io", ".", "Writer", ")", "error", "{", "if", "uiContent", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "_", ",", "err", ":=", "w", ".", "Write", "(", "uiContent", ")", "\n", "return", "err", "...
// renderUI writes the tour UI to the provided Writer.
[ "renderUI", "writes", "the", "tour", "UI", "to", "the", "provided", "Writer", "." ]
db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77
https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/tour.go#L217-L223
train
golang/tour
tour.go
nocode
func nocode(s present.Section) bool { for _, e := range s.Elem { if c, ok := e.(present.Code); ok && c.Play { return false } } return true }
go
func nocode(s present.Section) bool { for _, e := range s.Elem { if c, ok := e.(present.Code); ok && c.Play { return false } } return true }
[ "func", "nocode", "(", "s", "present", ".", "Section", ")", "bool", "{", "for", "_", ",", "e", ":=", "range", "s", ".", "Elem", "{", "if", "c", ",", "ok", ":=", "e", ".", "(", "present", ".", "Code", ")", ";", "ok", "&&", "c", ".", "Play", ...
// nocode returns true if the provided Section contains // no Code elements with Play enabled.
[ "nocode", "returns", "true", "if", "the", "provided", "Section", "contains", "no", "Code", "elements", "with", "Play", "enabled", "." ]
db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77
https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/tour.go#L227-L234
train
kahing/goofys
internal/goofys.go
GetFullName
func (fs *Goofys) GetFullName(id fuseops.InodeID) *string { fs.mu.Lock() inode := fs.inodes[id] fs.mu.Unlock() if inode == nil { return nil } return inode.FullName() }
go
func (fs *Goofys) GetFullName(id fuseops.InodeID) *string { fs.mu.Lock() inode := fs.inodes[id] fs.mu.Unlock() if inode == nil { return nil } return inode.FullName() }
[ "func", "(", "fs", "*", "Goofys", ")", "GetFullName", "(", "id", "fuseops", ".", "InodeID", ")", "*", "string", "{", "fs", ".", "mu", ".", "Lock", "(", ")", "\n", "inode", ":=", "fs", ".", "inodes", "[", "id", "]", "\n", "fs", ".", "mu", ".", ...
// GetFullName returns full name of the given inode
[ "GetFullName", "returns", "full", "name", "of", "the", "given", "inode" ]
224a69530a8fefa8f07e51582b928739127134f2
https://github.com/kahing/goofys/blob/224a69530a8fefa8f07e51582b928739127134f2/internal/goofys.go#L1174-L1183
train
kahing/goofys
internal/flags.go
filterCategory
func filterCategory(flags []cli.Flag, category string) (ret []cli.Flag) { for _, f := range flags { if flagCategories[f.GetName()] == category { ret = append(ret, f) } } return }
go
func filterCategory(flags []cli.Flag, category string) (ret []cli.Flag) { for _, f := range flags { if flagCategories[f.GetName()] == category { ret = append(ret, f) } } return }
[ "func", "filterCategory", "(", "flags", "[", "]", "cli", ".", "Flag", ",", "category", "string", ")", "(", "ret", "[", "]", "cli", ".", "Flag", ")", "{", "for", "_", ",", "f", ":=", "range", "flags", "{", "if", "flagCategories", "[", "f", ".", "G...
// Set up custom help text for goofys; in particular the usage section.
[ "Set", "up", "custom", "help", "text", "for", "goofys", ";", "in", "particular", "the", "usage", "section", "." ]
224a69530a8fefa8f07e51582b928739127134f2
https://github.com/kahing/goofys/blob/224a69530a8fefa8f07e51582b928739127134f2/internal/flags.go#L35-L42
train
kahing/goofys
main.go
mount
func mount( ctx context.Context, bucketName string, flags *FlagStorage) (fs *Goofys, mfs *fuse.MountedFileSystem, err error) { // XXX really silly copy here! in goofys.Mount we will copy it // back to FlagStorage. But I don't see a easier way to expose // Config in the api package var config goofys.Config copi...
go
func mount( ctx context.Context, bucketName string, flags *FlagStorage) (fs *Goofys, mfs *fuse.MountedFileSystem, err error) { // XXX really silly copy here! in goofys.Mount we will copy it // back to FlagStorage. But I don't see a easier way to expose // Config in the api package var config goofys.Config copi...
[ "func", "mount", "(", "ctx", "context", ".", "Context", ",", "bucketName", "string", ",", "flags", "*", "FlagStorage", ")", "(", "fs", "*", "Goofys", ",", "mfs", "*", "fuse", ".", "MountedFileSystem", ",", "err", "error", ")", "{", "// XXX really silly cop...
// Mount the file system based on the supplied arguments, returning a // fuse.MountedFileSystem that can be joined to wait for unmounting.
[ "Mount", "the", "file", "system", "based", "on", "the", "supplied", "arguments", "returning", "a", "fuse", ".", "MountedFileSystem", "that", "can", "be", "joined", "to", "wait", "for", "unmounting", "." ]
224a69530a8fefa8f07e51582b928739127134f2
https://github.com/kahing/goofys/blob/224a69530a8fefa8f07e51582b928739127134f2/main.go#L106-L118
train
kahing/goofys
internal/perms.go
MyUserAndGroup
func MyUserAndGroup() (uid int, gid int) { // Ask for the current user. user, err := user.Current() if err != nil { panic(err) } // Parse UID. uid64, err := strconv.ParseInt(user.Uid, 10, 32) if err != nil { log.Fatalf("Parsing UID (%s): %v", user.Uid, err) return } // Parse GID. gid64, err := strconv...
go
func MyUserAndGroup() (uid int, gid int) { // Ask for the current user. user, err := user.Current() if err != nil { panic(err) } // Parse UID. uid64, err := strconv.ParseInt(user.Uid, 10, 32) if err != nil { log.Fatalf("Parsing UID (%s): %v", user.Uid, err) return } // Parse GID. gid64, err := strconv...
[ "func", "MyUserAndGroup", "(", ")", "(", "uid", "int", ",", "gid", "int", ")", "{", "// Ask for the current user.", "user", ",", "err", ":=", "user", ".", "Current", "(", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", ...
// MyUserAndGroup returns the UID and GID of this process.
[ "MyUserAndGroup", "returns", "the", "UID", "and", "GID", "of", "this", "process", "." ]
224a69530a8fefa8f07e51582b928739127134f2
https://github.com/kahing/goofys/blob/224a69530a8fefa8f07e51582b928739127134f2/internal/perms.go#L25-L50
train
kahing/goofys
internal/buffer_pool.go
Seek
func (mb *MBuf) Seek(offset int64, whence int) (int64, error) { switch whence { case 0: // relative to beginning if offset == 0 { mb.rbuf = 0 mb.rp = 0 return 0, nil } case 1: // relative to current position if offset == 0 { for i := 0; i < mb.rbuf; i++ { offset += int64(len(mb.buffers[i])) ...
go
func (mb *MBuf) Seek(offset int64, whence int) (int64, error) { switch whence { case 0: // relative to beginning if offset == 0 { mb.rbuf = 0 mb.rp = 0 return 0, nil } case 1: // relative to current position if offset == 0 { for i := 0; i < mb.rbuf; i++ { offset += int64(len(mb.buffers[i])) ...
[ "func", "(", "mb", "*", "MBuf", ")", "Seek", "(", "offset", "int64", ",", "whence", "int", ")", "(", "int64", ",", "error", ")", "{", "switch", "whence", "{", "case", "0", ":", "// relative to beginning", "if", "offset", "==", "0", "{", "mb", ".", ...
// seek only seeks the reader
[ "seek", "only", "seeks", "the", "reader" ]
224a69530a8fefa8f07e51582b928739127134f2
https://github.com/kahing/goofys/blob/224a69530a8fefa8f07e51582b928739127134f2/internal/buffer_pool.go#L210-L242
train
cloudflare/cloudflare-go
duration.go
UnmarshalJSON
func (d *Duration) UnmarshalJSON(buf []byte) error { var str string err := json.Unmarshal(buf, &str) if err != nil { return err } dur, err := time.ParseDuration(str) if err != nil { return err } d.Duration = dur return nil }
go
func (d *Duration) UnmarshalJSON(buf []byte) error { var str string err := json.Unmarshal(buf, &str) if err != nil { return err } dur, err := time.ParseDuration(str) if err != nil { return err } d.Duration = dur return nil }
[ "func", "(", "d", "*", "Duration", ")", "UnmarshalJSON", "(", "buf", "[", "]", "byte", ")", "error", "{", "var", "str", "string", "\n\n", "err", ":=", "json", ".", "Unmarshal", "(", "buf", ",", "&", "str", ")", "\n", "if", "err", "!=", "nil", "{"...
// UnmarshalJSON decodes a Duration from a JSON string parsed using time.ParseDuration.
[ "UnmarshalJSON", "decodes", "a", "Duration", "from", "a", "JSON", "string", "parsed", "using", "time", ".", "ParseDuration", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/duration.go#L20-L35
train
cloudflare/cloudflare-go
cmd/flarectl/misc.go
writeTable
func writeTable(data [][]string, cols ...string) { table := tablewriter.NewWriter(os.Stdout) table.SetHeader(cols) table.SetBorder(false) table.AppendBulk(data) table.Render() }
go
func writeTable(data [][]string, cols ...string) { table := tablewriter.NewWriter(os.Stdout) table.SetHeader(cols) table.SetBorder(false) table.AppendBulk(data) table.Render() }
[ "func", "writeTable", "(", "data", "[", "]", "[", "]", "string", ",", "cols", "...", "string", ")", "{", "table", ":=", "tablewriter", ".", "NewWriter", "(", "os", ".", "Stdout", ")", "\n", "table", ".", "SetHeader", "(", "cols", ")", "\n", "table", ...
// writeTable outputs tabular data to stdout.
[ "writeTable", "outputs", "tabular", "data", "to", "stdout", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cmd/flarectl/misc.go#L16-L23
train
cloudflare/cloudflare-go
cmd/flarectl/misc.go
checkFlags
func checkFlags(c *cli.Context, flags ...string) error { for _, flag := range flags { if c.String(flag) == "" { cli.ShowSubcommandHelp(c) err := errors.Errorf("error: the required flag %q was empty or not provided", flag) fmt.Fprintln(os.Stderr, err) return err } } return nil }
go
func checkFlags(c *cli.Context, flags ...string) error { for _, flag := range flags { if c.String(flag) == "" { cli.ShowSubcommandHelp(c) err := errors.Errorf("error: the required flag %q was empty or not provided", flag) fmt.Fprintln(os.Stderr, err) return err } } return nil }
[ "func", "checkFlags", "(", "c", "*", "cli", ".", "Context", ",", "flags", "...", "string", ")", "error", "{", "for", "_", ",", "flag", ":=", "range", "flags", "{", "if", "c", ".", "String", "(", "flag", ")", "==", "\"", "\"", "{", "cli", ".", "...
// Utility function to check if CLI flags were given.
[ "Utility", "function", "to", "check", "if", "CLI", "flags", "were", "given", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cmd/flarectl/misc.go#L45-L56
train
cloudflare/cloudflare-go
cmd/flarectl/misc.go
_getIps
func _getIps(ipType string, showMsgType bool) { ips, _ := cloudflare.IPs() switch ipType { case "ipv4": if showMsgType != true { fmt.Println("IPv4 ranges:") } for _, r := range ips.IPv4CIDRs { fmt.Println(" ", r) } case "ipv6": if showMsgType != true { fmt.Println("IPv6 ranges:") } for _, r ...
go
func _getIps(ipType string, showMsgType bool) { ips, _ := cloudflare.IPs() switch ipType { case "ipv4": if showMsgType != true { fmt.Println("IPv4 ranges:") } for _, r := range ips.IPv4CIDRs { fmt.Println(" ", r) } case "ipv6": if showMsgType != true { fmt.Println("IPv6 ranges:") } for _, r ...
[ "func", "_getIps", "(", "ipType", "string", ",", "showMsgType", "bool", ")", "{", "ips", ",", "_", ":=", "cloudflare", ".", "IPs", "(", ")", "\n\n", "switch", "ipType", "{", "case", "\"", "\"", ":", "if", "showMsgType", "!=", "true", "{", "fmt", ".",...
// // gets type of IPs to retrieve and returns results //
[ "gets", "type", "of", "IPs", "to", "retrieve", "and", "returns", "results" ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cmd/flarectl/misc.go#L71-L90
train
cloudflare/cloudflare-go
auditlogs.go
String
func (a AuditLogFilter) String() string { params := "?" if a.ID != "" { params += "&id=" + a.ID } if a.ActorIP != "" { params += "&actor.ip=" + a.ActorIP } if a.ActorEmail != "" { params += "&actor.email=" + a.ActorEmail } if a.ZoneName != "" { params += "&zone.name=" + a.ZoneName } if a.Direction != ...
go
func (a AuditLogFilter) String() string { params := "?" if a.ID != "" { params += "&id=" + a.ID } if a.ActorIP != "" { params += "&actor.ip=" + a.ActorIP } if a.ActorEmail != "" { params += "&actor.email=" + a.ActorEmail } if a.ZoneName != "" { params += "&zone.name=" + a.ZoneName } if a.Direction != ...
[ "func", "(", "a", "AuditLogFilter", ")", "String", "(", ")", "string", "{", "params", ":=", "\"", "\"", "\n", "if", "a", ".", "ID", "!=", "\"", "\"", "{", "params", "+=", "\"", "\"", "+", "a", ".", "ID", "\n", "}", "\n", "if", "a", ".", "Acto...
// String turns an audit log filter in to an HTTP Query Param // list. It will not inclue empty members of the struct in the // query parameters.
[ "String", "turns", "an", "audit", "log", "filter", "in", "to", "an", "HTTP", "Query", "Param", "list", ".", "It", "will", "not", "inclue", "empty", "members", "of", "the", "struct", "in", "the", "query", "parameters", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/auditlogs.go#L71-L101
train
cloudflare/cloudflare-go
auditlogs.go
unmarshalReturn
func unmarshalReturn(res []byte) (AuditLogResponse, error) { var auditResponse AuditLogResponse err := json.Unmarshal(res, &auditResponse) if err != nil { return auditResponse, err } return auditResponse, nil }
go
func unmarshalReturn(res []byte) (AuditLogResponse, error) { var auditResponse AuditLogResponse err := json.Unmarshal(res, &auditResponse) if err != nil { return auditResponse, err } return auditResponse, nil }
[ "func", "unmarshalReturn", "(", "res", "[", "]", "byte", ")", "(", "AuditLogResponse", ",", "error", ")", "{", "var", "auditResponse", "AuditLogResponse", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "res", ",", "&", "auditResponse", ")", "\n", "if", ...
// unmarshalReturn will unmarshal bytes and return an auditlogresponse
[ "unmarshalReturn", "will", "unmarshal", "bytes", "and", "return", "an", "auditlogresponse" ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/auditlogs.go#L123-L130
train
cloudflare/cloudflare-go
zone.go
ListZonesContext
func (api *API) ListZonesContext(ctx context.Context, opts ...ReqOption) (r ZonesResponse, err error) { var res []byte opt := reqOption{ params: url.Values{}, } for _, of := range opts { of(&opt) } res, err = api.makeRequestContext(ctx, "GET", "/zones?"+opt.params.Encode(), nil) if err != nil { return Zon...
go
func (api *API) ListZonesContext(ctx context.Context, opts ...ReqOption) (r ZonesResponse, err error) { var res []byte opt := reqOption{ params: url.Values{}, } for _, of := range opts { of(&opt) } res, err = api.makeRequestContext(ctx, "GET", "/zones?"+opt.params.Encode(), nil) if err != nil { return Zon...
[ "func", "(", "api", "*", "API", ")", "ListZonesContext", "(", "ctx", "context", ".", "Context", ",", "opts", "...", "ReqOption", ")", "(", "r", "ZonesResponse", ",", "err", "error", ")", "{", "var", "res", "[", "]", "byte", "\n", "opt", ":=", "reqOpt...
// ListZonesContext lists zones on an account. Optionally takes a list of ReqOptions.
[ "ListZonesContext", "lists", "zones", "on", "an", "account", ".", "Optionally", "takes", "a", "list", "of", "ReqOptions", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/zone.go#L401-L420
train
cloudflare/cloudflare-go
zone.go
ZoneSetPaused
func (api *API) ZoneSetPaused(zoneID string, paused bool) (Zone, error) { zoneopts := ZoneOptions{Paused: &paused} zone, err := api.EditZone(zoneID, zoneopts) if err != nil { return Zone{}, err } return zone, nil }
go
func (api *API) ZoneSetPaused(zoneID string, paused bool) (Zone, error) { zoneopts := ZoneOptions{Paused: &paused} zone, err := api.EditZone(zoneID, zoneopts) if err != nil { return Zone{}, err } return zone, nil }
[ "func", "(", "api", "*", "API", ")", "ZoneSetPaused", "(", "zoneID", "string", ",", "paused", "bool", ")", "(", "Zone", ",", "error", ")", "{", "zoneopts", ":=", "ZoneOptions", "{", "Paused", ":", "&", "paused", "}", "\n", "zone", ",", "err", ":=", ...
// ZoneSetPaused pauses Cloudflare service for the entire zone, sending all // traffic direct to the origin.
[ "ZoneSetPaused", "pauses", "Cloudflare", "service", "for", "the", "entire", "zone", "sending", "all", "traffic", "direct", "to", "the", "origin", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/zone.go#L447-L455
train
cloudflare/cloudflare-go
zone.go
ZoneSetVanityNS
func (api *API) ZoneSetVanityNS(zoneID string, ns []string) (Zone, error) { zoneopts := ZoneOptions{VanityNS: ns} zone, err := api.EditZone(zoneID, zoneopts) if err != nil { return Zone{}, err } return zone, nil }
go
func (api *API) ZoneSetVanityNS(zoneID string, ns []string) (Zone, error) { zoneopts := ZoneOptions{VanityNS: ns} zone, err := api.EditZone(zoneID, zoneopts) if err != nil { return Zone{}, err } return zone, nil }
[ "func", "(", "api", "*", "API", ")", "ZoneSetVanityNS", "(", "zoneID", "string", ",", "ns", "[", "]", "string", ")", "(", "Zone", ",", "error", ")", "{", "zoneopts", ":=", "ZoneOptions", "{", "VanityNS", ":", "ns", "}", "\n", "zone", ",", "err", ":...
// ZoneSetVanityNS sets custom nameservers for the zone. // These names must be within the same zone.
[ "ZoneSetVanityNS", "sets", "custom", "nameservers", "for", "the", "zone", ".", "These", "names", "must", "be", "within", "the", "same", "zone", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/zone.go#L459-L467
train
cloudflare/cloudflare-go
zone.go
ZoneSetPlan
func (api *API) ZoneSetPlan(zoneID string, plan ZonePlan) (Zone, error) { zoneopts := ZoneOptions{Plan: &plan} zone, err := api.EditZone(zoneID, zoneopts) if err != nil { return Zone{}, err } return zone, nil }
go
func (api *API) ZoneSetPlan(zoneID string, plan ZonePlan) (Zone, error) { zoneopts := ZoneOptions{Plan: &plan} zone, err := api.EditZone(zoneID, zoneopts) if err != nil { return Zone{}, err } return zone, nil }
[ "func", "(", "api", "*", "API", ")", "ZoneSetPlan", "(", "zoneID", "string", ",", "plan", "ZonePlan", ")", "(", "Zone", ",", "error", ")", "{", "zoneopts", ":=", "ZoneOptions", "{", "Plan", ":", "&", "plan", "}", "\n", "zone", ",", "err", ":=", "ap...
// ZoneSetPlan changes the zone plan.
[ "ZoneSetPlan", "changes", "the", "zone", "plan", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/zone.go#L470-L478
train
cloudflare/cloudflare-go
options.go
UsingRateLimit
func UsingRateLimit(rps float64) Option { return func(api *API) error { // because ratelimiter doesnt do any windowing // setting burst makes it difficult to enforce a fixed rate // so setting it equal to 1 this effectively disables bursting // this doesn't check for sensible values, ultimately the api will en...
go
func UsingRateLimit(rps float64) Option { return func(api *API) error { // because ratelimiter doesnt do any windowing // setting burst makes it difficult to enforce a fixed rate // so setting it equal to 1 this effectively disables bursting // this doesn't check for sensible values, ultimately the api will en...
[ "func", "UsingRateLimit", "(", "rps", "float64", ")", "Option", "{", "return", "func", "(", "api", "*", "API", ")", "error", "{", "// because ratelimiter doesnt do any windowing", "// setting burst makes it difficult to enforce a fixed rate", "// so setting it equal to 1 this e...
// UsingRateLimit applies a non-default rate limit to client API requests // If not specified the default of 4rps will be applied
[ "UsingRateLimit", "applies", "a", "non", "-", "default", "rate", "limit", "to", "client", "API", "requests", "If", "not", "specified", "the", "default", "of", "4rps", "will", "be", "applied" ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/options.go#L42-L51
train
cloudflare/cloudflare-go
options.go
UsingLogger
func UsingLogger(logger Logger) Option { return func(api *API) error { api.logger = logger return nil } }
go
func UsingLogger(logger Logger) Option { return func(api *API) error { api.logger = logger return nil } }
[ "func", "UsingLogger", "(", "logger", "Logger", ")", "Option", "{", "return", "func", "(", "api", "*", "API", ")", "error", "{", "api", ".", "logger", "=", "logger", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// UsingLogger can be set if you want to get log output from this API instance // By default no log output is emitted
[ "UsingLogger", "can", "be", "set", "if", "you", "want", "to", "get", "log", "output", "from", "this", "API", "instance", "By", "default", "no", "log", "output", "is", "emitted" ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/options.go#L69-L74
train
cloudflare/cloudflare-go
virtualdns.go
VirtualDNSUserAnalytics
func (api *API) VirtualDNSUserAnalytics(virtualDNSID string, o VirtualDNSUserAnalyticsOptions) (VirtualDNSAnalytics, error) { uri := "/user/virtual_dns/" + virtualDNSID + "/dns_analytics/report?" + o.encode() res, err := api.makeRequest("GET", uri, nil) if err != nil { return VirtualDNSAnalytics{}, errors.Wrap(err...
go
func (api *API) VirtualDNSUserAnalytics(virtualDNSID string, o VirtualDNSUserAnalyticsOptions) (VirtualDNSAnalytics, error) { uri := "/user/virtual_dns/" + virtualDNSID + "/dns_analytics/report?" + o.encode() res, err := api.makeRequest("GET", uri, nil) if err != nil { return VirtualDNSAnalytics{}, errors.Wrap(err...
[ "func", "(", "api", "*", "API", ")", "VirtualDNSUserAnalytics", "(", "virtualDNSID", "string", ",", "o", "VirtualDNSUserAnalyticsOptions", ")", "(", "VirtualDNSAnalytics", ",", "error", ")", "{", "uri", ":=", "\"", "\"", "+", "virtualDNSID", "+", "\"", "\"", ...
// VirtualDNSUserAnalytics retrieves analytics report for a specified dimension and time range
[ "VirtualDNSUserAnalytics", "retrieves", "analytics", "report", "for", "a", "specified", "dimension", "and", "time", "range" ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/virtualdns.go#L178-L192
train
cloudflare/cloudflare-go
custom_hostname.go
CustomHostnameIDByName
func (api *API) CustomHostnameIDByName(zoneID string, hostname string) (string, error) { customHostnames, _, err := api.CustomHostnames(zoneID, 1, CustomHostname{Hostname: hostname}) if err != nil { return "", errors.Wrap(err, "CustomHostnames command failed") } for _, ch := range customHostnames { if ch.Hostna...
go
func (api *API) CustomHostnameIDByName(zoneID string, hostname string) (string, error) { customHostnames, _, err := api.CustomHostnames(zoneID, 1, CustomHostname{Hostname: hostname}) if err != nil { return "", errors.Wrap(err, "CustomHostnames command failed") } for _, ch := range customHostnames { if ch.Hostna...
[ "func", "(", "api", "*", "API", ")", "CustomHostnameIDByName", "(", "zoneID", "string", ",", "hostname", "string", ")", "(", "string", ",", "error", ")", "{", "customHostnames", ",", "_", ",", "err", ":=", "api", ".", "CustomHostnames", "(", "zoneID", ",...
// CustomHostnameIDByName retrieves the ID for the given hostname in the given zone.
[ "CustomHostnameIDByName", "retrieves", "the", "ID", "for", "the", "given", "hostname", "in", "the", "given", "zone", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/custom_hostname.go#L149-L160
train
cloudflare/cloudflare-go
cloudflare.go
newClient
func newClient(opts ...Option) (*API, error) { silentLogger := log.New(ioutil.Discard, "", log.LstdFlags) api := &API{ BaseURL: apiURL, headers: make(http.Header), rateLimiter: rate.NewLimiter(rate.Limit(4), 1), // 4rps equates to default api limit (1200 req/5 min) retryPolicy: RetryPolicy{ MaxRet...
go
func newClient(opts ...Option) (*API, error) { silentLogger := log.New(ioutil.Discard, "", log.LstdFlags) api := &API{ BaseURL: apiURL, headers: make(http.Header), rateLimiter: rate.NewLimiter(rate.Limit(4), 1), // 4rps equates to default api limit (1200 req/5 min) retryPolicy: RetryPolicy{ MaxRet...
[ "func", "newClient", "(", "opts", "...", "Option", ")", "(", "*", "API", ",", "error", ")", "{", "silentLogger", ":=", "log", ".", "New", "(", "ioutil", ".", "Discard", ",", "\"", "\"", ",", "log", ".", "LstdFlags", ")", "\n\n", "api", ":=", "&", ...
// newClient provides shared logic for New and NewWithUserServiceKey
[ "newClient", "provides", "shared", "logic", "for", "New", "and", "NewWithUserServiceKey" ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cloudflare.go#L48-L75
train
cloudflare/cloudflare-go
cloudflare.go
New
func New(key, email string, opts ...Option) (*API, error) { if key == "" || email == "" { return nil, errors.New(errEmptyCredentials) } api, err := newClient(opts...) if err != nil { return nil, err } api.APIKey = key api.APIEmail = email api.authType = AuthKeyEmail return api, nil }
go
func New(key, email string, opts ...Option) (*API, error) { if key == "" || email == "" { return nil, errors.New(errEmptyCredentials) } api, err := newClient(opts...) if err != nil { return nil, err } api.APIKey = key api.APIEmail = email api.authType = AuthKeyEmail return api, nil }
[ "func", "New", "(", "key", ",", "email", "string", ",", "opts", "...", "Option", ")", "(", "*", "API", ",", "error", ")", "{", "if", "key", "==", "\"", "\"", "||", "email", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(",...
// New creates a new Cloudflare v4 API client.
[ "New", "creates", "a", "new", "Cloudflare", "v4", "API", "client", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cloudflare.go#L78-L93
train
cloudflare/cloudflare-go
cloudflare.go
NewWithUserServiceKey
func NewWithUserServiceKey(key string, opts ...Option) (*API, error) { if key == "" { return nil, errors.New(errEmptyCredentials) } api, err := newClient(opts...) if err != nil { return nil, err } api.APIUserServiceKey = key api.authType = AuthUserService return api, nil }
go
func NewWithUserServiceKey(key string, opts ...Option) (*API, error) { if key == "" { return nil, errors.New(errEmptyCredentials) } api, err := newClient(opts...) if err != nil { return nil, err } api.APIUserServiceKey = key api.authType = AuthUserService return api, nil }
[ "func", "NewWithUserServiceKey", "(", "key", "string", ",", "opts", "...", "Option", ")", "(", "*", "API", ",", "error", ")", "{", "if", "key", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "errEmptyCredentials", ")", "\n", ...
// NewWithUserServiceKey creates a new Cloudflare v4 API client using service key authentication.
[ "NewWithUserServiceKey", "creates", "a", "new", "Cloudflare", "v4", "API", "client", "using", "service", "key", "authentication", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cloudflare.go#L96-L110
train
cloudflare/cloudflare-go
cloudflare.go
ZoneIDByName
func (api *API) ZoneIDByName(zoneName string) (string, error) { res, err := api.ListZonesContext(context.TODO(), WithZoneFilter(zoneName)) if err != nil { return "", errors.Wrap(err, "ListZonesContext command failed") } if len(res.Result) > 1 && api.OrganizationID == "" { return "", errors.New("ambiguous zone ...
go
func (api *API) ZoneIDByName(zoneName string) (string, error) { res, err := api.ListZonesContext(context.TODO(), WithZoneFilter(zoneName)) if err != nil { return "", errors.Wrap(err, "ListZonesContext command failed") } if len(res.Result) > 1 && api.OrganizationID == "" { return "", errors.New("ambiguous zone ...
[ "func", "(", "api", "*", "API", ")", "ZoneIDByName", "(", "zoneName", "string", ")", "(", "string", ",", "error", ")", "{", "res", ",", "err", ":=", "api", ".", "ListZonesContext", "(", "context", ".", "TODO", "(", ")", ",", "WithZoneFilter", "(", "z...
// ZoneIDByName retrieves a zone's ID from the name.
[ "ZoneIDByName", "retrieves", "a", "zone", "s", "ID", "from", "the", "name", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cloudflare.go#L118-L141
train
cloudflare/cloudflare-go
cloudflare.go
makeRequest
func (api *API) makeRequest(method, uri string, params interface{}) ([]byte, error) { return api.makeRequestWithAuthType(context.TODO(), method, uri, params, api.authType) }
go
func (api *API) makeRequest(method, uri string, params interface{}) ([]byte, error) { return api.makeRequestWithAuthType(context.TODO(), method, uri, params, api.authType) }
[ "func", "(", "api", "*", "API", ")", "makeRequest", "(", "method", ",", "uri", "string", ",", "params", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "api", ".", "makeRequestWithAuthType", "(", "context", ".", "...
// makeRequest makes a HTTP request and returns the body as a byte slice, // closing it before returnng. params will be serialized to JSON.
[ "makeRequest", "makes", "a", "HTTP", "request", "and", "returns", "the", "body", "as", "a", "byte", "slice", "closing", "it", "before", "returnng", ".", "params", "will", "be", "serialized", "to", "JSON", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cloudflare.go#L145-L147
train
cloudflare/cloudflare-go
cloudflare.go
userBaseURL
func (api *API) userBaseURL(accountBase string) string { if api.OrganizationID != "" { return "/accounts/" + api.OrganizationID } return accountBase }
go
func (api *API) userBaseURL(accountBase string) string { if api.OrganizationID != "" { return "/accounts/" + api.OrganizationID } return accountBase }
[ "func", "(", "api", "*", "API", ")", "userBaseURL", "(", "accountBase", "string", ")", "string", "{", "if", "api", ".", "OrganizationID", "!=", "\"", "\"", "{", "return", "\"", "\"", "+", "api", ".", "OrganizationID", "\n", "}", "\n", "return", "accoun...
// Returns the base URL to use for API endpoints that exist for both accounts and organizations. // If an Organization option was used when creating the API instance, returns the org URL. // // accountBase is the base URL for endpoints referring to the current user. It exists as a // parameter because it is not consist...
[ "Returns", "the", "base", "URL", "to", "use", "for", "API", "endpoints", "that", "exist", "for", "both", "accounts", "and", "organizations", ".", "If", "an", "Organization", "option", "was", "used", "when", "creating", "the", "API", "instance", "returns", "t...
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cloudflare.go#L308-L313
train
cloudflare/cloudflare-go
cloudflare.go
Raw
func (api *API) Raw(method, endpoint string, data interface{}) (json.RawMessage, error) { res, err := api.makeRequest(method, endpoint, data) if err != nil { return nil, errors.Wrap(err, errMakeRequestError) } var r RawResponse if err := json.Unmarshal(res, &r); err != nil { return nil, errors.Wrap(err, errUn...
go
func (api *API) Raw(method, endpoint string, data interface{}) (json.RawMessage, error) { res, err := api.makeRequest(method, endpoint, data) if err != nil { return nil, errors.Wrap(err, errMakeRequestError) } var r RawResponse if err := json.Unmarshal(res, &r); err != nil { return nil, errors.Wrap(err, errUn...
[ "func", "(", "api", "*", "API", ")", "Raw", "(", "method", ",", "endpoint", "string", ",", "data", "interface", "{", "}", ")", "(", "json", ".", "RawMessage", ",", "error", ")", "{", "res", ",", "err", ":=", "api", ".", "makeRequest", "(", "method"...
// Raw makes a HTTP request with user provided params and returns the // result as untouched JSON.
[ "Raw", "makes", "a", "HTTP", "request", "with", "user", "provided", "params", "and", "returns", "the", "result", "as", "untouched", "JSON", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cloudflare.go#L355-L366
train
cloudflare/cloudflare-go
cloudflare.go
WithZoneFilter
func WithZoneFilter(zone string) ReqOption { return func(opt *reqOption) { opt.params.Set("name", zone) } }
go
func WithZoneFilter(zone string) ReqOption { return func(opt *reqOption) { opt.params.Set("name", zone) } }
[ "func", "WithZoneFilter", "(", "zone", "string", ")", "ReqOption", "{", "return", "func", "(", "opt", "*", "reqOption", ")", "{", "opt", ".", "params", ".", "Set", "(", "\"", "\"", ",", "zone", ")", "\n", "}", "\n", "}" ]
// WithZoneFilter applies a filter based on zone name.
[ "WithZoneFilter", "applies", "a", "filter", "based", "on", "zone", "name", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cloudflare.go#L396-L400
train
cloudflare/cloudflare-go
cloudflare.go
WithPagination
func WithPagination(opts PaginationOptions) ReqOption { return func(opt *reqOption) { opt.params.Set("page", strconv.Itoa(opts.Page)) opt.params.Set("per_page", strconv.Itoa(opts.PerPage)) } }
go
func WithPagination(opts PaginationOptions) ReqOption { return func(opt *reqOption) { opt.params.Set("page", strconv.Itoa(opts.Page)) opt.params.Set("per_page", strconv.Itoa(opts.PerPage)) } }
[ "func", "WithPagination", "(", "opts", "PaginationOptions", ")", "ReqOption", "{", "return", "func", "(", "opt", "*", "reqOption", ")", "{", "opt", ".", "params", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "opts", ".", "Page", ")", ...
// WithPagination configures the pagination for a response.
[ "WithPagination", "configures", "the", "pagination", "for", "a", "response", "." ]
024278eb1b129df5cf9fdaf301c08b99283e81bc
https://github.com/cloudflare/cloudflare-go/blob/024278eb1b129df5cf9fdaf301c08b99283e81bc/cloudflare.go#L403-L408
train
prometheus/tsdb
record.go
Type
func (d *RecordDecoder) Type(rec []byte) RecordType { if len(rec) < 1 { return RecordInvalid } switch t := RecordType(rec[0]); t { case RecordSeries, RecordSamples, RecordTombstones: return t } return RecordInvalid }
go
func (d *RecordDecoder) Type(rec []byte) RecordType { if len(rec) < 1 { return RecordInvalid } switch t := RecordType(rec[0]); t { case RecordSeries, RecordSamples, RecordTombstones: return t } return RecordInvalid }
[ "func", "(", "d", "*", "RecordDecoder", ")", "Type", "(", "rec", "[", "]", "byte", ")", "RecordType", "{", "if", "len", "(", "rec", ")", "<", "1", "{", "return", "RecordInvalid", "\n", "}", "\n", "switch", "t", ":=", "RecordType", "(", "rec", "[", ...
// Type returns the type of the record. // Return RecordInvalid if no valid record type is found.
[ "Type", "returns", "the", "type", "of", "the", "record", ".", "Return", "RecordInvalid", "if", "no", "valid", "record", "type", "is", "found", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/record.go#L47-L56
train
prometheus/tsdb
record.go
Series
func (d *RecordDecoder) Series(rec []byte, series []RefSeries) ([]RefSeries, error) { dec := encoding.Decbuf{B: rec} if RecordType(dec.Byte()) != RecordSeries { return nil, errors.New("invalid record type") } for len(dec.B) > 0 && dec.Err() == nil { ref := dec.Be64() lset := make(labels.Labels, dec.Uvarint(...
go
func (d *RecordDecoder) Series(rec []byte, series []RefSeries) ([]RefSeries, error) { dec := encoding.Decbuf{B: rec} if RecordType(dec.Byte()) != RecordSeries { return nil, errors.New("invalid record type") } for len(dec.B) > 0 && dec.Err() == nil { ref := dec.Be64() lset := make(labels.Labels, dec.Uvarint(...
[ "func", "(", "d", "*", "RecordDecoder", ")", "Series", "(", "rec", "[", "]", "byte", ",", "series", "[", "]", "RefSeries", ")", "(", "[", "]", "RefSeries", ",", "error", ")", "{", "dec", ":=", "encoding", ".", "Decbuf", "{", "B", ":", "rec", "}",...
// Series appends series in rec to the given slice.
[ "Series", "appends", "series", "in", "rec", "to", "the", "given", "slice", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/record.go#L59-L88
train
prometheus/tsdb
record.go
Samples
func (d *RecordDecoder) Samples(rec []byte, samples []RefSample) ([]RefSample, error) { dec := encoding.Decbuf{B: rec} if RecordType(dec.Byte()) != RecordSamples { return nil, errors.New("invalid record type") } if dec.Len() == 0 { return samples, nil } var ( baseRef = dec.Be64() baseTime = dec.Be64int6...
go
func (d *RecordDecoder) Samples(rec []byte, samples []RefSample) ([]RefSample, error) { dec := encoding.Decbuf{B: rec} if RecordType(dec.Byte()) != RecordSamples { return nil, errors.New("invalid record type") } if dec.Len() == 0 { return samples, nil } var ( baseRef = dec.Be64() baseTime = dec.Be64int6...
[ "func", "(", "d", "*", "RecordDecoder", ")", "Samples", "(", "rec", "[", "]", "byte", ",", "samples", "[", "]", "RefSample", ")", "(", "[", "]", "RefSample", ",", "error", ")", "{", "dec", ":=", "encoding", ".", "Decbuf", "{", "B", ":", "rec", "}...
// Samples appends samples in rec to the given slice.
[ "Samples", "appends", "samples", "in", "rec", "to", "the", "given", "slice", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/record.go#L91-L123
train
prometheus/tsdb
record.go
Tombstones
func (d *RecordDecoder) Tombstones(rec []byte, tstones []Stone) ([]Stone, error) { dec := encoding.Decbuf{B: rec} if RecordType(dec.Byte()) != RecordTombstones { return nil, errors.New("invalid record type") } for dec.Len() > 0 && dec.Err() == nil { tstones = append(tstones, Stone{ ref: dec.Be64(), inter...
go
func (d *RecordDecoder) Tombstones(rec []byte, tstones []Stone) ([]Stone, error) { dec := encoding.Decbuf{B: rec} if RecordType(dec.Byte()) != RecordTombstones { return nil, errors.New("invalid record type") } for dec.Len() > 0 && dec.Err() == nil { tstones = append(tstones, Stone{ ref: dec.Be64(), inter...
[ "func", "(", "d", "*", "RecordDecoder", ")", "Tombstones", "(", "rec", "[", "]", "byte", ",", "tstones", "[", "]", "Stone", ")", "(", "[", "]", "Stone", ",", "error", ")", "{", "dec", ":=", "encoding", ".", "Decbuf", "{", "B", ":", "rec", "}", ...
// Tombstones appends tombstones in rec to the given slice.
[ "Tombstones", "appends", "tombstones", "in", "rec", "to", "the", "given", "slice", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/record.go#L126-L147
train
prometheus/tsdb
record.go
Series
func (e *RecordEncoder) Series(series []RefSeries, b []byte) []byte { buf := encoding.Encbuf{B: b} buf.PutByte(byte(RecordSeries)) for _, s := range series { buf.PutBE64(s.Ref) buf.PutUvarint(len(s.Labels)) for _, l := range s.Labels { buf.PutUvarintStr(l.Name) buf.PutUvarintStr(l.Value) } } return...
go
func (e *RecordEncoder) Series(series []RefSeries, b []byte) []byte { buf := encoding.Encbuf{B: b} buf.PutByte(byte(RecordSeries)) for _, s := range series { buf.PutBE64(s.Ref) buf.PutUvarint(len(s.Labels)) for _, l := range s.Labels { buf.PutUvarintStr(l.Name) buf.PutUvarintStr(l.Value) } } return...
[ "func", "(", "e", "*", "RecordEncoder", ")", "Series", "(", "series", "[", "]", "RefSeries", ",", "b", "[", "]", "byte", ")", "[", "]", "byte", "{", "buf", ":=", "encoding", ".", "Encbuf", "{", "B", ":", "b", "}", "\n", "buf", ".", "PutByte", "...
// Series appends the encoded series to b and returns the resulting slice.
[ "Series", "appends", "the", "encoded", "series", "to", "b", "and", "returns", "the", "resulting", "slice", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/record.go#L155-L169
train
prometheus/tsdb
record.go
Samples
func (e *RecordEncoder) Samples(samples []RefSample, b []byte) []byte { buf := encoding.Encbuf{B: b} buf.PutByte(byte(RecordSamples)) if len(samples) == 0 { return buf.Get() } // Store base timestamp and base reference number of first sample. // All samples encode their timestamp and ref as delta to those. f...
go
func (e *RecordEncoder) Samples(samples []RefSample, b []byte) []byte { buf := encoding.Encbuf{B: b} buf.PutByte(byte(RecordSamples)) if len(samples) == 0 { return buf.Get() } // Store base timestamp and base reference number of first sample. // All samples encode their timestamp and ref as delta to those. f...
[ "func", "(", "e", "*", "RecordEncoder", ")", "Samples", "(", "samples", "[", "]", "RefSample", ",", "b", "[", "]", "byte", ")", "[", "]", "byte", "{", "buf", ":=", "encoding", ".", "Encbuf", "{", "B", ":", "b", "}", "\n", "buf", ".", "PutByte", ...
// Samples appends the encoded samples to b and returns the resulting slice.
[ "Samples", "appends", "the", "encoded", "samples", "to", "b", "and", "returns", "the", "resulting", "slice", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/record.go#L172-L193
train
prometheus/tsdb
record.go
Tombstones
func (e *RecordEncoder) Tombstones(tstones []Stone, b []byte) []byte { buf := encoding.Encbuf{B: b} buf.PutByte(byte(RecordTombstones)) for _, s := range tstones { for _, iv := range s.intervals { buf.PutBE64(s.ref) buf.PutVarint64(iv.Mint) buf.PutVarint64(iv.Maxt) } } return buf.Get() }
go
func (e *RecordEncoder) Tombstones(tstones []Stone, b []byte) []byte { buf := encoding.Encbuf{B: b} buf.PutByte(byte(RecordTombstones)) for _, s := range tstones { for _, iv := range s.intervals { buf.PutBE64(s.ref) buf.PutVarint64(iv.Mint) buf.PutVarint64(iv.Maxt) } } return buf.Get() }
[ "func", "(", "e", "*", "RecordEncoder", ")", "Tombstones", "(", "tstones", "[", "]", "Stone", ",", "b", "[", "]", "byte", ")", "[", "]", "byte", "{", "buf", ":=", "encoding", ".", "Encbuf", "{", "B", ":", "b", "}", "\n", "buf", ".", "PutByte", ...
// Tombstones appends the encoded tombstones to b and returns the resulting slice.
[ "Tombstones", "appends", "the", "encoded", "tombstones", "to", "b", "and", "returns", "the", "resulting", "slice", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/record.go#L196-L208
train
prometheus/tsdb
tsdbutil/buffer.go
NewBuffer
func NewBuffer(it SeriesIterator, delta int64) *BufferedSeriesIterator { return &BufferedSeriesIterator{ it: it, buf: newSampleRing(delta, 16), lastTime: math.MinInt64, } }
go
func NewBuffer(it SeriesIterator, delta int64) *BufferedSeriesIterator { return &BufferedSeriesIterator{ it: it, buf: newSampleRing(delta, 16), lastTime: math.MinInt64, } }
[ "func", "NewBuffer", "(", "it", "SeriesIterator", ",", "delta", "int64", ")", "*", "BufferedSeriesIterator", "{", "return", "&", "BufferedSeriesIterator", "{", "it", ":", "it", ",", "buf", ":", "newSampleRing", "(", "delta", ",", "16", ")", ",", "lastTime", ...
// NewBuffer returns a new iterator that buffers the values within the time range // of the current element and the duration of delta before.
[ "NewBuffer", "returns", "a", "new", "iterator", "that", "buffers", "the", "values", "within", "the", "time", "range", "of", "the", "current", "element", "and", "the", "duration", "of", "delta", "before", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/tsdbutil/buffer.go#L44-L50
train
prometheus/tsdb
tsdbutil/buffer.go
PeekBack
func (b *BufferedSeriesIterator) PeekBack() (t int64, v float64, ok bool) { return b.buf.last() }
go
func (b *BufferedSeriesIterator) PeekBack() (t int64, v float64, ok bool) { return b.buf.last() }
[ "func", "(", "b", "*", "BufferedSeriesIterator", ")", "PeekBack", "(", ")", "(", "t", "int64", ",", "v", "float64", ",", "ok", "bool", ")", "{", "return", "b", ".", "buf", ".", "last", "(", ")", "\n", "}" ]
// PeekBack returns the previous element of the iterator. If there is none buffered, // ok is false.
[ "PeekBack", "returns", "the", "previous", "element", "of", "the", "iterator", ".", "If", "there", "is", "none", "buffered", "ok", "is", "false", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/tsdbutil/buffer.go#L54-L56
train
prometheus/tsdb
tsdbutil/buffer.go
add
func (r *sampleRing) add(t int64, v float64) { l := len(r.buf) // Grow the ring buffer if it fits no more elements. if l == r.l { buf := make([]sample, 2*l) copy(buf[l+r.f:], r.buf[r.f:]) copy(buf, r.buf[:r.f]) r.buf = buf r.i = r.f r.f += l } else { r.i++ if r.i >= l { r.i -= l } } r.buf[r...
go
func (r *sampleRing) add(t int64, v float64) { l := len(r.buf) // Grow the ring buffer if it fits no more elements. if l == r.l { buf := make([]sample, 2*l) copy(buf[l+r.f:], r.buf[r.f:]) copy(buf, r.buf[:r.f]) r.buf = buf r.i = r.f r.f += l } else { r.i++ if r.i >= l { r.i -= l } } r.buf[r...
[ "func", "(", "r", "*", "sampleRing", ")", "add", "(", "t", "int64", ",", "v", "float64", ")", "{", "l", ":=", "len", "(", "r", ".", "buf", ")", "\n", "// Grow the ring buffer if it fits no more elements.", "if", "l", "==", "r", ".", "l", "{", "buf", ...
// add adds a sample to the ring buffer and frees all samples that fall // out of the delta range.
[ "add", "adds", "a", "sample", "to", "the", "ring", "buffer", "and", "frees", "all", "samples", "that", "fall", "out", "of", "the", "delta", "range", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/tsdbutil/buffer.go#L182-L211
train
prometheus/tsdb
tsdbutil/buffer.go
last
func (r *sampleRing) last() (int64, float64, bool) { if r.l == 0 { return 0, 0, false } s := r.buf[r.i] return s.t, s.v, true }
go
func (r *sampleRing) last() (int64, float64, bool) { if r.l == 0 { return 0, 0, false } s := r.buf[r.i] return s.t, s.v, true }
[ "func", "(", "r", "*", "sampleRing", ")", "last", "(", ")", "(", "int64", ",", "float64", ",", "bool", ")", "{", "if", "r", ".", "l", "==", "0", "{", "return", "0", ",", "0", ",", "false", "\n", "}", "\n", "s", ":=", "r", ".", "buf", "[", ...
// last returns the most recent element added to the ring.
[ "last", "returns", "the", "most", "recent", "element", "added", "to", "the", "ring", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/tsdbutil/buffer.go#L214-L220
train
prometheus/tsdb
labels/labels.go
Equals
func (ls Labels) Equals(o Labels) bool { if len(ls) != len(o) { return false } for i, l := range ls { if o[i] != l { return false } } return true }
go
func (ls Labels) Equals(o Labels) bool { if len(ls) != len(o) { return false } for i, l := range ls { if o[i] != l { return false } } return true }
[ "func", "(", "ls", "Labels", ")", "Equals", "(", "o", "Labels", ")", "bool", "{", "if", "len", "(", "ls", ")", "!=", "len", "(", "o", ")", "{", "return", "false", "\n", "}", "\n", "for", "i", ",", "l", ":=", "range", "ls", "{", "if", "o", "...
// Equals returns whether the two label sets are equal.
[ "Equals", "returns", "whether", "the", "two", "label", "sets", "are", "equal", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/labels/labels.go#L85-L95
train
prometheus/tsdb
labels/labels.go
FromMap
func FromMap(m map[string]string) Labels { l := make(Labels, 0, len(m)) for k, v := range m { l = append(l, Label{Name: k, Value: v}) } sort.Sort(l) return l }
go
func FromMap(m map[string]string) Labels { l := make(Labels, 0, len(m)) for k, v := range m { l = append(l, Label{Name: k, Value: v}) } sort.Sort(l) return l }
[ "func", "FromMap", "(", "m", "map", "[", "string", "]", "string", ")", "Labels", "{", "l", ":=", "make", "(", "Labels", ",", "0", ",", "len", "(", "m", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "l", "=", "append", "(", ...
// FromMap returns new sorted Labels from the given map.
[ "FromMap", "returns", "new", "sorted", "Labels", "from", "the", "given", "map", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/labels/labels.go#L119-L127
train
prometheus/tsdb
labels/labels.go
ReadLabels
func ReadLabels(fn string, n int) ([]Labels, error) { f, err := os.Open(fn) if err != nil { return nil, err } defer f.Close() scanner := bufio.NewScanner(f) var mets []Labels hashes := map[uint64]struct{}{} i := 0 for scanner.Scan() && i < n { m := make(Labels, 0, 10) r := strings.NewReplacer("\"", "...
go
func ReadLabels(fn string, n int) ([]Labels, error) { f, err := os.Open(fn) if err != nil { return nil, err } defer f.Close() scanner := bufio.NewScanner(f) var mets []Labels hashes := map[uint64]struct{}{} i := 0 for scanner.Scan() && i < n { m := make(Labels, 0, 10) r := strings.NewReplacer("\"", "...
[ "func", "ReadLabels", "(", "fn", "string", ",", "n", "int", ")", "(", "[", "]", "Labels", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "fn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n"...
// ReadLabels reads up to n label sets in a JSON formatted file fn. It is mostly useful // to load testing data.
[ "ReadLabels", "reads", "up", "to", "n", "label", "sets", "in", "a", "JSON", "formatted", "file", "fn", ".", "It", "is", "mostly", "useful", "to", "load", "testing", "data", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/labels/labels.go#L172-L212
train
prometheus/tsdb
head.go
NewHead
func NewHead(r prometheus.Registerer, l log.Logger, wal *wal.WAL, chunkRange int64) (*Head, error) { if l == nil { l = log.NewNopLogger() } if chunkRange < 1 { return nil, errors.Errorf("invalid chunk range %d", chunkRange) } h := &Head{ wal: wal, logger: l, chunkRange: chunkRange, minTime: ...
go
func NewHead(r prometheus.Registerer, l log.Logger, wal *wal.WAL, chunkRange int64) (*Head, error) { if l == nil { l = log.NewNopLogger() } if chunkRange < 1 { return nil, errors.Errorf("invalid chunk range %d", chunkRange) } h := &Head{ wal: wal, logger: l, chunkRange: chunkRange, minTime: ...
[ "func", "NewHead", "(", "r", "prometheus", ".", "Registerer", ",", "l", "log", ".", "Logger", ",", "wal", "*", "wal", ".", "WAL", ",", "chunkRange", "int64", ")", "(", "*", "Head", ",", "error", ")", "{", "if", "l", "==", "nil", "{", "l", "=", ...
// NewHead opens the head block in dir.
[ "NewHead", "opens", "the", "head", "block", "in", "dir", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L223-L245
train
prometheus/tsdb
head.go
processWALSamples
func (h *Head) processWALSamples( minValidTime int64, input <-chan []RefSample, output chan<- []RefSample, ) (unknownRefs uint64) { defer close(output) // Mitigate lock contention in getByID. refSeries := map[uint64]*memSeries{} mint, maxt := int64(math.MaxInt64), int64(math.MinInt64) for samples := range inp...
go
func (h *Head) processWALSamples( minValidTime int64, input <-chan []RefSample, output chan<- []RefSample, ) (unknownRefs uint64) { defer close(output) // Mitigate lock contention in getByID. refSeries := map[uint64]*memSeries{} mint, maxt := int64(math.MaxInt64), int64(math.MinInt64) for samples := range inp...
[ "func", "(", "h", "*", "Head", ")", "processWALSamples", "(", "minValidTime", "int64", ",", "input", "<-", "chan", "[", "]", "RefSample", ",", "output", "chan", "<-", "[", "]", "RefSample", ",", ")", "(", "unknownRefs", "uint64", ")", "{", "defer", "cl...
// processWALSamples adds a partition of samples it receives to the head and passes // them on to other workers. // Samples before the mint timestamp are discarded.
[ "processWALSamples", "adds", "a", "partition", "of", "samples", "it", "receives", "to", "the", "head", "and", "passes", "them", "on", "to", "other", "workers", ".", "Samples", "before", "the", "mint", "timestamp", "are", "discarded", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L250-L292
train
prometheus/tsdb
head.go
Init
func (h *Head) Init(minValidTime int64) error { h.minValidTime = minValidTime defer h.postings.EnsureOrder() defer h.gc() // After loading the wal remove the obsolete data from the head. if h.wal == nil { return nil } // Backfill the checkpoint first if it exists. dir, startFrom, err := LastCheckpoint(h.wal....
go
func (h *Head) Init(minValidTime int64) error { h.minValidTime = minValidTime defer h.postings.EnsureOrder() defer h.gc() // After loading the wal remove the obsolete data from the head. if h.wal == nil { return nil } // Backfill the checkpoint first if it exists. dir, startFrom, err := LastCheckpoint(h.wal....
[ "func", "(", "h", "*", "Head", ")", "Init", "(", "minValidTime", "int64", ")", "error", "{", "h", ".", "minValidTime", "=", "minValidTime", "\n", "defer", "h", ".", "postings", ".", "EnsureOrder", "(", ")", "\n", "defer", "h", ".", "gc", "(", ")", ...
// Init loads data from the write ahead log and prepares the head for writes. // It should be called before using an appender so that // limits the ingested samples to the head min valid time.
[ "Init", "loads", "data", "from", "the", "write", "ahead", "log", "and", "prepares", "the", "head", "for", "writes", ".", "It", "should", "be", "called", "before", "using", "an", "appender", "so", "that", "limits", "the", "ingested", "samples", "to", "the",...
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L462-L508
train
prometheus/tsdb
head.go
initTime
func (h *Head) initTime(t int64) (initialized bool) { if !atomic.CompareAndSwapInt64(&h.minTime, math.MaxInt64, t) { return false } // Ensure that max time is initialized to at least the min time we just set. // Concurrent appenders may already have set it to a higher value. atomic.CompareAndSwapInt64(&h.maxTime...
go
func (h *Head) initTime(t int64) (initialized bool) { if !atomic.CompareAndSwapInt64(&h.minTime, math.MaxInt64, t) { return false } // Ensure that max time is initialized to at least the min time we just set. // Concurrent appenders may already have set it to a higher value. atomic.CompareAndSwapInt64(&h.maxTime...
[ "func", "(", "h", "*", "Head", ")", "initTime", "(", "t", "int64", ")", "(", "initialized", "bool", ")", "{", "if", "!", "atomic", ".", "CompareAndSwapInt64", "(", "&", "h", ".", "minTime", ",", "math", ".", "MaxInt64", ",", "t", ")", "{", "return"...
// initTime initializes a head with the first timestamp. This only needs to be called // for a completely fresh head with an empty WAL. // Returns true if the initialization took an effect.
[ "initTime", "initializes", "a", "head", "with", "the", "first", "timestamp", ".", "This", "only", "needs", "to", "be", "called", "for", "a", "completely", "fresh", "head", "with", "an", "empty", "WAL", ".", "Returns", "true", "if", "the", "initialization", ...
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L613-L622
train
prometheus/tsdb
head.go
Appender
func (h *Head) Appender() Appender { h.metrics.activeAppenders.Inc() // The head cache might not have a starting point yet. The init appender // picks up the first appended timestamp as the base. if h.MinTime() == math.MaxInt64 { return &initAppender{head: h} } return h.appender() }
go
func (h *Head) Appender() Appender { h.metrics.activeAppenders.Inc() // The head cache might not have a starting point yet. The init appender // picks up the first appended timestamp as the base. if h.MinTime() == math.MaxInt64 { return &initAppender{head: h} } return h.appender() }
[ "func", "(", "h", "*", "Head", ")", "Appender", "(", ")", "Appender", "{", "h", ".", "metrics", ".", "activeAppenders", ".", "Inc", "(", ")", "\n\n", "// The head cache might not have a starting point yet. The init appender", "// picks up the first appended timestamp as t...
// Appender returns a new Appender on the database.
[ "Appender", "returns", "a", "new", "Appender", "on", "the", "database", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L688-L697
train
prometheus/tsdb
head.go
chunkRewrite
func (h *Head) chunkRewrite(ref uint64, dranges Intervals) (err error) { if len(dranges) == 0 { return nil } ms := h.series.getByID(ref) ms.Lock() defer ms.Unlock() if len(ms.chunks) == 0 { return nil } metas := ms.chunksMetas() mint, maxt := metas[0].MinTime, metas[len(metas)-1].MaxTime it := newChunkS...
go
func (h *Head) chunkRewrite(ref uint64, dranges Intervals) (err error) { if len(dranges) == 0 { return nil } ms := h.series.getByID(ref) ms.Lock() defer ms.Unlock() if len(ms.chunks) == 0 { return nil } metas := ms.chunksMetas() mint, maxt := metas[0].MinTime, metas[len(metas)-1].MaxTime it := newChunkS...
[ "func", "(", "h", "*", "Head", ")", "chunkRewrite", "(", "ref", "uint64", ",", "dranges", "Intervals", ")", "(", "err", "error", ")", "{", "if", "len", "(", "dranges", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "ms", ":=", "h", ".",...
// chunkRewrite re-writes the chunks which overlaps with deleted ranges // and removes the samples in the deleted ranges. // Chunks is deleted if no samples are left at the end.
[ "chunkRewrite", "re", "-", "writes", "the", "chunks", "which", "overlaps", "with", "deleted", "ranges", "and", "removes", "the", "samples", "in", "the", "deleted", "ranges", ".", "Chunks", "is", "deleted", "if", "no", "samples", "are", "left", "at", "the", ...
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L931-L957
train
prometheus/tsdb
head.go
gc
func (h *Head) gc() { // Only data strictly lower than this timestamp must be deleted. mint := h.MinTime() // Drop old chunks and remember series IDs and hashes if they can be // deleted entirely. deleted, chunksRemoved := h.series.gc(mint) seriesRemoved := len(deleted) h.metrics.seriesRemoved.Add(float64(seri...
go
func (h *Head) gc() { // Only data strictly lower than this timestamp must be deleted. mint := h.MinTime() // Drop old chunks and remember series IDs and hashes if they can be // deleted entirely. deleted, chunksRemoved := h.series.gc(mint) seriesRemoved := len(deleted) h.metrics.seriesRemoved.Add(float64(seri...
[ "func", "(", "h", "*", "Head", ")", "gc", "(", ")", "{", "// Only data strictly lower than this timestamp must be deleted.", "mint", ":=", "h", ".", "MinTime", "(", ")", "\n\n", "// Drop old chunks and remember series IDs and hashes if they can be", "// deleted entirely.", ...
// gc removes data before the minimum timestamp from the head.
[ "gc", "removes", "data", "before", "the", "minimum", "timestamp", "from", "the", "head", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L960-L1018
train
prometheus/tsdb
head.go
Index
func (h *Head) Index() (IndexReader, error) { return h.indexRange(math.MinInt64, math.MaxInt64), nil }
go
func (h *Head) Index() (IndexReader, error) { return h.indexRange(math.MinInt64, math.MaxInt64), nil }
[ "func", "(", "h", "*", "Head", ")", "Index", "(", ")", "(", "IndexReader", ",", "error", ")", "{", "return", "h", ".", "indexRange", "(", "math", ".", "MinInt64", ",", "math", ".", "MaxInt64", ")", ",", "nil", "\n", "}" ]
// Index returns an IndexReader against the block.
[ "Index", "returns", "an", "IndexReader", "against", "the", "block", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1026-L1028
train
prometheus/tsdb
head.go
Chunks
func (h *Head) Chunks() (ChunkReader, error) { return h.chunksRange(math.MinInt64, math.MaxInt64), nil }
go
func (h *Head) Chunks() (ChunkReader, error) { return h.chunksRange(math.MinInt64, math.MaxInt64), nil }
[ "func", "(", "h", "*", "Head", ")", "Chunks", "(", ")", "(", "ChunkReader", ",", "error", ")", "{", "return", "h", ".", "chunksRange", "(", "math", ".", "MinInt64", ",", "math", ".", "MaxInt64", ")", ",", "nil", "\n", "}" ]
// Chunks returns a ChunkReader against the block.
[ "Chunks", "returns", "a", "ChunkReader", "against", "the", "block", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1038-L1040
train
prometheus/tsdb
head.go
compactable
func (h *Head) compactable() bool { return h.MaxTime()-h.MinTime() > h.chunkRange/2*3 }
go
func (h *Head) compactable() bool { return h.MaxTime()-h.MinTime() > h.chunkRange/2*3 }
[ "func", "(", "h", "*", "Head", ")", "compactable", "(", ")", "bool", "{", "return", "h", ".", "MaxTime", "(", ")", "-", "h", ".", "MinTime", "(", ")", ">", "h", ".", "chunkRange", "/", "2", "*", "3", "\n", "}" ]
// compactable returns whether the head has a compactable range. // The head has a compactable range when the head time range is 1.5 times the chunk range. // The 0.5 acts as a buffer of the appendable window.
[ "compactable", "returns", "whether", "the", "head", "has", "a", "compactable", "range", ".", "The", "head", "has", "a", "compactable", "range", "when", "the", "head", "time", "range", "is", "1", ".", "5", "times", "the", "chunk", "range", ".", "The", "0"...
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1062-L1064
train
prometheus/tsdb
head.go
Close
func (h *Head) Close() error { if h.wal == nil { return nil } return h.wal.Close() }
go
func (h *Head) Close() error { if h.wal == nil { return nil } return h.wal.Close() }
[ "func", "(", "h", "*", "Head", ")", "Close", "(", ")", "error", "{", "if", "h", ".", "wal", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "h", ".", "wal", ".", "Close", "(", ")", "\n", "}" ]
// Close flushes the WAL and closes the head.
[ "Close", "flushes", "the", "WAL", "and", "closes", "the", "head", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1067-L1072
train
prometheus/tsdb
head.go
packChunkID
func packChunkID(seriesID, chunkID uint64) uint64 { if seriesID > (1<<40)-1 { panic("series ID exceeds 5 bytes") } if chunkID > (1<<24)-1 { panic("chunk ID exceeds 3 bytes") } return (seriesID << 24) | chunkID }
go
func packChunkID(seriesID, chunkID uint64) uint64 { if seriesID > (1<<40)-1 { panic("series ID exceeds 5 bytes") } if chunkID > (1<<24)-1 { panic("chunk ID exceeds 3 bytes") } return (seriesID << 24) | chunkID }
[ "func", "packChunkID", "(", "seriesID", ",", "chunkID", "uint64", ")", "uint64", "{", "if", "seriesID", ">", "(", "1", "<<", "40", ")", "-", "1", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "chunkID", ">", "(", "1", "<<", "24", "...
// packChunkID packs a seriesID and a chunkID within it into a global 8 byte ID. // It panicks if the seriesID exceeds 5 bytes or the chunk ID 3 bytes.
[ "packChunkID", "packs", "a", "seriesID", "and", "a", "chunkID", "within", "it", "into", "a", "global", "8", "byte", "ID", ".", "It", "panicks", "if", "the", "seriesID", "exceeds", "5", "bytes", "or", "the", "chunk", "ID", "3", "bytes", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1085-L1093
train
prometheus/tsdb
head.go
Chunk
func (h *headChunkReader) Chunk(ref uint64) (chunkenc.Chunk, error) { sid, cid := unpackChunkID(ref) s := h.head.series.getByID(sid) // This means that the series has been garbage collected. if s == nil { return nil, ErrNotFound } s.Lock() c := s.chunk(int(cid)) // This means that the chunk has been garbag...
go
func (h *headChunkReader) Chunk(ref uint64) (chunkenc.Chunk, error) { sid, cid := unpackChunkID(ref) s := h.head.series.getByID(sid) // This means that the series has been garbage collected. if s == nil { return nil, ErrNotFound } s.Lock() c := s.chunk(int(cid)) // This means that the chunk has been garbag...
[ "func", "(", "h", "*", "headChunkReader", ")", "Chunk", "(", "ref", "uint64", ")", "(", "chunkenc", ".", "Chunk", ",", "error", ")", "{", "sid", ",", "cid", ":=", "unpackChunkID", "(", "ref", ")", "\n\n", "s", ":=", "h", ".", "head", ".", "series",...
// Chunk returns the chunk for the reference number.
[ "Chunk", "returns", "the", "chunk", "for", "the", "reference", "number", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1100-L1125
train
prometheus/tsdb
head.go
LabelValues
func (h *headIndexReader) LabelValues(names ...string) (index.StringTuples, error) { if len(names) != 1 { return nil, encoding.ErrInvalidSize } h.head.symMtx.RLock() sl := make([]string, 0, len(h.head.values[names[0]])) for s := range h.head.values[names[0]] { sl = append(sl, s) } h.head.symMtx.RUnlock() s...
go
func (h *headIndexReader) LabelValues(names ...string) (index.StringTuples, error) { if len(names) != 1 { return nil, encoding.ErrInvalidSize } h.head.symMtx.RLock() sl := make([]string, 0, len(h.head.values[names[0]])) for s := range h.head.values[names[0]] { sl = append(sl, s) } h.head.symMtx.RUnlock() s...
[ "func", "(", "h", "*", "headIndexReader", ")", "LabelValues", "(", "names", "...", "string", ")", "(", "index", ".", "StringTuples", ",", "error", ")", "{", "if", "len", "(", "names", ")", "!=", "1", "{", "return", "nil", ",", "encoding", ".", "ErrIn...
// LabelValues returns the possible label values
[ "LabelValues", "returns", "the", "possible", "label", "values" ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1162-L1176
train
prometheus/tsdb
head.go
LabelNames
func (h *headIndexReader) LabelNames() ([]string, error) { h.head.symMtx.RLock() defer h.head.symMtx.RUnlock() labelNames := make([]string, 0, len(h.head.values)) for name := range h.head.values { if name == "" { continue } labelNames = append(labelNames, name) } sort.Strings(labelNames) return labelNam...
go
func (h *headIndexReader) LabelNames() ([]string, error) { h.head.symMtx.RLock() defer h.head.symMtx.RUnlock() labelNames := make([]string, 0, len(h.head.values)) for name := range h.head.values { if name == "" { continue } labelNames = append(labelNames, name) } sort.Strings(labelNames) return labelNam...
[ "func", "(", "h", "*", "headIndexReader", ")", "LabelNames", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "h", ".", "head", ".", "symMtx", ".", "RLock", "(", ")", "\n", "defer", "h", ".", "head", ".", "symMtx", ".", "RUnlock", "(", ...
// LabelNames returns all the unique label names present in the head.
[ "LabelNames", "returns", "all", "the", "unique", "label", "names", "present", "in", "the", "head", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1179-L1191
train
prometheus/tsdb
head.go
Postings
func (h *headIndexReader) Postings(name, value string) (index.Postings, error) { return h.head.postings.Get(name, value), nil }
go
func (h *headIndexReader) Postings(name, value string) (index.Postings, error) { return h.head.postings.Get(name, value), nil }
[ "func", "(", "h", "*", "headIndexReader", ")", "Postings", "(", "name", ",", "value", "string", ")", "(", "index", ".", "Postings", ",", "error", ")", "{", "return", "h", ".", "head", ".", "postings", ".", "Get", "(", "name", ",", "value", ")", ","...
// Postings returns the postings list iterator for the label pair.
[ "Postings", "returns", "the", "postings", "list", "iterator", "for", "the", "label", "pair", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1194-L1196
train
prometheus/tsdb
head.go
Series
func (h *headIndexReader) Series(ref uint64, lbls *labels.Labels, chks *[]chunks.Meta) error { s := h.head.series.getByID(ref) if s == nil { h.head.metrics.seriesNotFound.Inc() return ErrNotFound } *lbls = append((*lbls)[:0], s.lset...) s.Lock() defer s.Unlock() *chks = (*chks)[:0] for i, c := range s.c...
go
func (h *headIndexReader) Series(ref uint64, lbls *labels.Labels, chks *[]chunks.Meta) error { s := h.head.series.getByID(ref) if s == nil { h.head.metrics.seriesNotFound.Inc() return ErrNotFound } *lbls = append((*lbls)[:0], s.lset...) s.Lock() defer s.Unlock() *chks = (*chks)[:0] for i, c := range s.c...
[ "func", "(", "h", "*", "headIndexReader", ")", "Series", "(", "ref", "uint64", ",", "lbls", "*", "labels", ".", "Labels", ",", "chks", "*", "[", "]", "chunks", ".", "Meta", ")", "error", "{", "s", ":=", "h", ".", "head", ".", "series", ".", "getB...
// Series returns the series for the given reference.
[ "Series", "returns", "the", "series", "for", "the", "given", "reference", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1227-L1254
train
prometheus/tsdb
head.go
gc
func (s *stripeSeries) gc(mint int64) (map[uint64]struct{}, int) { var ( deleted = map[uint64]struct{}{} rmChunks = 0 ) // Run through all series and truncate old chunks. Mark those with no // chunks left as deleted and store their ID. for i := 0; i < stripeSize; i++ { s.locks[i].Lock() for hash, all := ...
go
func (s *stripeSeries) gc(mint int64) (map[uint64]struct{}, int) { var ( deleted = map[uint64]struct{}{} rmChunks = 0 ) // Run through all series and truncate old chunks. Mark those with no // chunks left as deleted and store their ID. for i := 0; i < stripeSize; i++ { s.locks[i].Lock() for hash, all := ...
[ "func", "(", "s", "*", "stripeSeries", ")", "gc", "(", "mint", "int64", ")", "(", "map", "[", "uint64", "]", "struct", "{", "}", ",", "int", ")", "{", "var", "(", "deleted", "=", "map", "[", "uint64", "]", "struct", "{", "}", "{", "}", "\n", ...
// gc garbage collects old chunks that are strictly before mint and removes // series entirely that have no chunks left.
[ "gc", "garbage", "collects", "old", "chunks", "that", "are", "strictly", "before", "mint", "and", "removes", "series", "entirely", "that", "have", "no", "chunks", "left", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1387-L1434
train
prometheus/tsdb
head.go
appendable
func (s *memSeries) appendable(t int64, v float64) error { c := s.head() if c == nil { return nil } if t > c.maxTime { return nil } if t < c.maxTime { return ErrOutOfOrderSample } // We are allowing exact duplicates as we can encounter them in valid cases // like federation and erroring out at that time...
go
func (s *memSeries) appendable(t int64, v float64) error { c := s.head() if c == nil { return nil } if t > c.maxTime { return nil } if t < c.maxTime { return ErrOutOfOrderSample } // We are allowing exact duplicates as we can encounter them in valid cases // like federation and erroring out at that time...
[ "func", "(", "s", "*", "memSeries", ")", "appendable", "(", "t", "int64", ",", "v", "float64", ")", "error", "{", "c", ":=", "s", ".", "head", "(", ")", "\n", "if", "c", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "t", ">", "c...
// appendable checks whether the given sample is valid for appending to the series.
[ "appendable", "checks", "whether", "the", "given", "sample", "is", "valid", "for", "appending", "to", "the", "series", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1576-L1594
train
prometheus/tsdb
head.go
truncateChunksBefore
func (s *memSeries) truncateChunksBefore(mint int64) (removed int) { var k int for i, c := range s.chunks { if c.maxTime >= mint { break } k = i + 1 } s.chunks = append(s.chunks[:0], s.chunks[k:]...) s.firstChunkID += k if len(s.chunks) == 0 { s.headChunk = nil } else { s.headChunk = s.chunks[len(s....
go
func (s *memSeries) truncateChunksBefore(mint int64) (removed int) { var k int for i, c := range s.chunks { if c.maxTime >= mint { break } k = i + 1 } s.chunks = append(s.chunks[:0], s.chunks[k:]...) s.firstChunkID += k if len(s.chunks) == 0 { s.headChunk = nil } else { s.headChunk = s.chunks[len(s....
[ "func", "(", "s", "*", "memSeries", ")", "truncateChunksBefore", "(", "mint", "int64", ")", "(", "removed", "int", ")", "{", "var", "k", "int", "\n", "for", "i", ",", "c", ":=", "range", "s", ".", "chunks", "{", "if", "c", ".", "maxTime", ">=", "...
// truncateChunksBefore removes all chunks from the series that have not timestamp // at or after mint. Chunk IDs remain unchanged.
[ "truncateChunksBefore", "removes", "all", "chunks", "from", "the", "series", "that", "have", "not", "timestamp", "at", "or", "after", "mint", ".", "Chunk", "IDs", "remain", "unchanged", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/head.go#L1610-L1627
train
prometheus/tsdb
wal/reader.go
Next
func (r *Reader) Next() bool { err := r.next() if errors.Cause(err) == io.EOF { // The last WAL segment record shouldn't be torn(should be full or last). // The last record would be torn after a crash just before // the last record part could be persisted to disk. if recType(r.curRecTyp) == recFirst || recTyp...
go
func (r *Reader) Next() bool { err := r.next() if errors.Cause(err) == io.EOF { // The last WAL segment record shouldn't be torn(should be full or last). // The last record would be torn after a crash just before // the last record part could be persisted to disk. if recType(r.curRecTyp) == recFirst || recTyp...
[ "func", "(", "r", "*", "Reader", ")", "Next", "(", ")", "bool", "{", "err", ":=", "r", ".", "next", "(", ")", "\n", "if", "errors", ".", "Cause", "(", "err", ")", "==", "io", ".", "EOF", "{", "// The last WAL segment record shouldn't be torn(should be fu...
// Next advances the reader to the next records and returns true if it exists. // It must not be called again after it returned false.
[ "Next", "advances", "the", "reader", "to", "the", "next", "records", "and", "returns", "true", "if", "it", "exists", ".", "It", "must", "not", "be", "called", "again", "after", "it", "returned", "false", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/reader.go#L42-L55
train
prometheus/tsdb
wal/reader.go
Err
func (r *Reader) Err() error { if r.err == nil { return nil } if b, ok := r.rdr.(*segmentBufReader); ok { return &CorruptionErr{ Err: r.err, Dir: b.segs[b.cur].Dir(), Segment: b.segs[b.cur].Index(), Offset: int64(b.off), } } return &CorruptionErr{ Err: r.err, Segment: -1, Offse...
go
func (r *Reader) Err() error { if r.err == nil { return nil } if b, ok := r.rdr.(*segmentBufReader); ok { return &CorruptionErr{ Err: r.err, Dir: b.segs[b.cur].Dir(), Segment: b.segs[b.cur].Index(), Offset: int64(b.off), } } return &CorruptionErr{ Err: r.err, Segment: -1, Offse...
[ "func", "(", "r", "*", "Reader", ")", "Err", "(", ")", "error", "{", "if", "r", ".", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "b", ",", "ok", ":=", "r", ".", "rdr", ".", "(", "*", "segmentBufReader", ")", ";", "ok", ...
// Err returns the last encountered error wrapped in a corruption error. // If the reader does not allow to infer a segment index and offset, a total // offset in the reader stream will be provided.
[ "Err", "returns", "the", "last", "encountered", "error", "wrapped", "in", "a", "corruption", "error", ".", "If", "the", "reader", "does", "not", "allow", "to", "infer", "a", "segment", "index", "and", "offset", "a", "total", "offset", "in", "the", "reader"...
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/reader.go#L144-L161
train
prometheus/tsdb
wal/reader.go
Segment
func (r *Reader) Segment() int { if b, ok := r.rdr.(*segmentBufReader); ok { return b.segs[b.cur].Index() } return -1 }
go
func (r *Reader) Segment() int { if b, ok := r.rdr.(*segmentBufReader); ok { return b.segs[b.cur].Index() } return -1 }
[ "func", "(", "r", "*", "Reader", ")", "Segment", "(", ")", "int", "{", "if", "b", ",", "ok", ":=", "r", ".", "rdr", ".", "(", "*", "segmentBufReader", ")", ";", "ok", "{", "return", "b", ".", "segs", "[", "b", ".", "cur", "]", ".", "Index", ...
// Segment returns the current segment being read.
[ "Segment", "returns", "the", "current", "segment", "being", "read", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/reader.go#L170-L175
train
prometheus/tsdb
wal/reader.go
Offset
func (r *Reader) Offset() int64 { if b, ok := r.rdr.(*segmentBufReader); ok { return int64(b.off) } return r.total }
go
func (r *Reader) Offset() int64 { if b, ok := r.rdr.(*segmentBufReader); ok { return int64(b.off) } return r.total }
[ "func", "(", "r", "*", "Reader", ")", "Offset", "(", ")", "int64", "{", "if", "b", ",", "ok", ":=", "r", ".", "rdr", ".", "(", "*", "segmentBufReader", ")", ";", "ok", "{", "return", "int64", "(", "b", ".", "off", ")", "\n", "}", "\n", "retur...
// Offset returns the current position of the segment being read.
[ "Offset", "returns", "the", "current", "position", "of", "the", "segment", "being", "read", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/reader.go#L178-L183
train
prometheus/tsdb
querier.go
NewBlockQuerier
func NewBlockQuerier(b BlockReader, mint, maxt int64) (Querier, error) { indexr, err := b.Index() if err != nil { return nil, errors.Wrapf(err, "open index reader") } chunkr, err := b.Chunks() if err != nil { indexr.Close() return nil, errors.Wrapf(err, "open chunk reader") } tombsr, err := b.Tombstones() ...
go
func NewBlockQuerier(b BlockReader, mint, maxt int64) (Querier, error) { indexr, err := b.Index() if err != nil { return nil, errors.Wrapf(err, "open index reader") } chunkr, err := b.Chunks() if err != nil { indexr.Close() return nil, errors.Wrapf(err, "open chunk reader") } tombsr, err := b.Tombstones() ...
[ "func", "NewBlockQuerier", "(", "b", "BlockReader", ",", "mint", ",", "maxt", "int64", ")", "(", "Querier", ",", "error", ")", "{", "indexr", ",", "err", ":=", "b", ".", "Index", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", ...
// NewBlockQuerier returns a querier against the reader.
[ "NewBlockQuerier", "returns", "a", "querier", "against", "the", "reader", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/querier.go#L177-L200
train
prometheus/tsdb
querier.go
PostingsForMatchers
func PostingsForMatchers(ix IndexReader, ms ...labels.Matcher) (index.Postings, error) { var its, notIts []index.Postings // See which label must be non-empty. labelMustBeSet := make(map[string]bool, len(ms)) for _, m := range ms { if !m.Matches("") { labelMustBeSet[m.Name()] = true } } for _, m := range ...
go
func PostingsForMatchers(ix IndexReader, ms ...labels.Matcher) (index.Postings, error) { var its, notIts []index.Postings // See which label must be non-empty. labelMustBeSet := make(map[string]bool, len(ms)) for _, m := range ms { if !m.Matches("") { labelMustBeSet[m.Name()] = true } } for _, m := range ...
[ "func", "PostingsForMatchers", "(", "ix", "IndexReader", ",", "ms", "...", "labels", ".", "Matcher", ")", "(", "index", ".", "Postings", ",", "error", ")", "{", "var", "its", ",", "notIts", "[", "]", "index", ".", "Postings", "\n", "// See which label must...
// PostingsForMatchers assembles a single postings iterator against the index reader // based on the given matchers.
[ "PostingsForMatchers", "assembles", "a", "single", "postings", "iterator", "against", "the", "index", "reader", "based", "on", "the", "given", "matchers", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/querier.go#L271-L348
train
prometheus/tsdb
querier.go
inversePostingsForMatcher
func inversePostingsForMatcher(ix IndexReader, m labels.Matcher) (index.Postings, error) { tpls, err := ix.LabelValues(m.Name()) if err != nil { return nil, err } var res []string for i := 0; i < tpls.Len(); i++ { vals, err := tpls.At(i) if err != nil { return nil, err } if !m.Matches(vals[0]) { ...
go
func inversePostingsForMatcher(ix IndexReader, m labels.Matcher) (index.Postings, error) { tpls, err := ix.LabelValues(m.Name()) if err != nil { return nil, err } var res []string for i := 0; i < tpls.Len(); i++ { vals, err := tpls.At(i) if err != nil { return nil, err } if !m.Matches(vals[0]) { ...
[ "func", "inversePostingsForMatcher", "(", "ix", "IndexReader", ",", "m", "labels", ".", "Matcher", ")", "(", "index", ".", "Postings", ",", "error", ")", "{", "tpls", ",", "err", ":=", "ix", ".", "LabelValues", "(", "m", ".", "Name", "(", ")", ")", "...
// inversePostingsForMatcher eeturns the postings for the series with the label name set but not matching the matcher.
[ "inversePostingsForMatcher", "eeturns", "the", "postings", "for", "the", "series", "with", "the", "label", "name", "set", "but", "not", "matching", "the", "matcher", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/querier.go#L392-L421
train
prometheus/tsdb
querier.go
LookupChunkSeries
func LookupChunkSeries(ir IndexReader, tr TombstoneReader, ms ...labels.Matcher) (ChunkSeriesSet, error) { if tr == nil { tr = newMemTombstones() } p, err := PostingsForMatchers(ir, ms...) if err != nil { return nil, err } return &baseChunkSeries{ p: p, index: ir, tombstones: tr, }, nil }
go
func LookupChunkSeries(ir IndexReader, tr TombstoneReader, ms ...labels.Matcher) (ChunkSeriesSet, error) { if tr == nil { tr = newMemTombstones() } p, err := PostingsForMatchers(ir, ms...) if err != nil { return nil, err } return &baseChunkSeries{ p: p, index: ir, tombstones: tr, }, nil }
[ "func", "LookupChunkSeries", "(", "ir", "IndexReader", ",", "tr", "TombstoneReader", ",", "ms", "...", "labels", ".", "Matcher", ")", "(", "ChunkSeriesSet", ",", "error", ")", "{", "if", "tr", "==", "nil", "{", "tr", "=", "newMemTombstones", "(", ")", "\...
// LookupChunkSeries retrieves all series for the given matchers and returns a ChunkSeriesSet // over them. It drops chunks based on tombstones in the given reader.
[ "LookupChunkSeries", "retrieves", "all", "series", "for", "the", "given", "matchers", "and", "returns", "a", "ChunkSeriesSet", "over", "them", ".", "It", "drops", "chunks", "based", "on", "tombstones", "in", "the", "given", "reader", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/querier.go#L624-L637
train
prometheus/tsdb
index/postings.go
NewMemPostings
func NewMemPostings() *MemPostings { return &MemPostings{ m: make(map[string]map[string][]uint64, 512), ordered: true, } }
go
func NewMemPostings() *MemPostings { return &MemPostings{ m: make(map[string]map[string][]uint64, 512), ordered: true, } }
[ "func", "NewMemPostings", "(", ")", "*", "MemPostings", "{", "return", "&", "MemPostings", "{", "m", ":", "make", "(", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "uint64", ",", "512", ")", ",", "ordered", ":", "true", ",", "}",...
// NewMemPostings returns a memPostings that's ready for reads and writes.
[ "NewMemPostings", "returns", "a", "memPostings", "that", "s", "ready", "for", "reads", "and", "writes", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L45-L50
train
prometheus/tsdb
index/postings.go
NewUnorderedMemPostings
func NewUnorderedMemPostings() *MemPostings { return &MemPostings{ m: make(map[string]map[string][]uint64, 512), ordered: false, } }
go
func NewUnorderedMemPostings() *MemPostings { return &MemPostings{ m: make(map[string]map[string][]uint64, 512), ordered: false, } }
[ "func", "NewUnorderedMemPostings", "(", ")", "*", "MemPostings", "{", "return", "&", "MemPostings", "{", "m", ":", "make", "(", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "uint64", ",", "512", ")", ",", "ordered", ":", "false", "...
// NewUnorderedMemPostings returns a memPostings that is not safe to be read from // until ensureOrder was called once.
[ "NewUnorderedMemPostings", "returns", "a", "memPostings", "that", "is", "not", "safe", "to", "be", "read", "from", "until", "ensureOrder", "was", "called", "once", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L54-L59
train
prometheus/tsdb
index/postings.go
SortedKeys
func (p *MemPostings) SortedKeys() []labels.Label { p.mtx.RLock() keys := make([]labels.Label, 0, len(p.m)) for n, e := range p.m { for v := range e { keys = append(keys, labels.Label{Name: n, Value: v}) } } p.mtx.RUnlock() sort.Slice(keys, func(i, j int) bool { if d := strings.Compare(keys[i].Name, ke...
go
func (p *MemPostings) SortedKeys() []labels.Label { p.mtx.RLock() keys := make([]labels.Label, 0, len(p.m)) for n, e := range p.m { for v := range e { keys = append(keys, labels.Label{Name: n, Value: v}) } } p.mtx.RUnlock() sort.Slice(keys, func(i, j int) bool { if d := strings.Compare(keys[i].Name, ke...
[ "func", "(", "p", "*", "MemPostings", ")", "SortedKeys", "(", ")", "[", "]", "labels", ".", "Label", "{", "p", ".", "mtx", ".", "RLock", "(", ")", "\n", "keys", ":=", "make", "(", "[", "]", "labels", ".", "Label", ",", "0", ",", "len", "(", "...
// SortedKeys returns a list of sorted label keys of the postings.
[ "SortedKeys", "returns", "a", "list", "of", "sorted", "label", "keys", "of", "the", "postings", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L62-L80
train
prometheus/tsdb
index/postings.go
Get
func (p *MemPostings) Get(name, value string) Postings { var lp []uint64 p.mtx.RLock() l := p.m[name] if l != nil { lp = l[value] } p.mtx.RUnlock() if lp == nil { return EmptyPostings() } return newListPostings(lp...) }
go
func (p *MemPostings) Get(name, value string) Postings { var lp []uint64 p.mtx.RLock() l := p.m[name] if l != nil { lp = l[value] } p.mtx.RUnlock() if lp == nil { return EmptyPostings() } return newListPostings(lp...) }
[ "func", "(", "p", "*", "MemPostings", ")", "Get", "(", "name", ",", "value", "string", ")", "Postings", "{", "var", "lp", "[", "]", "uint64", "\n", "p", ".", "mtx", ".", "RLock", "(", ")", "\n", "l", ":=", "p", ".", "m", "[", "name", "]", "\n...
// Get returns a postings list for the given label pair.
[ "Get", "returns", "a", "postings", "list", "for", "the", "given", "label", "pair", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L83-L96
train
prometheus/tsdb
index/postings.go
EnsureOrder
func (p *MemPostings) EnsureOrder() { p.mtx.Lock() defer p.mtx.Unlock() if p.ordered { return } n := runtime.GOMAXPROCS(0) workc := make(chan []uint64) var wg sync.WaitGroup wg.Add(n) for i := 0; i < n; i++ { go func() { for l := range workc { sort.Slice(l, func(i, j int) bool { return l[i] < l[...
go
func (p *MemPostings) EnsureOrder() { p.mtx.Lock() defer p.mtx.Unlock() if p.ordered { return } n := runtime.GOMAXPROCS(0) workc := make(chan []uint64) var wg sync.WaitGroup wg.Add(n) for i := 0; i < n; i++ { go func() { for l := range workc { sort.Slice(l, func(i, j int) bool { return l[i] < l[...
[ "func", "(", "p", "*", "MemPostings", ")", "EnsureOrder", "(", ")", "{", "p", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "mtx", ".", "Unlock", "(", ")", "\n\n", "if", "p", ".", "ordered", "{", "return", "\n", "}", "\n\n", "n", ...
// EnsureOrder ensures that all postings lists are sorted. After it returns all further // calls to add and addFor will insert new IDs in a sorted manner.
[ "EnsureOrder", "ensures", "that", "all", "postings", "lists", "are", "sorted", ".", "After", "it", "returns", "all", "further", "calls", "to", "add", "and", "addFor", "will", "insert", "new", "IDs", "in", "a", "sorted", "manner", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L105-L137
train
prometheus/tsdb
index/postings.go
Delete
func (p *MemPostings) Delete(deleted map[uint64]struct{}) { var keys, vals []string // Collect all keys relevant for deletion once. New keys added afterwards // can by definition not be affected by any of the given deletes. p.mtx.RLock() for n := range p.m { keys = append(keys, n) } p.mtx.RUnlock() for _, n...
go
func (p *MemPostings) Delete(deleted map[uint64]struct{}) { var keys, vals []string // Collect all keys relevant for deletion once. New keys added afterwards // can by definition not be affected by any of the given deletes. p.mtx.RLock() for n := range p.m { keys = append(keys, n) } p.mtx.RUnlock() for _, n...
[ "func", "(", "p", "*", "MemPostings", ")", "Delete", "(", "deleted", "map", "[", "uint64", "]", "struct", "{", "}", ")", "{", "var", "keys", ",", "vals", "[", "]", "string", "\n\n", "// Collect all keys relevant for deletion once. New keys added afterwards", "//...
// Delete removes all ids in the given map from the postings lists.
[ "Delete", "removes", "all", "ids", "in", "the", "given", "map", "from", "the", "postings", "lists", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L140-L196
train
prometheus/tsdb
index/postings.go
Iter
func (p *MemPostings) Iter(f func(labels.Label, Postings) error) error { p.mtx.RLock() defer p.mtx.RUnlock() for n, e := range p.m { for v, p := range e { if err := f(labels.Label{Name: n, Value: v}, newListPostings(p...)); err != nil { return err } } } return nil }
go
func (p *MemPostings) Iter(f func(labels.Label, Postings) error) error { p.mtx.RLock() defer p.mtx.RUnlock() for n, e := range p.m { for v, p := range e { if err := f(labels.Label{Name: n, Value: v}, newListPostings(p...)); err != nil { return err } } } return nil }
[ "func", "(", "p", "*", "MemPostings", ")", "Iter", "(", "f", "func", "(", "labels", ".", "Label", ",", "Postings", ")", "error", ")", "error", "{", "p", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "mtx", ".", "RUnlock", "(", ")...
// Iter calls f for each postings list. It aborts if f returns an error and returns it.
[ "Iter", "calls", "f", "for", "each", "postings", "list", ".", "It", "aborts", "if", "f", "returns", "an", "error", "and", "returns", "it", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L199-L211
train
prometheus/tsdb
index/postings.go
Add
func (p *MemPostings) Add(id uint64, lset labels.Labels) { p.mtx.Lock() for _, l := range lset { p.addFor(id, l) } p.addFor(id, allPostingsKey) p.mtx.Unlock() }
go
func (p *MemPostings) Add(id uint64, lset labels.Labels) { p.mtx.Lock() for _, l := range lset { p.addFor(id, l) } p.addFor(id, allPostingsKey) p.mtx.Unlock() }
[ "func", "(", "p", "*", "MemPostings", ")", "Add", "(", "id", "uint64", ",", "lset", "labels", ".", "Labels", ")", "{", "p", ".", "mtx", ".", "Lock", "(", ")", "\n\n", "for", "_", ",", "l", ":=", "range", "lset", "{", "p", ".", "addFor", "(", ...
// Add a label set to the postings index.
[ "Add", "a", "label", "set", "to", "the", "postings", "index", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L214-L223
train
prometheus/tsdb
index/postings.go
ExpandPostings
func ExpandPostings(p Postings) (res []uint64, err error) { for p.Next() { res = append(res, p.At()) } return res, p.Err() }
go
func ExpandPostings(p Postings) (res []uint64, err error) { for p.Next() { res = append(res, p.At()) } return res, p.Err() }
[ "func", "ExpandPostings", "(", "p", "Postings", ")", "(", "res", "[", "]", "uint64", ",", "err", "error", ")", "{", "for", "p", ".", "Next", "(", ")", "{", "res", "=", "append", "(", "res", ",", "p", ".", "At", "(", ")", ")", "\n", "}", "\n",...
// ExpandPostings returns the postings expanded as a slice.
[ "ExpandPostings", "returns", "the", "postings", "expanded", "as", "a", "slice", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L250-L255
train
prometheus/tsdb
index/postings.go
Intersect
func Intersect(its ...Postings) Postings { if len(its) == 0 { return EmptyPostings() } if len(its) == 1 { return its[0] } l := len(its) / 2 a := Intersect(its[:l]...) b := Intersect(its[l:]...) if a == EmptyPostings() || b == EmptyPostings() { return EmptyPostings() } return newIntersectPostings(a, b)...
go
func Intersect(its ...Postings) Postings { if len(its) == 0 { return EmptyPostings() } if len(its) == 1 { return its[0] } l := len(its) / 2 a := Intersect(its[:l]...) b := Intersect(its[l:]...) if a == EmptyPostings() || b == EmptyPostings() { return EmptyPostings() } return newIntersectPostings(a, b)...
[ "func", "Intersect", "(", "its", "...", "Postings", ")", "Postings", "{", "if", "len", "(", "its", ")", "==", "0", "{", "return", "EmptyPostings", "(", ")", "\n", "}", "\n", "if", "len", "(", "its", ")", "==", "1", "{", "return", "its", "[", "0",...
// Intersect returns a new postings list over the intersection of the // input postings.
[ "Intersect", "returns", "a", "new", "postings", "list", "over", "the", "intersection", "of", "the", "input", "postings", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L299-L315
train
prometheus/tsdb
index/postings.go
Merge
func Merge(its ...Postings) Postings { if len(its) == 0 { return EmptyPostings() } if len(its) == 1 { return its[0] } p, ok := newMergedPostings(its) if !ok { return EmptyPostings() } return p }
go
func Merge(its ...Postings) Postings { if len(its) == 0 { return EmptyPostings() } if len(its) == 1 { return its[0] } p, ok := newMergedPostings(its) if !ok { return EmptyPostings() } return p }
[ "func", "Merge", "(", "its", "...", "Postings", ")", "Postings", "{", "if", "len", "(", "its", ")", "==", "0", "{", "return", "EmptyPostings", "(", ")", "\n", "}", "\n", "if", "len", "(", "its", ")", "==", "1", "{", "return", "its", "[", "0", "...
// Merge returns a new iterator over the union of the input iterators.
[ "Merge", "returns", "a", "new", "iterator", "over", "the", "union", "of", "the", "input", "iterators", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L371-L384
train
prometheus/tsdb
index/postings.go
Without
func Without(full, drop Postings) Postings { if full == EmptyPostings() { return EmptyPostings() } if drop == EmptyPostings() { return full } return newRemovedPostings(full, drop) }
go
func Without(full, drop Postings) Postings { if full == EmptyPostings() { return EmptyPostings() } if drop == EmptyPostings() { return full } return newRemovedPostings(full, drop) }
[ "func", "Without", "(", "full", ",", "drop", "Postings", ")", "Postings", "{", "if", "full", "==", "EmptyPostings", "(", ")", "{", "return", "EmptyPostings", "(", ")", "\n", "}", "\n\n", "if", "drop", "==", "EmptyPostings", "(", ")", "{", "return", "fu...
// Without returns a new postings list that contains all elements from the full list that // are not in the drop list.
[ "Without", "returns", "a", "new", "postings", "list", "that", "contains", "all", "elements", "from", "the", "full", "list", "that", "are", "not", "in", "the", "drop", "list", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/postings.go#L520-L529
train
prometheus/tsdb
fileutil/flock.go
Flock
func Flock(fileName string) (r Releaser, existed bool, err error) { if err = os.MkdirAll(filepath.Dir(fileName), 0755); err != nil { return nil, false, err } _, err = os.Stat(fileName) existed = err == nil r, err = newLock(fileName) return r, existed, err }
go
func Flock(fileName string) (r Releaser, existed bool, err error) { if err = os.MkdirAll(filepath.Dir(fileName), 0755); err != nil { return nil, false, err } _, err = os.Stat(fileName) existed = err == nil r, err = newLock(fileName) return r, existed, err }
[ "func", "Flock", "(", "fileName", "string", ")", "(", "r", "Releaser", ",", "existed", "bool", ",", "err", "error", ")", "{", "if", "err", "=", "os", ".", "MkdirAll", "(", "filepath", ".", "Dir", "(", "fileName", ")", ",", "0755", ")", ";", "err", ...
// Flock locks the file with the provided name. If the file does not exist, it is // created. The returned Releaser is used to release the lock. existed is true // if the file to lock already existed. A non-nil error is returned if the // locking has failed. Neither this function nor the returned Releaser is // gorouti...
[ "Flock", "locks", "the", "file", "with", "the", "provided", "name", ".", "If", "the", "file", "does", "not", "exist", "it", "is", "created", ".", "The", "returned", "Releaser", "is", "used", "to", "release", "the", "lock", ".", "existed", "is", "true", ...
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/fileutil/flock.go#L31-L41
train
prometheus/tsdb
tsdbutil/chunks.go
PopulatedChunk
func PopulatedChunk(numSamples int, minTime int64) chunks.Meta { samples := make([]Sample, numSamples) for i := 0; i < numSamples; i++ { samples[i] = sample{minTime + int64(i*1000), 1.0} } return ChunkFromSamples(samples) }
go
func PopulatedChunk(numSamples int, minTime int64) chunks.Meta { samples := make([]Sample, numSamples) for i := 0; i < numSamples; i++ { samples[i] = sample{minTime + int64(i*1000), 1.0} } return ChunkFromSamples(samples) }
[ "func", "PopulatedChunk", "(", "numSamples", "int", ",", "minTime", "int64", ")", "chunks", ".", "Meta", "{", "samples", ":=", "make", "(", "[", "]", "Sample", ",", "numSamples", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "numSamples", ";", "i"...
// PopulatedChunk creates a chunk populated with samples every second starting at minTime
[ "PopulatedChunk", "creates", "a", "chunk", "populated", "with", "samples", "every", "second", "starting", "at", "minTime" ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/tsdbutil/chunks.go#L47-L53
train
prometheus/tsdb
encoding/encoding.go
PutHash
func (e *Encbuf) PutHash(h hash.Hash) { h.Reset() _, err := h.Write(e.B) if err != nil { panic(err) // The CRC32 implementation does not error } e.B = h.Sum(e.B) }
go
func (e *Encbuf) PutHash(h hash.Hash) { h.Reset() _, err := h.Write(e.B) if err != nil { panic(err) // The CRC32 implementation does not error } e.B = h.Sum(e.B) }
[ "func", "(", "e", "*", "Encbuf", ")", "PutHash", "(", "h", "hash", ".", "Hash", ")", "{", "h", ".", "Reset", "(", ")", "\n", "_", ",", "err", ":=", "h", ".", "Write", "(", "e", ".", "B", ")", "\n", "if", "err", "!=", "nil", "{", "panic", ...
// PutHash appends a hash over the buffers current contents to the buffer.
[ "PutHash", "appends", "a", "hash", "over", "the", "buffers", "current", "contents", "to", "the", "buffer", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/encoding/encoding.go#L76-L83
train
prometheus/tsdb
encoding/encoding.go
NewDecbufAt
func NewDecbufAt(bs ByteSlice, off int, castagnoliTable *crc32.Table) Decbuf { if bs.Len() < off+4 { return Decbuf{E: ErrInvalidSize} } b := bs.Range(off, off+4) l := int(binary.BigEndian.Uint32(b)) if bs.Len() < off+4+l+4 { return Decbuf{E: ErrInvalidSize} } // Load bytes holding the contents plus a CRC32...
go
func NewDecbufAt(bs ByteSlice, off int, castagnoliTable *crc32.Table) Decbuf { if bs.Len() < off+4 { return Decbuf{E: ErrInvalidSize} } b := bs.Range(off, off+4) l := int(binary.BigEndian.Uint32(b)) if bs.Len() < off+4+l+4 { return Decbuf{E: ErrInvalidSize} } // Load bytes holding the contents plus a CRC32...
[ "func", "NewDecbufAt", "(", "bs", "ByteSlice", ",", "off", "int", ",", "castagnoliTable", "*", "crc32", ".", "Table", ")", "Decbuf", "{", "if", "bs", ".", "Len", "(", ")", "<", "off", "+", "4", "{", "return", "Decbuf", "{", "E", ":", "ErrInvalidSize"...
// NewDecbufAt returns a new decoding buffer. It expects the first 4 bytes // after offset to hold the big endian encoded content length, followed by the contents and the expected // checksum.
[ "NewDecbufAt", "returns", "a", "new", "decoding", "buffer", ".", "It", "expects", "the", "first", "4", "bytes", "after", "offset", "to", "hold", "the", "big", "endian", "encoded", "content", "length", "followed", "by", "the", "contents", "and", "the", "expec...
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/encoding/encoding.go#L97-L116
train
prometheus/tsdb
encoding/encoding.go
NewDecbufUvarintAt
func NewDecbufUvarintAt(bs ByteSlice, off int, castagnoliTable *crc32.Table) Decbuf { // We never have to access this method at the far end of the byte slice. Thus just checking // against the MaxVarintLen32 is sufficient. if bs.Len() < off+binary.MaxVarintLen32 { return Decbuf{E: ErrInvalidSize} } b := bs.Range...
go
func NewDecbufUvarintAt(bs ByteSlice, off int, castagnoliTable *crc32.Table) Decbuf { // We never have to access this method at the far end of the byte slice. Thus just checking // against the MaxVarintLen32 is sufficient. if bs.Len() < off+binary.MaxVarintLen32 { return Decbuf{E: ErrInvalidSize} } b := bs.Range...
[ "func", "NewDecbufUvarintAt", "(", "bs", "ByteSlice", ",", "off", "int", ",", "castagnoliTable", "*", "crc32", ".", "Table", ")", "Decbuf", "{", "// We never have to access this method at the far end of the byte slice. Thus just checking", "// against the MaxVarintLen32 is suffic...
// NewDecbufUvarintAt returns a new decoding buffer. It expects the first bytes // after offset to hold the uvarint-encoded buffers length, followed by the contents and the expected // checksum.
[ "NewDecbufUvarintAt", "returns", "a", "new", "decoding", "buffer", ".", "It", "expects", "the", "first", "bytes", "after", "offset", "to", "hold", "the", "uvarint", "-", "encoded", "buffers", "length", "followed", "by", "the", "contents", "and", "the", "expect...
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/encoding/encoding.go#L121-L146
train
prometheus/tsdb
encoding/encoding.go
Crc32
func (d *Decbuf) Crc32(castagnoliTable *crc32.Table) uint32 { return crc32.Checksum(d.B, castagnoliTable) }
go
func (d *Decbuf) Crc32(castagnoliTable *crc32.Table) uint32 { return crc32.Checksum(d.B, castagnoliTable) }
[ "func", "(", "d", "*", "Decbuf", ")", "Crc32", "(", "castagnoliTable", "*", "crc32", ".", "Table", ")", "uint32", "{", "return", "crc32", ".", "Checksum", "(", "d", ".", "B", ",", "castagnoliTable", ")", "\n", "}" ]
// Crc32 returns a CRC32 checksum over the remaining bytes.
[ "Crc32", "returns", "a", "CRC32", "checksum", "over", "the", "remaining", "bytes", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/encoding/encoding.go#L153-L155
train
prometheus/tsdb
block.go
OpenBlock
func OpenBlock(logger log.Logger, dir string, pool chunkenc.Pool) (pb *Block, err error) { if logger == nil { logger = log.NewNopLogger() } var closers []io.Closer defer func() { if err != nil { var merr tsdb_errors.MultiError merr.Add(err) merr.Add(closeAll(closers)) err = merr.Err() } }() meta...
go
func OpenBlock(logger log.Logger, dir string, pool chunkenc.Pool) (pb *Block, err error) { if logger == nil { logger = log.NewNopLogger() } var closers []io.Closer defer func() { if err != nil { var merr tsdb_errors.MultiError merr.Add(err) merr.Add(closeAll(closers)) err = merr.Err() } }() meta...
[ "func", "OpenBlock", "(", "logger", "log", ".", "Logger", ",", "dir", "string", ",", "pool", "chunkenc", ".", "Pool", ")", "(", "pb", "*", "Block", ",", "err", "error", ")", "{", "if", "logger", "==", "nil", "{", "logger", "=", "log", ".", "NewNopL...
// OpenBlock opens the block in the directory. It can be passed a chunk pool, which is used // to instantiate chunk structs.
[ "OpenBlock", "opens", "the", "block", "in", "the", "directory", ".", "It", "can", "be", "passed", "a", "chunk", "pool", "which", "is", "used", "to", "instantiate", "chunk", "structs", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/block.go#L292-L347
train
prometheus/tsdb
block.go
Close
func (pb *Block) Close() error { pb.mtx.Lock() pb.closing = true pb.mtx.Unlock() pb.pendingReaders.Wait() var merr tsdb_errors.MultiError merr.Add(pb.chunkr.Close()) merr.Add(pb.indexr.Close()) merr.Add(pb.tombstones.Close()) return merr.Err() }
go
func (pb *Block) Close() error { pb.mtx.Lock() pb.closing = true pb.mtx.Unlock() pb.pendingReaders.Wait() var merr tsdb_errors.MultiError merr.Add(pb.chunkr.Close()) merr.Add(pb.indexr.Close()) merr.Add(pb.tombstones.Close()) return merr.Err() }
[ "func", "(", "pb", "*", "Block", ")", "Close", "(", ")", "error", "{", "pb", ".", "mtx", ".", "Lock", "(", ")", "\n", "pb", ".", "closing", "=", "true", "\n", "pb", ".", "mtx", ".", "Unlock", "(", ")", "\n\n", "pb", ".", "pendingReaders", ".", ...
// Close closes the on-disk block. It blocks as long as there are readers reading from the block.
[ "Close", "closes", "the", "on", "-", "disk", "block", ".", "It", "blocks", "as", "long", "as", "there", "are", "readers", "reading", "from", "the", "block", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/block.go#L360-L374
train
prometheus/tsdb
block.go
Index
func (pb *Block) Index() (IndexReader, error) { if err := pb.startRead(); err != nil { return nil, err } return blockIndexReader{ir: pb.indexr, b: pb}, nil }
go
func (pb *Block) Index() (IndexReader, error) { if err := pb.startRead(); err != nil { return nil, err } return blockIndexReader{ir: pb.indexr, b: pb}, nil }
[ "func", "(", "pb", "*", "Block", ")", "Index", "(", ")", "(", "IndexReader", ",", "error", ")", "{", "if", "err", ":=", "pb", ".", "startRead", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "blo...
// Index returns a new IndexReader against the block data.
[ "Index", "returns", "a", "new", "IndexReader", "against", "the", "block", "data", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/block.go#L410-L415
train
prometheus/tsdb
block.go
Chunks
func (pb *Block) Chunks() (ChunkReader, error) { if err := pb.startRead(); err != nil { return nil, err } return blockChunkReader{ChunkReader: pb.chunkr, b: pb}, nil }
go
func (pb *Block) Chunks() (ChunkReader, error) { if err := pb.startRead(); err != nil { return nil, err } return blockChunkReader{ChunkReader: pb.chunkr, b: pb}, nil }
[ "func", "(", "pb", "*", "Block", ")", "Chunks", "(", ")", "(", "ChunkReader", ",", "error", ")", "{", "if", "err", ":=", "pb", ".", "startRead", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "bl...
// Chunks returns a new ChunkReader against the block data.
[ "Chunks", "returns", "a", "new", "ChunkReader", "against", "the", "block", "data", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/block.go#L418-L423
train
prometheus/tsdb
block.go
Tombstones
func (pb *Block) Tombstones() (TombstoneReader, error) { if err := pb.startRead(); err != nil { return nil, err } return blockTombstoneReader{TombstoneReader: pb.tombstones, b: pb}, nil }
go
func (pb *Block) Tombstones() (TombstoneReader, error) { if err := pb.startRead(); err != nil { return nil, err } return blockTombstoneReader{TombstoneReader: pb.tombstones, b: pb}, nil }
[ "func", "(", "pb", "*", "Block", ")", "Tombstones", "(", ")", "(", "TombstoneReader", ",", "error", ")", "{", "if", "err", ":=", "pb", ".", "startRead", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return...
// Tombstones returns a new TombstoneReader against the block data.
[ "Tombstones", "returns", "a", "new", "TombstoneReader", "against", "the", "block", "data", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/block.go#L426-L431
train
prometheus/tsdb
block.go
Delete
func (pb *Block) Delete(mint, maxt int64, ms ...labels.Matcher) error { pb.mtx.Lock() defer pb.mtx.Unlock() if pb.closing { return ErrClosing } p, err := PostingsForMatchers(pb.indexr, ms...) if err != nil { return errors.Wrap(err, "select series") } ir := pb.indexr // Choose only valid postings which ...
go
func (pb *Block) Delete(mint, maxt int64, ms ...labels.Matcher) error { pb.mtx.Lock() defer pb.mtx.Unlock() if pb.closing { return ErrClosing } p, err := PostingsForMatchers(pb.indexr, ms...) if err != nil { return errors.Wrap(err, "select series") } ir := pb.indexr // Choose only valid postings which ...
[ "func", "(", "pb", "*", "Block", ")", "Delete", "(", "mint", ",", "maxt", "int64", ",", "ms", "...", "labels", ".", "Matcher", ")", "error", "{", "pb", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "pb", ".", "mtx", ".", "Unlock", "(", ")",...
// Delete matching series between mint and maxt in the block.
[ "Delete", "matching", "series", "between", "mint", "and", "maxt", "in", "the", "block", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/block.go#L510-L568
train
prometheus/tsdb
block.go
Snapshot
func (pb *Block) Snapshot(dir string) error { blockDir := filepath.Join(dir, pb.meta.ULID.String()) if err := os.MkdirAll(blockDir, 0777); err != nil { return errors.Wrap(err, "create snapshot block dir") } chunksDir := chunkDir(blockDir) if err := os.MkdirAll(chunksDir, 0777); err != nil { return errors.Wrap...
go
func (pb *Block) Snapshot(dir string) error { blockDir := filepath.Join(dir, pb.meta.ULID.String()) if err := os.MkdirAll(blockDir, 0777); err != nil { return errors.Wrap(err, "create snapshot block dir") } chunksDir := chunkDir(blockDir) if err := os.MkdirAll(chunksDir, 0777); err != nil { return errors.Wrap...
[ "func", "(", "pb", "*", "Block", ")", "Snapshot", "(", "dir", "string", ")", "error", "{", "blockDir", ":=", "filepath", ".", "Join", "(", "dir", ",", "pb", ".", "meta", ".", "ULID", ".", "String", "(", ")", ")", "\n", "if", "err", ":=", "os", ...
// Snapshot creates snapshot of the block into dir.
[ "Snapshot", "creates", "snapshot", "of", "the", "block", "into", "dir", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/block.go#L595-L632
train
prometheus/tsdb
wal.go
OpenSegmentWAL
func OpenSegmentWAL(dir string, logger log.Logger, flushInterval time.Duration, r prometheus.Registerer) (*SegmentWAL, error) { if err := os.MkdirAll(dir, 0777); err != nil { return nil, err } df, err := fileutil.OpenDir(dir) if err != nil { return nil, err } if logger == nil { logger = log.NewNopLogger() ...
go
func OpenSegmentWAL(dir string, logger log.Logger, flushInterval time.Duration, r prometheus.Registerer) (*SegmentWAL, error) { if err := os.MkdirAll(dir, 0777); err != nil { return nil, err } df, err := fileutil.OpenDir(dir) if err != nil { return nil, err } if logger == nil { logger = log.NewNopLogger() ...
[ "func", "OpenSegmentWAL", "(", "dir", "string", ",", "logger", "log", ".", "Logger", ",", "flushInterval", "time", ".", "Duration", ",", "r", "prometheus", ".", "Registerer", ")", "(", "*", "SegmentWAL", ",", "error", ")", "{", "if", "err", ":=", "os", ...
// OpenSegmentWAL opens or creates a write ahead log in the given directory. // The WAL must be read completely before new data is written.
[ "OpenSegmentWAL", "opens", "or", "creates", "a", "write", "ahead", "log", "in", "the", "given", "directory", ".", "The", "WAL", "must", "be", "read", "completely", "before", "new", "data", "is", "written", "." ]
3ccab17f5dc60de1bea3e5cfc807cb63a287078f
https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L184-L232
train