loki

package
v0.4.20 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResultTypeStream = "streams"
	ResultTypeScalar = "scalar"
	ResultTypeVector = "vector"
	ResultTypeMatrix = "matrix"
)

ResultType values

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction string
var (
	FORWARD  Direction = "FORWARD"
	BACKWARD Direction = "BACKWARD"
)

func (Direction) String

func (d Direction) String() string

type Entry

type Entry struct {
	Timestamp time.Time
	Line      string
}

Entry represents a log entry. It includes a log message and the time it occurred at.

func GetEntriesFromStreams

func GetEntriesFromStreams(streams Streams) []Entry

func (*Entry) MarshalJSON

func (e *Entry) MarshalJSON() ([]byte, error)

func (*Entry) UnmarshalJSON

func (e *Entry) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type LabelSet

type LabelSet map[string]string

LabelSet is a key/value pair mapping of labels

func (LabelSet) Map

func (l LabelSet) Map() map[string]string

Map coerces LabelSet into a map[string]string. This is useful for working with adapter types.

func (LabelSet) String

func (l LabelSet) String() string

String implements the Stringer interface. It returns a formatted/sorted set of label key/value pairs.

type LokiClient

type LokiClient struct {
	// contains filtered or unexported fields
}

func New

func New(baseUrl string, client LokiHttpClient) *LokiClient

func (*LokiClient) QueryRange

func (c *LokiClient) QueryRange(
	ctx context.Context,
	request *QueryRangeRequest,
	logger *slog.Logger,
) (*QueryResponse, error)

type LokiHttpClient

type LokiHttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type MockLokiHttpClient

type MockLokiHttpClient struct {
	mock.Mock
}

MockLokiHttpClient is an autogenerated mock type for the LokiHttpClient type

func NewMockLokiHttpClient

func NewMockLokiHttpClient(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockLokiHttpClient

NewMockLokiHttpClient creates a new instance of MockLokiHttpClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockLokiHttpClient) Do

func (_m *MockLokiHttpClient) Do(req *http.Request) (*http.Response, error)

Do provides a mock function with given fields: req

func (*MockLokiHttpClient) EXPECT

type MockLokiHttpClient_Do_Call

type MockLokiHttpClient_Do_Call struct {
	*mock.Call
}

MockLokiHttpClient_Do_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Do'

func (*MockLokiHttpClient_Do_Call) Return

func (*MockLokiHttpClient_Do_Call) Run

func (*MockLokiHttpClient_Do_Call) RunAndReturn

type MockLokiHttpClient_Expecter

type MockLokiHttpClient_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockLokiHttpClient_Expecter) Do

Do is a helper method to define mock.On call

  • req *http.Request

type QueryRangeRequest

type QueryRangeRequest struct {
	Query     string
	Limit     *int64
	Start     *time.Time
	End       *time.Time
	Direction *Direction
}

type QueryResponse

type QueryResponse struct {
	Status string            `json:"status"`
	Data   QueryResponseData `json:"data"`
}

Define a struct that matches the structure of the JSON response you expect from Loki. This is a simplified example; adjust according to the actual response structure you need. QueryResponse represents the http json response to a label query

type QueryResponseData

type QueryResponseData struct {
	ResultType ResultType  `json:"resultType"`
	Result     ResultValue `json:"result"`
}

QueryResponseData represents the http json response to a label query

func (*QueryResponseData) UnmarshalJSON

func (q *QueryResponseData) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type ResultType

type ResultType string

ResultType holds the type of the result

type ResultValue

type ResultValue interface {
	Type() ResultType
}

ResultValue interface mimics the promql.Value interface

type Stream

type Stream struct {
	Labels  LabelSet `json:"stream"`
	Entries []Entry  `json:"values"`
}

Stream represents a log stream. It includes a set of log entries and their labels.

type Streams

type Streams []Stream

Streams is a slice of Stream

func GetStreamsFromResponseData

func GetStreamsFromResponseData(data *QueryResponseData) (Streams, error)

func (Streams) ToProto

func (s Streams) ToProto() []Stream

func (Streams) Type

func (Streams) Type() ResultType

Jump to

Keyboard shortcuts

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