telemetry

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ATTR_FGA_CLIENT_REQUEST_CLIENT_ID = "fga-client.request.client_id"
	ATTR_FGA_CLIENT_REQUEST_METHOD    = "fga-client.request.method"
	ATTR_FGA_CLIENT_REQUEST_MODEL_ID  = "fga-client.request.model_id"
	ATTR_FGA_CLIENT_REQUEST_STORE_ID  = "fga-client.request.store_id"
	ATTR_FGA_CLIENT_RESPONSE_MODEL_ID = "fga-client.response.model_id"
	ATTR_FGA_CLIENT_USER              = "fga-client.user"
	ATTR_HTTP_CLIENT_REQUEST_DURATION = "http.client.request.duration"
	ATTR_HTTP_HOST                    = "http.host"
	ATTR_HTTP_REQUEST_METHOD          = "http.request.method"
	ATTR_HTTP_REQUEST_RESEND_COUNT    = "http.request.resend_count"
	ATTR_HTTP_RESPONSE_STATUS_CODE    = "http.response.status_code"
	ATTR_HTTP_SERVER_REQUEST_DURATION = "http.server.request.duration"
	ATTR_URL_SCHEME                   = "url.scheme"
	ATTR_URL_FULL                     = "url.full"
	ATTR_USER_AGENT_ORIGINAL          = "user_agent.original"
)
View Source
const (
	METRIC_HISTOGRAM_REQUEST_DURATION string = "fga-client.request.duration"
	METRIC_HISTOGRAM_QUERY_DURATION   string = "fga-client.query.duration"
)
View Source
const (
	METRIC_COUNTER_CREDENTIALS_REQUEST string = "fga-client.credentials.request"
)

Variables

View Source
var (
	FGAClientRequestClientID  = &Attribute{Name: ATTR_FGA_CLIENT_REQUEST_CLIENT_ID}
	FGAClientRequestMethod    = &Attribute{Name: ATTR_FGA_CLIENT_REQUEST_METHOD}
	FGAClientRequestModelID   = &Attribute{Name: ATTR_FGA_CLIENT_REQUEST_MODEL_ID}
	FGAClientRequestStoreID   = &Attribute{Name: ATTR_FGA_CLIENT_REQUEST_STORE_ID}
	FGAClientResponseModelID  = &Attribute{Name: ATTR_FGA_CLIENT_RESPONSE_MODEL_ID}
	FGAClientUser             = &Attribute{Name: ATTR_FGA_CLIENT_USER}
	HTTPClientRequestDuration = &Attribute{Name: ATTR_HTTP_CLIENT_REQUEST_DURATION}
	HTTPHost                  = &Attribute{Name: ATTR_HTTP_HOST}
	HTTPRequestMethod         = &Attribute{Name: ATTR_HTTP_REQUEST_METHOD}
	HTTPRequestResendCount    = &Attribute{Name: ATTR_HTTP_REQUEST_RESEND_COUNT}
	HTTPResponseStatusCode    = &Attribute{Name: ATTR_HTTP_RESPONSE_STATUS_CODE}
	HTTPServerRequestDuration = &Attribute{Name: ATTR_HTTP_SERVER_REQUEST_DURATION}
	URLScheme                 = &Attribute{Name: ATTR_URL_SCHEME}
	URLFull                   = &Attribute{Name: ATTR_URL_FULL}
	UserAgent                 = &Attribute{Name: ATTR_USER_AGENT_ORIGINAL}
)
View Source
var (
	RequestDuration = &Histogram{
		Name:        METRIC_HISTOGRAM_REQUEST_DURATION,
		Unit:        "milliseconds",
		Description: "The total time (in milliseconds) it took for the request to complete, including the time it took to send the request and receive the response.",
	}

	QueryDuration = &Histogram{
		Name:        METRIC_HISTOGRAM_QUERY_DURATION,
		Unit:        "milliseconds",
		Description: "The total time it took (in milliseconds) for the FGA server to process and evaluate the request.",
	}
)
View Source
var CredentialsRequest = &Counter{
	Name:        METRIC_COUNTER_CREDENTIALS_REQUEST,
	Description: "The total number of times new access tokens have been requested using ClientCredentials.",
}

Functions

func Bind

func Bind(ctx context.Context, instance *Telemetry) context.Context

func Unbind

func Unbind(ctx context.Context) context.Context

Types

type Attribute

type Attribute struct {
	Name string
}

type AttributeConfiguration

type AttributeConfiguration struct {
	Enabled bool `json:"enabled,omitempty"`
}

type CheckRequestInterface

type CheckRequestInterface interface {
	GetTupleKey() CheckRequestTupleKeyInterface
	RequestAuthorizationModelIdInterface
}

CheckRequestInterface is a simplified interface that defines the methods the CheckRequest struct implements, relevant to the context of the telemetry package.

type CheckRequestTupleKeyInterface

type CheckRequestTupleKeyInterface interface {
	GetUser() *string
}

CheckRequestTupleKeyInterface is a simplified interface that defines the methods the CheckRequestTupleKey struct implements, relevant to the context of the telemetry package.

type Configuration

type Configuration struct {
	Metrics *MetricsConfiguration `json:"metrics,omitempty"`
}

func DefaultTelemetryConfiguration

func DefaultTelemetryConfiguration() *Configuration

type Counter

type Counter struct {
	Name        string
	Description string
}

func (*Counter) GetDescription

func (m *Counter) GetDescription() string

func (*Counter) GetName

func (m *Counter) GetName() string

type CredentialsRequestMetricParameters

type CredentialsRequestMetricParameters struct {
	Value int64
	Attrs map[*Attribute]string
	TelemetryFactoryParameters
}

type Histogram

type Histogram struct {
	Name        string
	Unit        string
	Description string
}

func (*Histogram) GetDescription

func (m *Histogram) GetDescription() string

func (*Histogram) GetName

func (m *Histogram) GetName() string

func (*Histogram) GetUnit

func (m *Histogram) GetUnit() string

type Metric

type Metric struct {
	Name        string
	Description string
	MetricInterface
}

func (*Metric) GetDescription

func (m *Metric) GetDescription() string

func (*Metric) GetName

func (m *Metric) GetName() string

type MetricConfiguration

type MetricConfiguration struct {
	ATTR_FGA_CLIENT_REQUEST_CLIENT_ID *AttributeConfiguration `json:"fga_client_request_client_id,omitempty"`
	ATTR_FGA_CLIENT_REQUEST_METHOD    *AttributeConfiguration `json:"fga_client_request_method,omitempty"`
	ATTR_FGA_CLIENT_REQUEST_MODEL_ID  *AttributeConfiguration `json:"fga_client_request_model_id,omitempty"`
	ATTR_FGA_CLIENT_REQUEST_STORE_ID  *AttributeConfiguration `json:"fga_client_request_store_id,omitempty"`
	ATTR_FGA_CLIENT_RESPONSE_MODEL_ID *AttributeConfiguration `json:"fga_client_response_model_id,omitempty"`
	ATTR_FGA_CLIENT_USER              *AttributeConfiguration `json:"fga_client_user,omitempty"`
	ATTR_HTTP_CLIENT_REQUEST_DURATION *AttributeConfiguration `json:"http_client_request_duration,omitempty"`
	ATTR_HTTP_HOST                    *AttributeConfiguration `json:"http_host,omitempty"`
	ATTR_HTTP_REQUEST_METHOD          *AttributeConfiguration `json:"http_request_method,omitempty"`
	ATTR_HTTP_REQUEST_RESEND_COUNT    *AttributeConfiguration `json:"http_request_resend_count,omitempty"`
	ATTR_HTTP_RESPONSE_STATUS_CODE    *AttributeConfiguration `json:"http_response_status_code,omitempty"`
	ATTR_HTTP_SERVER_REQUEST_DURATION *AttributeConfiguration `json:"http_server_request_duration,omitempty"`
	ATTR_URL_SCHEME                   *AttributeConfiguration `json:"url_scheme,omitempty"`
	ATTR_URL_FULL                     *AttributeConfiguration `json:"url_full,omitempty"`
	ATTR_USER_AGENT_ORIGINAL          *AttributeConfiguration `json:"user_agent_original,omitempty"`
}

type MetricInterface

type MetricInterface interface {
	GetName() string
	GetDescription() string
}

type Metrics

type Metrics struct {
	Meter metric.Meter

	Counters map[string]metric.Int64Counter

	Histograms    map[string]metric.Float64Histogram
	Configuration *MetricsConfiguration
	// contains filtered or unexported fields
}

func (*Metrics) AttributesFromQueryDuration

func (m *Metrics) AttributesFromQueryDuration(attrs map[*Attribute]string) (float64, map[*Attribute]string, error)

func (*Metrics) AttributesFromRequest

func (m *Metrics) AttributesFromRequest(req *http.Request, params map[string]interface{}) (map[*Attribute]string, error)

func (*Metrics) AttributesFromRequestDuration

func (m *Metrics) AttributesFromRequestDuration(requestStarted time.Time, attrs map[*Attribute]string) (float64, map[*Attribute]string, error)

func (*Metrics) AttributesFromResendCount

func (m *Metrics) AttributesFromResendCount(resendCount int, attrs map[*Attribute]string) (map[*Attribute]string, error)

func (*Metrics) AttributesFromResponse

func (m *Metrics) AttributesFromResponse(res *http.Response, attrs map[*Attribute]string) (map[*Attribute]string, error)

func (*Metrics) BuildTelemetryAttributes

func (m *Metrics) BuildTelemetryAttributes(requestMethod string, methodParameters map[string]interface{}, req *http.Request, res *http.Response, requestStarted time.Time, resendCount int) (map[*Attribute]string, float64, float64, error)

func (*Metrics) CredentialsRequest

func (m *Metrics) CredentialsRequest(value int64, attrs map[*Attribute]string) (metric.Int64Counter, error)

func (*Metrics) GetCounter

func (m *Metrics) GetCounter(name string, description string) (metric.Int64Counter, error)

func (*Metrics) GetHistogram

func (m *Metrics) GetHistogram(name string, description string, unit string) (metric.Float64Histogram, error)

func (*Metrics) PrepareAttributes

func (m *Metrics) PrepareAttributes(metric MetricInterface, attrs map[*Attribute]string, config *MetricsConfiguration) (attribute.Set, error)

func (*Metrics) QueryDuration

func (m *Metrics) QueryDuration(value float64, attrs map[*Attribute]string) (metric.Float64Histogram, error)

func (*Metrics) RequestDuration

func (m *Metrics) RequestDuration(value float64, attrs map[*Attribute]string) (metric.Float64Histogram, error)

type MetricsConfiguration

type MetricsConfiguration struct {
	METRIC_COUNTER_CREDENTIALS_REQUEST *MetricConfiguration `json:"fga_client_credentials_request,omitempty"`
	METRIC_HISTOGRAM_REQUEST_DURATION  *MetricConfiguration `json:"fga_client_request_duration,omitempty"`
	METRIC_HISTOGRAM_QUERY_DURATION    *MetricConfiguration `json:"fga_client_query_duration,omitempty"`
}

type MetricsInterface

type MetricsInterface interface {
	GetCounter(name string, description string) (metric.Int64Counter, error)
	GetHistogram(name string, description string, unit string) (metric.Float64Histogram, error)
	CredentialsRequest(value int64, attrs map[*Attribute]string) (metric.Int64Counter, error)
	RequestDuration(value float64, attrs map[*Attribute]string) (metric.Float64Histogram, error)
	QueryDuration(value float64, attrs map[*Attribute]string) (metric.Float64Histogram, error)
	BuildTelemetryAttributes(requestMethod string, methodParameters map[string]interface{}, req *http.Request, res *http.Response, requestStarted time.Time, resendCount int) (map[*Attribute]string, float64, float64, error)
}

type QueryDurationMetricParameters

type QueryDurationMetricParameters struct {
	Value float64
	Attrs map[*Attribute]string
	TelemetryFactoryParameters
}

type RequestAuthorizationModelIdInterface

type RequestAuthorizationModelIdInterface interface {
	GetAuthorizationModelId() *string
}

RequestAuthorizationModelIdInterface is a generic interface that defines the GetAuthorizationModelId() method a Request struct implements, relevant to the context of the telemetry package.

type RequestDurationMetricParameters

type RequestDurationMetricParameters struct {
	Value float64
	Attrs map[*Attribute]string
	TelemetryFactoryParameters
}

type Telemetry

type Telemetry struct {
	Metrics       MetricsInterface
	Configuration *Configuration
}

func Configure

func Configure(configuration *Configuration) (*Telemetry, error)

func Extract

func Extract(ctx context.Context) *Telemetry

func Get

type TelemetryContextKey

type TelemetryContextKey struct{}
var (

	// Warning: do not use directly, it may cause data race.
	// Deprecated: this map will be renamed to telemetryInstances.
	TelemetryInstances map[*Configuration]*Telemetry
	TelemetryContext   TelemetryContextKey
)

type TelemetryFactoryParameters

type TelemetryFactoryParameters struct {
	Configuration *Configuration
}

type TelemetryInterface

type TelemetryInterface interface {
	Configure(configuration *Configuration) (*Telemetry, error)
	Get(configuration *Configuration) *Telemetry
}

Jump to

Keyboard shortcuts

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