cdk

package
v1.50.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CDKCacheMissError

type CDKCacheMissError struct {
	Err error
}

func (*CDKCacheMissError) Error

func (c *CDKCacheMissError) Error() string

type CDKClientOption

type CDKClientOption func(c *ComponentCDKClient)

func WithLogger

func WithLogger(logger *zap.SugaredLogger) CDKClientOption

type ComponentCDKClient

type ComponentCDKClient struct {
	// contains filtered or unexported fields
}

func NewCDKClient

func NewCDKClient(componentVersion string, opts ...CDKClientOption) (*ComponentCDKClient, error)

NewCDKClient creates a new component CDK client

This client provides opinionated access to the services offerred from gRPC in the CDK (caching, metric data, etc)

Note, ensure you are closing the gRPC connection when your component ends using the `Close()` method on the ComponentCDKClient

func (*ComponentCDKClient) Close

func (c *ComponentCDKClient) Close() error

Close terminates the gRPC connection to the CDK service

func (*ComponentCDKClient) Metric

func (c *ComponentCDKClient) Metric(feature string, featureData map[string]string) *MetricData

Metric is used to create a new MetricData struct that can be augmented and ultimately sent

 now := time.Now()
 c, _ := NewCDKClient("0.0.1")
 _ = c.Metric("example", map[string]string{"example": "data"}).Send()
 _ = c.Metric("example2", map[string]string{"example2": "data"}).
	       WithDuration(time.Since(now).Milliseconds()).
	       Send()

func (*ComponentCDKClient) MetricError

func (c *ComponentCDKClient) MetricError(e error)

MetricError is used to write an error to Honeycomb

func (*ComponentCDKClient) ReadCacheAsset

func (c *ComponentCDKClient) ReadCacheAsset(key string) ([]byte, error)

ReadCacheAsset fetch key from cache

when an error is returned, if the reason for the error is a cache miss it will be of type CDKCacheMissError which should be handled/treated as non-fatal

Response data is in []byte format and will need to be unmarshalled to the correct data type

func (*ComponentCDKClient) SetLogger

func (c *ComponentCDKClient) SetLogger(logger ComponentCDKLogger)

SetLogger enables overwriting the built-in logger to a custom logger that satifies the ComponentCDKLogger interface

func (*ComponentCDKClient) WriteCacheAsset

func (c *ComponentCDKClient) WriteCacheAsset(key string, expires time.Time, data interface{}) error

WriteCacheAsset persists data to the Lacework CLI on-disk cache via the CDK service

Note, data written to the cache is marshalled to JSON first.

If there is an error writing to cache the error is logged but the return will be nil. Errors writing to should never be fatal and stop a component. However, if the data supplied cannot be marshalled into JSON an actual error will be returned.

type ComponentCDKLogger

type ComponentCDKLogger interface {
	Infow(msg string, keysAndValues ...interface{})
	Debugf(template string, args ...interface{})
	Debug(args ...interface{})
	Warn(args ...interface{})
}

type MetricData

type MetricData struct {
	// Feature name in Honeycomb
	Feature string

	// Feature data in Honeycomb
	FeatureData map[string]string

	// Duration for this span (each MetricData is a unique span)
	Duration int64
	// contains filtered or unexported fields
}

MetricData is used when sending data to Honeycomb

For convience, use the `Metric()` method on the ComponentCDKClient instead of this struct directly

func (*MetricData) Send

func (m *MetricData) Send() error

Send Writes the MetricData to Honeycomb

func (*MetricData) WithDuration

func (m *MetricData) WithDuration(duration int64) *MetricData

WithDuration attaches a duration to the given span that will be created in Honeycomb (which is optional)

Jump to

Keyboard shortcuts

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