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 ¶
- Variables
- type Client
- func (c *Client) ConfigureOverride(override api.ResponseOverride) error
- func (c *Client) FilterCheckRuns(name string, options ...MatchOpt[*aggregator.CheckRun]) ([]*aggregator.CheckRun, error)
- func (c *Client) FilterContainerImages(name string, options ...MatchOpt[*aggregator.ContainerImagePayload]) ([]*aggregator.ContainerImagePayload, error)
- func (c *Client) FilterLogs(service string, options ...MatchOpt[*aggregator.Log]) ([]*aggregator.Log, error)
- func (c *Client) FilterMetrics(name string, options ...MatchOpt[*aggregator.MetricSeries]) ([]*aggregator.MetricSeries, error)
- func (c *Client) FilterSBOMs(id string, options ...MatchOpt[*aggregator.SBOMPayload]) ([]*aggregator.SBOMPayload, error)
- func (c *Client) FlushServerAndResetAggregators() error
- func (c *Client) GetAPMStats() ([]*aggregator.APMStatsPayload, error)
- func (c *Client) GetCheckRun(name string) ([]*aggregator.CheckRun, error)
- func (c *Client) GetCheckRunNames() ([]string, error)
- func (c *Client) GetConnections() (conns *aggregator.ConnectionsAggregator, err error)
- func (c *Client) GetConnectionsNames() ([]string, error)
- func (c *Client) GetContainerImageNames() ([]string, error)
- func (c *Client) GetContainerLifecycleEvents() ([]*aggregator.ContainerLifecyclePayload, error)
- func (c *Client) GetContainers() ([]*aggregator.ContainerPayload, error)
- func (c *Client) GetLatestFlare() (flare.Flare, error)
- func (c *Client) GetLogServiceNames() ([]string, error)
- func (c *Client) GetMetadata() ([]*aggregator.MetadataPayload, error)
- func (c *Client) GetMetricNames() ([]string, error)
- func (c *Client) GetNDMFlows() ([]*aggregator.NDMFlow, error)
- func (c *Client) GetOrchestratorManifests() ([]*aggregator.OrchestratorManifestPayload, error)
- func (c *Client) GetOrchestratorResources(filter *PayloadFilter) ([]*aggregator.OrchestratorPayload, error)
- func (c *Client) GetProcessDiscoveries() ([]*aggregator.ProcessDiscoveryPayload, error)
- func (c *Client) GetProcesses() ([]*aggregator.ProcessPayload, error)
- func (c *Client) GetSBOMIDs() ([]string, error)
- func (c *Client) GetServerHealth() error
- func (c *Client) GetTraces() ([]*aggregator.TracePayload, error)
- func (c *Client) RouteStats() (map[string]int, error)
- func (c *Client) URL() string
- type MatchOpt
- func WithMatchingTags[P aggregator.PayloadItem](tags []*regexp.Regexp) MatchOpt[P]
- func WithMessageContaining(content string) MatchOpt[*aggregator.Log]
- func WithMessageMatching(pattern string) MatchOpt[*aggregator.Log]
- func WithMetricValueHigherThan(minValue float64) MatchOpt[*aggregator.MetricSeries]
- func WithMetricValueInRange(minValue float64, maxValue float64) MatchOpt[*aggregator.MetricSeries]
- func WithMetricValueLowerThan(maxValue float64) MatchOpt[*aggregator.MetricSeries]
- func WithTags[P aggregator.PayloadItem](tags []string) MatchOpt[P]
- type Option
- type PayloadFilter
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) 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 ¶
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)
GetCheckRun fetches fakeintake on `/api/v1/check_run` endpoint, unpackage payloads and returns checks matching `name`
func (*Client) GetCheckRunNames ¶
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
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
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
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 ¶
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 ¶
GetMetricNames fetches fakeintake on `/api/v2/series` endpoint and returns all received metric names
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) 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
GetSBOMIDs fetches fakeintake on `/api/v2/sbom` endpoint and returns all received SBOM IDs
func (*Client) GetServerHealth ¶
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
RouteStats queries the routestats fakeintake endpoint to get statistics about each route. It only returns statistics about endpoint which store some payloads.
type MatchOpt ¶
type MatchOpt[P aggregator.PayloadItem] func(payload P) (bool, error)
A MatchOpt to filter fakeintake payloads
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 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