common

package
v1.50.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2020 License: Apache-2.0 Imports: 12 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExtraLabels added in v1.40.1

func GetExtraLabels(req *http.Request) ([]prompbmarshal.Label, error)

GetExtraLabels extracts name:value labels from `extra_label=name=value` query args from req.

func GetGzipReader

func GetGzipReader(r io.Reader) (*gzip.Reader, error)

GetGzipReader returns new gzip reader from the pool.

Return back the gzip reader when it no longer needed with PutGzipReader.

func GetTimestamp added in v1.41.0

func GetTimestamp(req *http.Request) (int64, error)

GetTimestamp extracts unix timestamp in milliseconds from `timestamp` query arg.

It returns 0 if there is no `timestamp` query arg.

func PutGzipReader

func PutGzipReader(zr *gzip.Reader)

PutGzipReader returns back gzip reader obtained via GetGzipReader.

func ReadLinesBlock

func ReadLinesBlock(r io.Reader, dstBuf, tailBuf []byte) ([]byte, []byte, error)

ReadLinesBlock reads a block of lines delimited by '\n' from tailBuf and r into dstBuf.

Trailing chars after the last newline are put into tailBuf.

Returns (dstBuf, tailBuf).

It is expected that read timeout on r exceeds 1 second.

func ReadLinesBlockExt

func ReadLinesBlockExt(r io.Reader, dstBuf, tailBuf []byte, maxLineLen int) ([]byte, []byte, error)

ReadLinesBlockExt reads a block of lines delimited by '\n' from tailBuf and r into dstBuf.

Trailing chars after the last newline are put into tailBuf.

Returns (dstBuf, tailBuf).

maxLineLen limits the maximum length of a single line.

It is expected that read timeout on r exceeds 1 second.

func ScheduleUnmarshalWork added in v1.42.0

func ScheduleUnmarshalWork(uw UnmarshalWork)

ScheduleUnmarshalWork schedules uw to run in the worker pool.

It is expected that StartUnmarshalWorkers is already called.

func StartUnmarshalWorkers added in v1.42.0

func StartUnmarshalWorkers()

StartUnmarshalWorkers starts unmarshal workers.

func StopUnmarshalWorkers added in v1.42.0

func StopUnmarshalWorkers()

StopUnmarshalWorkers stops unmarshal workers.

No more calles to ScheduleUnmarshalWork are allowed after callsing stopUnmarshalWorkers

Types

type UnmarshalWork added in v1.42.0

type UnmarshalWork interface {
	// Unmarshal must implement CPU-bound unmarshal work.
	Unmarshal()
}

UnmarshalWork is a unit of unmarshal work.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL