client

package
v0.75.3 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 18 Imported by: 6

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
}

Client is a fake intake client

func NewClient

func NewClient(fakeIntakeURL string, opts ...Option) *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) FilterCheckRuns added in v0.56.0

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

FilterCheckRuns fetches fakeintake on `/api/v1/check_run` endpoint and returns metrics matching `name` and any MatchOpt(#MatchOpt) options

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) FilterEvents added in v0.64.0

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

FilterEvents fetches fakeintake on `/intake/` endpoint and returns events 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) GetAllProcessPayloadAPIKeys added in v0.67.0

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

GetAllProcessPayloadAPIKeys fetches fakeintake on `/api/v1/collector` endpoint and returns a list of unique API keys of the received process payloads

func (*Client) GetCheckRun

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

GetCheckRun 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) GetEventSources added in v0.64.0

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

GetEventSources fetches fakeintake on `/intake/` endpoint and returns all received event sources

func (*Client) GetLastAPIKey added in v0.64.0

func (c *Client) GetLastAPIKey() (string, error)

GetLastAPIKey returns the last apiKey sent with a payload to the intake

func (*Client) GetLastProcessPayloadAPIKey added in v0.65.0

func (c *Client) GetLastProcessPayloadAPIKey() (string, error)

GetLastProcessPayloadAPIKey fetches fakeintake on `/api/v1/collector` endpoint and returns the API key of the last received process payload

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) GetLatestHostInfos added in v0.72.0

func (c *Client) GetLatestHostInfos() ([]*aggregator.Host, error)

GetLatestHostInfos returns the latest host information received by the fake intake

func (*Client) GetLatestNetpathEvents added in v0.65.0

func (c *Client) GetLatestNetpathEvents() ([]*aggregator.Netpath, error)

GetLatestNetpathEvents returns the latest netpath events by destination

func (*Client) GetLogServiceNames

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

GetLogServiceNames 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) GetNCMPayloads added in v0.74.0

func (c *Client) GetNCMPayloads() ([]*aggregator.NCMPayload, error)

GetNCMPayloads fetches fakeintake on `/api/v2/ndmconfig` endpoint and returns all received NCM payloads

func (*Client) GetNDMFlows added in v0.54.0

func (c *Client) GetNDMFlows() ([]*aggregator.NDMFlow, error)

GetNDMFlows fetches fakeintake on `/api/v2/ndmflows` endpoint and returns all received ndmflow payloads

func (*Client) GetNDMPayloads added in v0.66.0

func (c *Client) GetNDMPayloads() ([]*aggregator.NDMPayload, error)

GetNDMPayloads fetches fakeintake on `/api/v2/ndm` endpoint and returns all received NDM payloads

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) GetOrchestratorResourcesPayloadAPIKeys added in v0.66.0

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

GetOrchestratorResourcesPayloadAPIKeys fetches fakeintake on `/api/v2/orch` endpoint and returns the API keys of the received orchestrator 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 WithAlertType added in v0.64.0

func WithAlertType(alertType event.AlertType) MatchOpt[*aggregator.Event]

WithAlertType filters events by `alertType`

func WithMatchingTags added in v0.53.0

func WithMatchingTags[P aggregator.PayloadItem](tags []*regexp.Regexp) MatchOpt[P]

WithMatchingTags filters by `tags` where tags is an array of regex strings

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]

WithMetricValueHigherThan 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 Option added in v0.55.0

type Option func(*Client)

Option is a configuration option for the client

func WithGetBackoffDelay added in v0.66.0

func WithGetBackoffDelay(delay time.Duration) Option

WithGetBackoffDelay sets the delay between two retries in get

func WithGetBackoffRetries added in v0.66.0

func WithGetBackoffRetries(retries uint64) Option

WithGetBackoffRetries sets the number of retries in get

func WithoutStrictFakeintakeIDCheck added in v0.55.0

func WithoutStrictFakeintakeIDCheck() Option

WithoutStrictFakeintakeIDCheck disables strict fakeintake ID check

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