client

package
v0.48.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Overview

Package client implements helpers APIs to interact with a fakeintake server from go tests Helpers fetch fakeintake endpoints, unpackage payloads and store parsed data in aggregators

Using fakeintake in go tests

In this example we assert that a fakeintake running at localhost on port 8080 received "system.uptime" metrics with tags "app:system" and values in range 4226000 < value < 4226050.

client := NewClient("http://localhost:8080")
metrics, err := client.FilterMetrics("system.uptime",
		WithTags[*aggregator.MetricSeries]([]string{"app:system"}),
		WithMetricValueInRange(4226000, 4226050))
assert.NoError(t, err)
assert.NotEmpty(t, metrics)

In this example we assert that a fakeintake running at localhost on port 8080 received logs by service "system" with tags "app:system" and content containing "totoro"

client := NewClient("http://localhost:8080")
logs, err := client.FilterLogs("system",
		WithTags[*aggregator.Log]([]string{"totoro"}),
assert.NoError(t, err)
assert.NotEmpty(t, logs)

In this example we assert that a fakeintake running at localhost on port 8080 received check runs by name "totoro" with tags "status:ok"

client := NewClient("http://localhost:8080")
logs, err := client.GetCheckRun("totoro")
assert.NoError(t, err)
assert.NotEmpty(t, logs)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(fakeIntakeURL string) *Client

NewClient creates a new fake intake client fakeIntakeURL: the host of the fake Datadog intake server

func (*Client) FilterLogs

func (c *Client) FilterLogs(service string, options ...MatchOpt[*aggregator.Log]) ([]*aggregator.Log, error)

FilterLogs fetches fakeintake on `/api/v2/logs` endpoint, unpackage payloads and returns logs matching `service` and any MatchOpt(#MatchOpt) options

func (*Client) FilterMetrics

func (c *Client) FilterMetrics(name string, options ...MatchOpt[*aggregator.MetricSeries]) ([]*aggregator.MetricSeries, error)

FilterMetrics fetches fakeintake on `/api/v2/series` endpoint and returns metrics matching `name` and any MatchOpt(#MatchOpt) options

func (*Client) FlushServerAndResetAggregators

func (c *Client) FlushServerAndResetAggregators() error

FlushServerAndResetAggregators sends a request to delete any stored payload and resets client's aggregators Call this in between tests to reset the fakeintake status on both client and server side

func (*Client) GetCheckRun

func (c *Client) GetCheckRun(name string) ([]*aggregator.CheckRun, error)

FilterLogs fetches fakeintake on `/api/v1/check_run` endpoint, unpackage payloads and returns checks matching `name`

func (*Client) GetCheckRunNames

func (c *Client) GetCheckRunNames() ([]string, error)

GetCheckRunNames fetches fakeintake on `/api/v1/check_run` endpoint and returns all received check run names

func (*Client) GetLogServiceNames

func (c *Client) GetLogServiceNames() ([]string, error)

GetLogNames fetches fakeintake on `/api/v2/logs` endpoint and returns all received log service names

func (*Client) GetMetricNames

func (c *Client) GetMetricNames() ([]string, error)

GetMetricNames fetches fakeintake on `/api/v2/series` endpoint and returns all received metric names

func (*Client) GetServerHealth

func (c *Client) GetServerHealth() error

GetServerHealth fetches fakeintake health status and returns an error if fakeintake is unhealthy

type MatchOpt

type MatchOpt[P aggregator.PayloadItem] func(payload P) (bool, error)

A MatchOpt to filter fakeintake payloads

func WithMessageContaining

func WithMessageContaining(content string) MatchOpt[*aggregator.Log]

WithMessageContaining filters logs by message containing `content`

func WithMessageMatching

func WithMessageMatching(pattern string) MatchOpt[*aggregator.Log]

WithMessageMatching filters logs by message matching regexp(https://pkg.go.dev/regexp) `pattern`

func WithMetricValueHigherThan

func WithMetricValueHigherThan(minValue float64) MatchOpt[*aggregator.MetricSeries]

WithMetricValueLowerThan filters metrics with values higher than `minValue`

func WithMetricValueInRange

func WithMetricValueInRange(minValue float64, maxValue float64) MatchOpt[*aggregator.MetricSeries]

WithMetricValueInRange filters metrics with values in range `minValue < value < maxValue`

func WithMetricValueLowerThan

func WithMetricValueLowerThan(maxValue float64) MatchOpt[*aggregator.MetricSeries]

WithMetricValueLowerThan filters metrics with values lower than `maxValue`

func WithTags

func WithTags[P aggregator.PayloadItem](tags []string) MatchOpt[P]

WithTags filters by `tags`

Jump to

Keyboard shortcuts

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