client

package
v0.52.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 14 Imported by: 2

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

View Source
var ErrNoFlareAvailable = errors.New("no flare available")

ErrNoFlareAvailable is returned when no flare is available

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) ConfigureOverride added in v0.51.0

func (c *Client) ConfigureOverride(override api.ResponseOverride) error

ConfigureOverride sets a response override on the fakeintake server

func (*Client) FilterContainerImages added in v0.51.0

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

FilterContainerImages fetches fakeintake on `/api/v2/contimage` endpoint and returns container images matching `name` and any MatchOpt(#MatchOpt) options

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) FilterSBOMs added in v0.51.0

func (c *Client) FilterSBOMs(id string, options ...MatchOpt[*aggregator.SBOMPayload]) ([]*aggregator.SBOMPayload, error)

FilterSBOMs fetches fakeintake on `/api/v2/sbom` endpoint and returns SBOMs matching `id` 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) GetAPMStats added in v0.52.0

func (c *Client) GetAPMStats() ([]*aggregator.APMStatsPayload, error)

GetAPMStats fetches fakeintake on /api/v0.2/stats endpoint and returns all received apm stats payloads

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) GetConnections added in v0.49.0

func (c *Client) GetConnections() (conns *aggregator.ConnectionsAggregator, err error)

GetConnections fetches fakeintake on `/api/v1/connections` endpoint and returns all received connections

func (*Client) GetConnectionsNames added in v0.49.0

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

GetConnectionsNames fetches fakeintake on `/api/v1/connections` endpoint and returns all received connections from hostname+network_id

func (*Client) GetContainerImageNames added in v0.51.0

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

GetContainerImageNames fetches fakeintake on `/api/v2/contimage` endpoint and returns all received container image names

func (*Client) GetContainerLifecycleEvents added in v0.51.0

func (c *Client) GetContainerLifecycleEvents() ([]*aggregator.ContainerLifecyclePayload, error)

GetContainerLifecycleEvents fetches fakeintake on `/api/v2/contlcycle` endpoint and returns all received container lifecycle payloads

func (*Client) GetContainers added in v0.50.0

func (c *Client) GetContainers() ([]*aggregator.ContainerPayload, error)

GetContainers fetches fakeintake on `/api/v1/container` endpoint and returns all received container payloads

func (*Client) GetLatestFlare added in v0.49.0

func (c *Client) GetLatestFlare() (flare.Flare, error)

GetLatestFlare queries the Fake Intake to fetch flares that were sent by a Datadog Agent and returns the latest flare as a Flare struct TODO: handle multiple flares / flush when returning latest flare

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) GetMetadata added in v0.52.0

func (c *Client) GetMetadata() ([]*aggregator.MetadataPayload, error)

GetMetadata fetches fakeintake on `/api/v1/metadata` endpoint and returns a list of metadata payloads

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) GetOrchestratorManifests added in v0.52.0

func (c *Client) GetOrchestratorManifests() ([]*aggregator.OrchestratorManifestPayload, error)

GetOrchestratorManifests fetches fakeintake on `/api/v2/orchmanif` endpoint and returns all received process payloads

func (*Client) GetOrchestratorResources added in v0.52.0

func (c *Client) GetOrchestratorResources(filter *PayloadFilter) ([]*aggregator.OrchestratorPayload, error)

GetOrchestratorResources fetches fakeintake on `/api/v2/orch` endpoint and returns all received process payloads

func (*Client) GetProcessDiscoveries added in v0.50.0

func (c *Client) GetProcessDiscoveries() ([]*aggregator.ProcessDiscoveryPayload, error)

GetProcessDiscoveries fetches fakeintake on `/api/v1/discovery` endpoint and returns all received process discovery payloads

func (*Client) GetProcesses added in v0.50.0

func (c *Client) GetProcesses() ([]*aggregator.ProcessPayload, error)

GetProcesses fetches fakeintake on `/api/v1/collector` endpoint and returns all received process payloads

func (*Client) GetSBOMIDs added in v0.51.0

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

GetSBOMIDs fetches fakeintake on `/api/v2/sbom` endpoint and returns all received SBOM IDs

func (*Client) GetServerHealth

func (c *Client) GetServerHealth() error

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

func (*Client) GetTraces added in v0.52.0

func (c *Client) GetTraces() ([]*aggregator.TracePayload, error)

GetTraces fetches fakeintake on /api/v0.2/traces endpoint and returns all received trace payloads

func (*Client) RouteStats added in v0.50.0

func (c *Client) RouteStats() (map[string]int, error)

RouteStats queries the routestats fakeintake endpoint to get statistics about each route. It only returns statistics about endpoint which store some payloads.

func (*Client) URL added in v0.50.0

func (c *Client) URL() string

URL returns the client's URL

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.golang.ir/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`

type PayloadFilter added in v0.52.0

type PayloadFilter struct {
	Name         string
	ResourceType agentmodel.MessageType
}

PayloadFilter is used to filter payloads by name and resource type

Directories

Path Synopsis
Package flare implements helpers to parse a Datadog Agent Flare and fetch its content
Package flare implements helpers to parse a Datadog Agent Flare and fetch its content

Jump to

Keyboard shortcuts

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