Documentation ¶
Index ¶
- func RunClientTests(f ClientFactory) func(*testing.T)
- func WithHTTPCollectorRespondingPlainText() func(*HTTPCollector)
- type Client
- type ClientFactory
- type Collector
- type ExportResult
- type GRPCCollector
- func (c *GRPCCollector) Addr() net.Addr
- func (c *GRPCCollector) Collect() *Storage
- func (c *GRPCCollector) Export(ctx context.Context, req *collpb.ExportMetricsServiceRequest) (*collpb.ExportMetricsServiceResponse, error)
- func (c *GRPCCollector) Headers() map[string][]string
- func (c *GRPCCollector) Shutdown()
- type HTTPCollector
- type HTTPResponseError
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunClientTests ¶
func RunClientTests(f ClientFactory) func(*testing.T)
RunClientTests runs a suite of Client integration tests. For example:
t.Run("Integration", RunClientTests(factory))
func WithHTTPCollectorRespondingPlainText ¶ added in v0.44.0
func WithHTTPCollectorRespondingPlainText() func(*HTTPCollector)
WithHTTPCollectorRespondingPlainText makes the HTTPCollector return a plaintext, instead of protobuf, response.
Types ¶
type ClientFactory ¶
type ClientFactory func(resultCh <-chan ExportResult) (Client, Collector)
ClientFactory is a function that when called returns a Client implementation that is connected to also returned Collector implementation. The Client is ready to upload metric data to the Collector which is ready to store that data.
If resultCh is not nil, the returned Collector needs to use the responses from that channel to send back to the client for every export request.
type Collector ¶
type Collector interface {
Collect() *Storage
}
Collector is the collection target a Client sends metric uploads to.
type ExportResult ¶
type ExportResult struct { Response *collpb.ExportMetricsServiceResponse Err error }
type GRPCCollector ¶
type GRPCCollector struct { collpb.UnimplementedMetricsServiceServer // contains filtered or unexported fields }
GRPCCollector is an OTLP gRPC server that collects all requests it receives.
func NewGRPCCollector ¶
func NewGRPCCollector(endpoint string, resultCh <-chan ExportResult) (*GRPCCollector, error)
NewGRPCCollector returns a *GRPCCollector that is listening at the provided endpoint.
If endpoint is an empty string, the returned collector will be listening on the localhost interface at an OS chosen port.
If errCh is not nil, the collector will respond to Export calls with errors sent on that channel. This means that if errCh is not nil Export calls will block until an error is received.
func (*GRPCCollector) Addr ¶
func (c *GRPCCollector) Addr() net.Addr
Addr returns the net.Addr c is listening at.
func (*GRPCCollector) Collect ¶
func (c *GRPCCollector) Collect() *Storage
Collect returns the Storage holding all collected requests.
func (*GRPCCollector) Export ¶
func (c *GRPCCollector) Export(ctx context.Context, req *collpb.ExportMetricsServiceRequest) (*collpb.ExportMetricsServiceResponse, error)
Export handles the export req.
func (*GRPCCollector) Headers ¶
func (c *GRPCCollector) Headers() map[string][]string
Headers returns the headers received for all requests.
func (*GRPCCollector) Shutdown ¶
func (c *GRPCCollector) Shutdown()
Shutdown shuts down the gRPC server closing all open connections and listeners immediately.
type HTTPCollector ¶
type HTTPCollector struct {
// contains filtered or unexported fields
}
HTTPCollector is an OTLP HTTP server that collects all requests it receives.
func NewHTTPCollector ¶
func NewHTTPCollector(endpoint string, resultCh <-chan ExportResult, opts ...func(*HTTPCollector)) (*HTTPCollector, error)
NewHTTPCollector returns a *HTTPCollector that is listening at the provided endpoint.
If endpoint is an empty string, the returned collector will be listening on the localhost interface at an OS chosen port, not use TLS, and listen at the default OTLP metric endpoint path ("/v1/metrics"). If the endpoint contains a prefix of "https" the server will generate weak self-signed TLS certificates and use them to server data. If the endpoint contains a path, that path will be used instead of the default OTLP metric endpoint path.
If errCh is not nil, the collector will respond to HTTP requests with errors sent on that channel. This means that if errCh is not nil Export calls will block until an error is received.
func (*HTTPCollector) Addr ¶
func (c *HTTPCollector) Addr() net.Addr
Addr returns the net.Addr c is listening at.
func (*HTTPCollector) Collect ¶
func (c *HTTPCollector) Collect() *Storage
Collect returns the Storage holding all collected requests.
func (*HTTPCollector) Headers ¶
func (c *HTTPCollector) Headers() map[string][]string
Headers returns the headers received for all requests.
type HTTPResponseError ¶
func (*HTTPResponseError) Error ¶
func (e *HTTPResponseError) Error() string
func (*HTTPResponseError) Unwrap ¶
func (e *HTTPResponseError) Unwrap() error
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage stores uploaded OTLP metric data in their proto form.
func NewStorage ¶
func NewStorage() *Storage
NewStorage returns a configure storage ready to store received requests.
func (*Storage) Add ¶
func (s *Storage) Add(request *collpb.ExportMetricsServiceRequest)
Add adds the request to the Storage.
func (*Storage) Dump ¶
func (s *Storage) Dump() []*mpb.ResourceMetrics
Dump returns all added ResourceMetrics and clears the storage.