Documentation ¶
Index ¶
- Variables
- func Aggregate(ctx context.Context, cfg *Config, celVariables *CELVariables, ...) ([]*metricdata.ResourceMetrics, error)
- func AggregationTypeStrings() []string
- func AppendValueToHistogramDataPoint[N int64 | float64](value N, dp metricdata.HistogramDataPoint[N], noMinMax bool) metricdata.HistogramDataPoint[N]
- func IsGzipped(data []byte) bool
- func LenDataPoints(data metricdata.Aggregation) int
- func MakeVM(opts ...JsonnetOption) *jsonnet.VM
- func NewS3ObjectReader(ctx context.Context, downloader *manager.Downloader, bucket, key string) (io.Reader, error)
- func ParseCFStandardLogObjectKey(str string) (string, string, string, string, error)
- func ToAttribute(ctx context.Context, key string, value any) (attribute.KeyValue, bool)
- func ToAttributes(ctx context.Context, cfgs []AttributeConfig, celVariables *CELVariables) ([]attribute.KeyValue, error)
- func UnwrapEvent(ctx context.Context, event json.RawMessage) func(yield func(json.RawMessage) bool)
- type AggregationType
- func (i AggregationType) IsAAggregationType() bool
- func (i AggregationType) MarshalJSON() ([]byte, error)
- func (i AggregationType) MarshalText() ([]byte, error)
- func (i AggregationType) String() string
- func (i *AggregationType) UnmarshalJSON(data []byte) error
- func (i *AggregationType) UnmarshalText(text []byte) error
- type App
- func (app *App) GetVariablesAndLogs(ctx context.Context, notification events.S3EventRecord) (*CELVariables, []CELVariablesLog, error)
- func (app *App) Invoke(ctx context.Context, event json.RawMessage) (any, error)
- func (app *App) Process(ctx context.Context, notifications []events.S3EventRecord) error
- type AttributeConfig
- type BackfillConfig
- type CELCapable
- type CELVariables
- type CELVariablesCloudFront
- type CELVariablesLog
- type CELVariablesS3Bucket
- type CELVariablesS3Object
- type CELVariablesS3UserIdentity
- type CannotUseCELNativeFunctionError
- type Config
- type JsonnetOption
- type MetricsConfig
- type OtelConfig
- type S3APIClient
- type ScopeConfig
- type WriteAtBuffer
Constants ¶
This section is empty.
Variables ¶
var Base64EncodeNativeFunction = &jsonnet.NativeFunction{ Name: "base64_encode", Params: []ast.Identifier{"data"}, Func: func(args []interface{}) (interface{}, error) { if len(args) != 1 { return nil, oops.Errorf("base64_encode: invalid arguments length expected 1 got %d", len(args)) } var data []byte str, ok := args[0].(string) if ok { data = []byte(str) } else { data, ok = args[0].([]byte) if !ok { return nil, oops.Errorf("base64_encode: invalid arguments, expected string or []byte got %T", args[0]) } } return base64.StdEncoding.EncodeToString(data), nil }, }
var CELCapableNativeFunction = &jsonnet.NativeFunction{ Name: "cel", Params: []ast.Identifier{"expr"}, Func: func(args []interface{}) (interface{}, error) { if len(args) != 1 { return nil, oops.Errorf("cel: invalid arguments length expected 1 got %d", len(args)) } str, ok := args[0].(string) if !ok { return nil, oops.Errorf("cel: invalid arguments, expected string got %T", args[0]) } return map[string]interface{}{ "expr": str, }, nil }, }
var DefaultHistogramBoundaries = []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}
var EnvNativeFunction = &jsonnet.NativeFunction{ Name: "env", Params: []ast.Identifier{"name", "default"}, Func: func(args []interface{}) (interface{}, error) { if len(args) != 2 { return nil, oops.Errorf("env: invalid arguments length expected 2 got %d", len(args)) } key, ok := args[0].(string) if !ok { return nil, oops.Errorf("env: invalid 1st arguments, expected string got %T", args[0]) } val := os.Getenv(key) if val == "" { return args[1], nil } return val, nil }, }
var JsonescapeNativeFunction = &jsonnet.NativeFunction{ Name: "json_escape", Params: []ast.Identifier{"str"}, Func: func(args []interface{}) (interface{}, error) { if len(args) != 1 { return nil, oops.Errorf("jsonescape: invalid arguments length expected 1 got %d", len(args)) } str, ok := args[0].(string) if !ok { return nil, oops.Errorf("jsonescape: invalid arguments, expected string got %T", args[0]) } bs, err := json.Marshal(str) if err != nil { return nil, oops.Wrapf(err, "jsonescape") } return string(bs), nil }, }
var MustEnvNativeFunction = &jsonnet.NativeFunction{ Name: "must_env", Params: []ast.Identifier{"name"}, Func: func(args []interface{}) (interface{}, error) { if len(args) != 1 { return nil, oops.Errorf("must_env: invalid arguments length expected 1 got %d", len(args)) } key, ok := args[0].(string) if !ok { return nil, oops.Errorf("must_env: invalid arguments, expected string got %T", args[0]) } val, ok := os.LookupEnv(key) if !ok { return nil, oops.Errorf("must_env: %s not set", key) } return val, nil }, }
var NativeFunctions = []*jsonnet.NativeFunction{ MustEnvNativeFunction, EnvNativeFunction, JsonescapeNativeFunction, Base64EncodeNativeFunction, CELCapableNativeFunction, SwitchNativeFunction, }
var SwitchNativeFunction = &jsonnet.NativeFunction{ Name: "switch", Params: []ast.Identifier{"cases"}, Func: func(args []interface{}) (interface{}, error) { if len(args) != 1 { return nil, oops.Errorf("switch: invalid arguments length expected 1 got %d", len(args)) } cases, ok := args[0].([]any) if !ok { return nil, oops.Errorf("switch: invalid arguments, expected string got %T", args[0]) } defaultCount := 0 for i, c := range cases { v, ok := c.(map[string]any) if !ok { return nil, oops.Errorf("switch: invalid arguments, expected map[string]interface{} got %T", c) } caseField, ok := v["case"] if !ok { defaultField, ok := v["default"] if !ok { return nil, oops.Errorf("switch: invalid arguments, expected string case") } defaultCount++ if defaultExpr, ok := castCELExpr(defaultField); ok { cases[i] = map[string]any{ "default_expr": defaultExpr, } } continue } caseExpr, ok := castCELExpr(caseField) if !ok { return nil, oops.Errorf("switch: case must be a CEL expression") } valueField, ok := v["value"] if !ok { return nil, oops.Errorf("cel: invalid arguments, need value") } if valueExpr, ok := castCELExpr(valueField); ok { cases[i] = map[string]any{ "case": caseExpr, "value_expr": valueExpr, } continue } cases[i] = map[string]any{ "case": caseExpr, "value": valueField, } } if defaultCount > 1 { return nil, oops.Errorf("cel: multiple default values in switch") } return map[string]interface{}{ "switch": cases, }, nil }, }
var Version = "v0.6.0"
Functions ¶
func Aggregate ¶
func Aggregate(ctx context.Context, cfg *Config, celVariables *CELVariables, logs []CELVariablesLog) ([]*metricdata.ResourceMetrics, error)
func AggregationTypeStrings ¶
func AggregationTypeStrings() []string
AggregationTypeStrings returns a slice of all String values of the enum
func AppendValueToHistogramDataPoint ¶
func AppendValueToHistogramDataPoint[N int64 | float64](value N, dp metricdata.HistogramDataPoint[N], noMinMax bool) metricdata.HistogramDataPoint[N]
func LenDataPoints ¶
func LenDataPoints(data metricdata.Aggregation) int
func MakeVM ¶
func MakeVM(opts ...JsonnetOption) *jsonnet.VM
func NewS3ObjectReader ¶ added in v0.2.0
func ToAttribute ¶ added in v0.3.0
func ToAttributes ¶
func ToAttributes(ctx context.Context, cfgs []AttributeConfig, celVariables *CELVariables) ([]attribute.KeyValue, error)
func UnwrapEvent ¶
func UnwrapEvent(ctx context.Context, event json.RawMessage) func(yield func(json.RawMessage) bool)
Types ¶
type AggregationType ¶
type AggregationType int
const ( AggregationTypeCount AggregationType = iota AggregationTypeSum AggregationTypeHistogram )
func AggregationTypeString ¶
func AggregationTypeString(s string) (AggregationType, error)
AggregationTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func AggregationTypeValues ¶
func AggregationTypeValues() []AggregationType
AggregationTypeValues returns all values of the enum
func (AggregationType) IsAAggregationType ¶
func (i AggregationType) IsAAggregationType() bool
IsAAggregationType returns "true" if the value is listed in the enum definition. "false" otherwise
func (AggregationType) MarshalJSON ¶
func (i AggregationType) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for AggregationType
func (AggregationType) MarshalText ¶
func (i AggregationType) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface for AggregationType
func (AggregationType) String ¶
func (i AggregationType) String() string
func (*AggregationType) UnmarshalJSON ¶
func (i *AggregationType) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for AggregationType
func (*AggregationType) UnmarshalText ¶
func (i *AggregationType) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface for AggregationType
type App ¶
type App struct {
// contains filtered or unexported fields
}
func NewWithClient ¶
func NewWithClient(cfg *Config, client S3APIClient) (*App, error)
func (*App) GetVariablesAndLogs ¶ added in v0.2.0
func (app *App) GetVariablesAndLogs(ctx context.Context, notification events.S3EventRecord) (*CELVariables, []CELVariablesLog, error)
type AttributeConfig ¶
type AttributeConfig struct { Key string `json:"key,omitempty"` Value *CELCapable[any] `json:"value,omitempty"` }
func (*AttributeConfig) UnmarshalJSON ¶ added in v0.3.0
func (c *AttributeConfig) UnmarshalJSON(data []byte) error
func (*AttributeConfig) Validate ¶
func (c *AttributeConfig) Validate() error
type BackfillConfig ¶ added in v0.2.0
type BackfillConfig struct { Enabled bool `json:"enabled,omitempty"` TimeTolerance string `json:"time_tolerance,omitempty"` // contains filtered or unexported fields }
func (*BackfillConfig) TimeToleranceDuration ¶ added in v0.2.0
func (c *BackfillConfig) TimeToleranceDuration() time.Duration
func (*BackfillConfig) UnmarshalJSON ¶ added in v0.3.0
func (c *BackfillConfig) UnmarshalJSON(data []byte) error
func (*BackfillConfig) Validate ¶ added in v0.2.0
func (c *BackfillConfig) Validate() error
type CELCapable ¶
type CELCapable[T any] struct { // contains filtered or unexported fields }
func (*CELCapable[T]) Eval ¶
func (expr *CELCapable[T]) Eval(ctx context.Context, vars *CELVariables) (T, error)
func (*CELCapable[T]) MarshalJSON ¶
func (expr *CELCapable[T]) MarshalJSON() ([]byte, error)
func (*CELCapable[T]) UnmarshalJSON ¶
func (expr *CELCapable[T]) UnmarshalJSON(data []byte) error
type CELVariables ¶
type CELVariables struct { Bucket CELVariablesS3Bucket `json:"bucket" cel:"bucket"` Object CELVariablesS3Object `json:"object" cel:"object"` CloudFront CELVariablesCloudFront `json:"cloudfront" cel:"cloudfront"` Log CELVariablesLog `json:"log" cel:"log"` }
func NewCELVariables ¶
func NewCELVariables(record events.S3EventRecord, distributionID string) *CELVariables
func (*CELVariables) MarshalMap ¶
func (v *CELVariables) MarshalMap() map[string]interface{}
func (*CELVariables) SetLogLine ¶ added in v0.2.0
func (v *CELVariables) SetLogLine(log CELVariablesLog)
type CELVariablesCloudFront ¶
type CELVariablesCloudFront struct {
DistributionID string `json:"distributionId" cel:"distributionId"`
}
type CELVariablesLog ¶
type CELVariablesLog struct { Type string `json:"type" cel:"type"` Date string `json:"date" cel:"date"` Time string `json:"time" cel:"time"` Timestamp time.Time `json:"timestamp" cel:"timestamp"` EdgeLocation *string `json:"xEdgeLocation" cel:"xEdgeLocation"` ScBytes *int `json:"scBytes" cel:"scBytes"` ClientIP *string `json:"clientIp" cel:"clientIp"` CsMethod *string `json:"csMethod" cel:"csMethod"` CsHost *string `json:"csHost" cel:"csHost"` CsURIStem *string `json:"csUriStem" cel:"csUriStem"` ScStatus *int `json:"scStatus" cel:"scStatus"` ScStatusCategory *string `json:"scStatusCategory" cel:"scStatusCategory"` CsReferer *string `json:"csReferer" cel:"csReferer"` CsUserAgent *string `json:"csUserAgent" cel:"csUserAgent"` CsURIQuery *string `json:"csUriQuery" cel:"csUriQuery"` CsCookie *string `json:"csCookie" cel:"csCookie"` EdgeResultType *string `json:"xEdgeResultType" cel:"xEdgeResultType"` EdgeRequestID *string `json:"xEdgeRequestId" cel:"xEdgeRequestId"` HostHeader *string `json:"xHostHeader" cel:"xHostHeader"` CsProtocol *string `json:"csProtocol" cel:"csProtocol"` CsBytes *int `json:"csBytes" cel:"csBytes"` TimeTaken *float64 `json:"timeTaken" cel:"timeTaken"` XForwardedFor *string `json:"xForwardedFor" cel:"xForwardedFor"` SslProtocol *string `json:"sslProtocol" cel:"sslProtocol"` SslCipher *string `json:"sslCipher" cel:"sslCipher"` EdgeResponseResultType *string `json:"edgeResponseResultType" cel:"edgeResponseResultType"` CsProtocolVersion *string `json:"csProtocolVersion" cel:"csProtocolVersion"` FleStatus *string `json:"fleStatus" cel:"fleStatus"` FleEncryptedFields *int `json:"fleEncryptedFields" cel:"fleEncryptedFields"` CPort *int `json:"cPort" cel:"cPort"` TimeToFirstByte *float64 `json:"timeToFirstByte" cel:"timeToFirstByte"` EdgeDetailedResultType *string `json:"xEdgeDetailedResultType" cel:"xEdgeDetailedResultType"` ScContentType *string `json:"scContentType" cel:"scContentType"` ScContentLen *int `json:"scContentLen" cel:"scContentLen"` ScRangeStart *string `json:"scRangeStart" cel:"scRangeStart"` ScRangeEnd *string `json:"scRangeEnd" cel:"scRangeEnd"` }
func ParseCloudFrontLog ¶
func (*CELVariablesLog) CloudFrontStandardLogFieldSetters ¶
func (l *CELVariablesLog) CloudFrontStandardLogFieldSetters() map[string]func(string) error
type CELVariablesS3Bucket ¶
type CELVariablesS3Bucket struct { Name string `json:"name" cel:"name"` OwnerIdentity CELVariablesS3UserIdentity `json:"ownerIdentity" cel:"ownerIdentity"` Arn string `json:"arn" cel:"arn"` }
type CELVariablesS3Object ¶
type CELVariablesS3UserIdentity ¶
type CELVariablesS3UserIdentity struct {
PrincipalID string `json:"principalId" cel:"principalId"`
}
type CannotUseCELNativeFunctionError ¶ added in v0.3.0
type CannotUseCELNativeFunctionError struct {
Field string
}
func IsCannotUseCELNativeFunction ¶ added in v0.3.0
func IsCannotUseCELNativeFunction(err error, bs []byte, allowColumns []string) (*CannotUseCELNativeFunctionError, bool)
func (*CannotUseCELNativeFunctionError) Error ¶ added in v0.3.0
func (e *CannotUseCELNativeFunctionError) Error() string
type Config ¶
type Config struct { Otel OtelConfig `json:"otel,omitempty"` ResourceAttributes []AttributeConfig `json:"resource_attributes,omitempty"` Scope ScopeConfig `json:"scope,omitempty"` Metrics []MetricsConfig `json:"metrics,omitempty"` Backfill BackfillConfig `json:"backfill,omitempty"` NoSkip bool `json:"no_skip,omitempty"` }
func DefaultConfig ¶
func DefaultConfig() *Config
type JsonnetOption ¶
type JsonnetOption func(*jsonnetOptions)
func WithAWSConfig ¶
func WithAWSConfig(cfg aws.Config) JsonnetOption
func WithCache ¶
func WithCache(cache *sync.Map) JsonnetOption
func WithContext ¶
func WithContext(ctx context.Context) JsonnetOption
type MetricsConfig ¶
type MetricsConfig struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` Interval string `json:"interval,omitempty"` Unit string `json:"unit,omitempty"` Type AggregationType `json:"type,omitempty"` Attributes []AttributeConfig `json:"attributes,omitempty"` Filter *CELCapable[bool] `json:"filter,omitempty"` Value *CELCapable[float64] `json:"value,omitempty"` IsMonotonic bool `json:"is_monotonic,omitempty"` IsCumulative bool `json:"is_cumulative,omitempty"` Boundaries []float64 `json:"boundaries,omitempty"` NoMinMax bool `json:"no_min_max,omitempty"` EmitZero [][]any `json:"emit_zero,omitempty"` // contains filtered or unexported fields }
func (*MetricsConfig) AggregateInterval ¶
func (c *MetricsConfig) AggregateInterval() time.Duration
func (*MetricsConfig) UnmarshalJSON ¶ added in v0.3.0
func (c *MetricsConfig) UnmarshalJSON(data []byte) error
func (*MetricsConfig) Validate ¶
func (c *MetricsConfig) Validate() error
type OtelConfig ¶
type OtelConfig struct { Headers map[string]string `json:"headers,omitempty"` Endpoint string `json:"endpoint,omitempty"` GZip bool `json:"gzip,omitempty"` // contains filtered or unexported fields }
func (*OtelConfig) EndpointURL ¶
func (c *OtelConfig) EndpointURL() *url.URL
func (*OtelConfig) SetEndpointURL ¶
func (c *OtelConfig) SetEndpointURL(endpoint string) error
func (*OtelConfig) UnmarshalJSON ¶ added in v0.3.0
func (c *OtelConfig) UnmarshalJSON(data []byte) error
func (*OtelConfig) Validate ¶
func (c *OtelConfig) Validate() error
type S3APIClient ¶ added in v0.2.0
type S3APIClient interface { manager.DownloadAPIClient s3.ListObjectsV2APIClient }
type ScopeConfig ¶
type ScopeConfig struct { Name string `json:"name"` Version string `json:"version,omitempty"` SchemaURL string `json:"schema_url,omitempty"` }
func (*ScopeConfig) Validate ¶
func (c *ScopeConfig) Validate() error
type WriteAtBuffer ¶
type WriteAtBuffer struct {
// contains filtered or unexported fields
}
WriteAtBuffer is an in-memory buffer implementing io.WriterAt
func NewWriteAtBuffer ¶
func NewWriteAtBuffer() *WriteAtBuffer
NewWriteAtBuffer creates a new WriteAtBuffer
func (*WriteAtBuffer) Bytes ¶
func (w *WriteAtBuffer) Bytes() []byte
Bytes returns the contents of the buffer