Documentation
¶
Overview ¶
Package testutil includes OTLP-related test utilities.
Index ¶
- Constants
- Variables
- func GenerateLogsNoLogRecords() plog.Logs
- func GenerateLogsOneEmptyLogRecord() plog.Logs
- func GenerateLogsOneEmptyResourceLogs() plog.Logs
- func GenerateLogsOneLogRecord() plog.Logs
- func GenerateLogsOneLogRecordNoResource() plog.Logs
- func GenerateLogsTwoLogRecordsSameResource() plog.Logs
- func LoadConfig(t *testing.T, path string) (pkgConfigModel.Reader, error)
- func NewAttributeMap(mp map[string]string) pcommon.Map
- func NewGaugeMetrics(tgs []TestGauge) pmetric.Metrics
- func OTLPConfigFromPorts(bindHost string, gRPCPort uint, httpPort uint) map[string]interface{}
- func ValidateAPIKeyEndpointInvalid() (string, http.HandlerFunc)
- type DataPoint
- type DatadogLogsServer
- type DatadogServer
- type HTTPRequestRecorder
- type HTTPRequestRecorderWithChan
- type JSONLog
- type JSONLogs
- type MockSourceProvider
- type MockStatsProcessor
- type OverwriteHandleFunc
- type TestGauge
Constants ¶
const ( ValidateAPIKeyEndpoint = "/api/v1/validate" // nolint G101 MetricV1Endpoint = "/api/v1/series" MetricV2Endpoint = "/api/v2/series" SketchesMetricEndpoint = "/api/beta/sketches" MetadataEndpoint = "/intake" TraceEndpoint = "/api/v0.2/traces" APMStatsEndpoint = "/api/v0.2/stats" )
#nosec G101 -- This is a false positive, these are API endpoints rather than credentials
Variables ¶
var ( // TestLogTime is the default time used for tests. TestLogTime = time.Date(2020, 2, 11, 20, 26, 13, 789, time.UTC) // TestLogTimestamp is the default timestamp used for tests. TestLogTimestamp = pcommon.NewTimestampFromTime(TestLogTime) )
var ( // TestMetrics metrics for tests. TestMetrics = newMetricsWithAttributeMap(testAttributes) // TestTraces traces for tests. TestTraces = newTracesWithAttributeMap(testAttributes) )
var StatsPayloads = []*pb.ClientStatsPayload{ { Hostname: "host", Env: "prod", Version: "v1.2", Lang: "go", TracerVersion: "v44", RuntimeID: "123jkl", Sequence: 2, AgentAggregation: "blah", Service: "mysql", ContainerID: "abcdef123456", Tags: []string{"a:b", "c:d"}, Stats: []*pb.ClientStatsBucket{ { Start: 10, Duration: 1, Stats: []*pb.ClientGroupedStats{ { Service: "kafka", Name: "queue.add", Resource: "append", HTTPStatusCode: 220, Type: "queue", Hits: 15, Errors: 3, Duration: 143, OkSummary: testSketchBytes(1, 2, 3), ErrorSummary: testSketchBytes(4, 5, 6), TopLevelHits: 5, }, }, }, }, }, { Hostname: "host2", Env: "prod2", Version: "v1.22", Lang: "go2", TracerVersion: "v442", RuntimeID: "123jkl2", Sequence: 22, AgentAggregation: "blah2", Service: "mysql2", ContainerID: "abcdef1234562", Tags: []string{"a:b2", "c:d2"}, Stats: []*pb.ClientStatsBucket{ { Start: 102, Duration: 12, Stats: []*pb.ClientGroupedStats{ { Service: "kafka2", Name: "queue.add2", Resource: "append2", HTTPStatusCode: 2202, Type: "queue2", Hits: 152, Errors: 32, Duration: 1432, OkSummary: testSketchBytes(7, 8), ErrorSummary: testSketchBytes(9, 10, 11), TopLevelHits: 52, }, }, }, }, }, }
StatsPayloads contains a couple of *pb.ClientStatsPayloads used for testing.
Functions ¶
func GenerateLogsNoLogRecords ¶
GenerateLogsNoLogRecords generates a logs structure with one entry.
func GenerateLogsOneEmptyLogRecord ¶
GenerateLogsOneEmptyLogRecord generates a log structure with one empty record.
func GenerateLogsOneEmptyResourceLogs ¶
GenerateLogsOneEmptyResourceLogs generates one empty logs structure.
func GenerateLogsOneLogRecord ¶
GenerateLogsOneLogRecord generates a logs structure with one record.
func GenerateLogsOneLogRecordNoResource ¶
GenerateLogsOneLogRecordNoResource generates a logs structure with one record and no resource.
func GenerateLogsTwoLogRecordsSameResource ¶
GenerateLogsTwoLogRecordsSameResource generates a logs structure with two log records sharding the same resource.
func LoadConfig ¶
LoadConfig from a given path.
func NewAttributeMap ¶
NewAttributeMap creates a new attribute map (string only) from a Go map
func NewGaugeMetrics ¶
NewGaugeMetrics creates a set of pmetric.Metrics containing all the specified test gauges.
func OTLPConfigFromPorts ¶
OTLPConfigFromPorts creates a test OTLP config map.
func ValidateAPIKeyEndpointInvalid ¶
func ValidateAPIKeyEndpointInvalid() (string, http.HandlerFunc)
ValidateAPIKeyEndpointInvalid returns a handler function that returns an invalid API key response
Types ¶
type DatadogLogsServer ¶
type DatadogLogsServer struct { *httptest.Server // LogsData is the array of json requests sent to datadog backend LogsData JSONLogs }
DatadogLogsServer implements a HTTP server that accepts Datadog logs
func DatadogLogServerMock ¶
func DatadogLogServerMock(overwriteHandlerFuncs ...OverwriteHandleFunc) *DatadogLogsServer
DatadogLogServerMock mocks a Datadog Logs Intake backend server
type DatadogServer ¶
type DatadogServer struct { *httptest.Server MetadataChan chan payload.HostMetadata }
DatadogServer is the mock Datadog backend server
func DatadogServerMock ¶
func DatadogServerMock(overwriteHandlerFuncs ...OverwriteHandleFunc) *DatadogServer
DatadogServerMock mocks a Datadog backend server
type HTTPRequestRecorder ¶
HTTPRequestRecorder records a HTTP request.
func (*HTTPRequestRecorder) HandlerFunc ¶
func (rec *HTTPRequestRecorder) HandlerFunc() (string, http.HandlerFunc)
HandlerFunc implements an HTTP handler
type HTTPRequestRecorderWithChan ¶
HTTPRequestRecorderWithChan puts all incoming HTTP request bytes to the given channel.
func (*HTTPRequestRecorderWithChan) HandlerFunc ¶
func (rec *HTTPRequestRecorderWithChan) HandlerFunc() (string, http.HandlerFunc)
HandlerFunc implements an HTTP handler
type JSONLogs ¶
JSONLogs is the type for the array of processed JSON log data from each request
func MockLogsEndpoint ¶
func MockLogsEndpoint(w http.ResponseWriter, r *http.Request) JSONLogs
MockLogsEndpoint returns the processed JSON log data for each endpoint call
func ProcessLogsAgentRequest ¶
func ProcessLogsAgentRequest(w http.ResponseWriter, r *http.Request) JSONLogs
ProcessLogsAgentRequest handles HTTP requests from logs agent
type MockSourceProvider ¶
MockSourceProvider mocks a source provider
type MockStatsProcessor ¶
type MockStatsProcessor struct {
In []*pb.ClientStatsPayload
}
MockStatsProcessor mocks a stats processor
func (*MockStatsProcessor) ProcessStats ¶
func (s *MockStatsProcessor) ProcessStats(in *pb.ClientStatsPayload, _, _ string)
ProcessStats implements the stats processor interface
type OverwriteHandleFunc ¶
type OverwriteHandleFunc func() (string, http.HandlerFunc)
OverwriteHandleFunc allows to overwrite the default handler functions