pkger

package
v2.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2020 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package pkger implements a means to create and consume reusable templates for what will eventually come to support all influxdb resources. As of writing this we have support for creating buckets, dashboards, labels, and variables. All the resources can be cloned to create a new pkg from existing resources as well.

The parser supports both JSON and YAML encodings as well as a number of different ways to read the file/reader/string as it may.

As an example, you can use the following to parse and validate a YAML file and see a summary of its contents:

newPkg, err := Parse(EncodingYAML, FromFile(PATH_TO_FILE))
if err != nil {
	panic(err) // handle error as you see fit
}
sum := newPkg.Summary()
fmt.Println(sum) // do something with the summary

The parser will validate all contents of the package and provide any and all fields/entries that failed validation.

If you wish to use the Pkg type in your transport layer and let the the transport layer manage the decoding, then you can run the following to validate the package after the raw decoding is done:

if err := pkg.Validate(); err != nil {
	panic(err) // handle error as you see fit
}

If a validation error is encountered during the validation or parsing then the error returned will be of type *parseErr. The parseErr provides a rich set of validations failures. There can be numerous failures in a package and we did our best to inform the caller about them all in a single run.

If you want to see the effects of a package before applying it to the organization's influxdb platform, you have the flexibility to dry run the package and see the outcome of what would happen after it were to be applied. You may use the following to dry run a package within your organization:

svc := NewService(serviceOpts...)
summary, diff, err := svc.DryRun(ctx, orgID, pkg)
if err != nil {
	panic(err) // handle error as you see fit
}
// explore the summary and diff

The diff provided here is a diff of the existing state of the platform for your organization and the concluding the state after the application of a package. All buckets, labels, and variables, when given a name that already exists, will not create a new resource, but rather, will edit the existing resource. If this is not a desired result, then rename your bucket to something else to avoid the imposed changes applying this package would incur. The summary provided is a summary of hte package itself. If a resource exists all IDs will be populated for them, if they do not, then they will be zero values. Any zero value ID is safe to assume is not populated. All influxdb.ID's must be non zero to be valid.

If you would like to apply a package you may use the service to do so. The following will apply the package in full to the provided organization.

svc := NewService(serviceOpts...)
summary, err := svc.Apply(ctx, orgID, pkg)
if err != nil {
	panic(err) // handle error as you see fit
}
// explore the summary

The summary will be populated with valid IDs that were created during the application of the package. If an error is encountered during the application of a package, then all changes that had occurred will be rolled back. However, as a warning for buckets, changes may have incurred destructive changes. The changes are not applied inside a large transaction, for numerous reasons, but it is something to be considered. If you have dry run the package before it is to be applied, then the changes should have been made known to you. If not, then there is potential loss of data if the changes to a bucket resulted in the retention period being shortened in the package.

If you would like to export existing resources into the form of a package, then you have the ability to do so using the following:

resourcesToClone := []ResourceToClone{
	{
		Kind: KindBucket,
		ID:   Existing_BUCKET_ID,
		Name: "new bucket name"
	},
	{
		Kind: KindDashboard,
		ID:   Existing_Dashboard_ID,
	},
	{
		Kind: KindLabel,
		ID:   Existing_Label_ID,
	},
	{
		Kind: KindVarible,
		ID:   Existing_Var_ID,
	},
}

svc := NewService(serviceOpts...)
newPkg, err := svc.CreatePkg(ctx,
	CreateWithMetadata(Metadata{
		Name: 		 "pkg name",
		Description: "stand up desc",
		Version: 	 "v1.0.0",
	}),
	CreateWithExistingResources(resourcesToClone...),
)
if err != nil {
	panic(err) // handle error as you see fit
}
// explore newly created and validated package

Things to note about the behavior of exporting existing resources. All label associations with existing resources will be included in the new package. However, the variables that are used within a dashboard query will not be added automatically to the package. Variables will need to be passed in alongside the dashboard to be added to the package.

Index

Constants

View Source
const APIVersion = "influxdata.com/v2alpha1"

APIVersion marks the current APIVersion for influx packages.

View Source
const RoutePrefix = "/api/v2/packages"

Variables

View Source
var ErrInvalidEncoding = errors.New("invalid encoding provided")

ErrInvalidEncoding indicates the encoding is invalid type for the parser.

Functions

func IsParseErr

func IsParseErr(err error) bool

IsParseErr inspects a given error to determine if it is a parseErr. If a parseErr it is, it will return it along with the confirmation boolean. If the error is not a parseErr it will return nil values for the parseErr, making it unsafe to use.

func NewParseError

func NewParseError(errs ...ValidationErr) error

NewParseError creates a new parse error from existing validation errors.

Types

type ApplyOpt

type ApplyOpt struct {
	EnvRefs        map[string]string
	MissingSecrets map[string]string
}

ApplyOpt is an option for applying a package.

type ApplyOptFn

type ApplyOptFn func(opt *ApplyOpt) error

ApplyOptFn updates the ApplyOpt per the functional option.

func ApplyWithEnvRefs

func ApplyWithEnvRefs(envRefs map[string]string) ApplyOptFn

ApplyWithEnvRefs provides env refs to saturate the missing reference fields in the pkg.

func ApplyWithSecrets

func ApplyWithSecrets(secrets map[string]string) ApplyOptFn

ApplyWithSecrets provides secrets to the platform that the pkg will need.

type CreateOpt

type CreateOpt struct {
	OrgIDs    map[influxdb.ID]bool
	Resources []ResourceToClone
}

CreateOpt are the options for creating a new package.

type CreatePkgSetFn

type CreatePkgSetFn func(opt *CreateOpt) error

CreatePkgSetFn is a functional input for setting the pkg fields.

func CreateWithAllOrgResources

func CreateWithAllOrgResources(orgID influxdb.ID) CreatePkgSetFn

CreateWithAllOrgResources allows the create method to clone all existing resources for the given organization.

func CreateWithExistingResources

func CreateWithExistingResources(resources ...ResourceToClone) CreatePkgSetFn

CreateWithExistingResources allows the create method to clone existing resources.

type Diff

type Diff struct {
	Buckets               []DiffBucket               `json:"buckets"`
	Checks                []DiffCheck                `json:"checks"`
	Dashboards            []DiffDashboard            `json:"dashboards"`
	Labels                []DiffLabel                `json:"labels"`
	LabelMappings         []DiffLabelMapping         `json:"labelMappings"`
	NotificationEndpoints []DiffNotificationEndpoint `json:"notificationEndpoints"`
	NotificationRules     []DiffNotificationRule     `json:"notificationRules"`
	Tasks                 []DiffTask                 `json:"tasks"`
	Telegrafs             []DiffTelegraf             `json:"telegrafConfigs"`
	Variables             []DiffVariable             `json:"variables"`
}

Diff is the result of a service DryRun call. The diff outlines what is new and or updated from the current state of the platform.

func (Diff) HasConflicts

func (d Diff) HasConflicts() bool

HasConflicts provides a binary t/f if there are any changes within package after dry run is complete.

type DiffBucket

type DiffBucket struct {
	ID   SafeID            `json:"id"`
	Name string            `json:"name"`
	New  DiffBucketValues  `json:"new"`
	Old  *DiffBucketValues `json:"old,omitempty"` // using omitempty here to signal there was no prev state with a nil
}

DiffBucket is a diff of an individual bucket.

func (DiffBucket) IsNew

func (d DiffBucket) IsNew() bool

IsNew indicates whether a pkg bucket is going to be new to the platform.

type DiffBucketValues

type DiffBucketValues struct {
	Description    string         `json:"description"`
	RetentionRules retentionRules `json:"retentionRules"`
}

DiffBucketValues are the varying values for a bucket.

type DiffChart

type DiffChart SummaryChart

DiffChart is a diff of oa chart. Since all charts are new right now. the SummaryChart is reused here.

type DiffCheck

type DiffCheck struct {
	ID   SafeID           `json:"id"`
	Name string           `json:"name"`
	New  DiffCheckValues  `json:"new"`
	Old  *DiffCheckValues `json:"old"`
}

DiffCheck is a diff of an individual check.

func (DiffCheck) IsNew

func (d DiffCheck) IsNew() bool

IsNew determines if the check in the pkg is new to the platform.

type DiffCheckValues

type DiffCheckValues struct {
	influxdb.Check
}

DiffCheckValues are the varying values for a check.

func (*DiffCheckValues) UnmarshalJSON

func (d *DiffCheckValues) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON decodes the check values.

type DiffDashboard

type DiffDashboard struct {
	Name   string      `json:"name"`
	Desc   string      `json:"description"`
	Charts []DiffChart `json:"charts"`
}

DiffDashboard is a diff of an individual dashboard. This resource is always new.

type DiffLabel

type DiffLabel struct {
	ID   SafeID           `json:"id"`
	Name string           `json:"name"`
	New  DiffLabelValues  `json:"new"`
	Old  *DiffLabelValues `json:"old,omitempty"` // using omitempty here to signal there was no prev state with a nil
}

DiffLabel is a diff of an individual label.

func (DiffLabel) IsNew

func (d DiffLabel) IsNew() bool

IsNew indicates whether a pkg label is going to be new to the platform.

type DiffLabelMapping

type DiffLabelMapping struct {
	IsNew bool `json:"isNew"`

	ResType influxdb.ResourceType `json:"resourceType"`
	ResID   SafeID                `json:"resourceID"`
	ResName string                `json:"resourceName"`

	LabelID   SafeID `json:"labelID"`
	LabelName string `json:"labelName"`
}

DiffLabelMapping is a diff of an individual label mapping. A single resource may have multiple mappings to multiple labels. A label can have many mappings to other resources.

type DiffLabelValues

type DiffLabelValues struct {
	Color       string `json:"color"`
	Description string `json:"description"`
}

DiffLabelValues are the varying values for a label.

type DiffNotificationEndpoint

type DiffNotificationEndpoint struct {
	ID   SafeID                          `json:"id"`
	Name string                          `json:"name"`
	New  DiffNotificationEndpointValues  `json:"new"`
	Old  *DiffNotificationEndpointValues `json:"old"`
}

DiffNotificationEndpoint is a diff of an individual notification endpoint.

func (DiffNotificationEndpoint) IsNew

func (d DiffNotificationEndpoint) IsNew() bool

IsNew indicates if the resource will be new to the platform or if it edits an existing resource.

type DiffNotificationEndpointValues

type DiffNotificationEndpointValues struct {
	influxdb.NotificationEndpoint
}

DiffNotificationEndpointValues are the varying values for a notification endpoint.

func (*DiffNotificationEndpointValues) UnmarshalJSON

func (d *DiffNotificationEndpointValues) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON decodes the notification endpoint. This is necessary unfortunately.

type DiffNotificationRule

type DiffNotificationRule struct {
	Name        string `json:"name"`
	Description string `json:"description"`

	// These 3 fields represent the relationship of the rule to the endpoint.
	EndpointID   SafeID `json:"endpointID"`
	EndpointName string `json:"endpointName"`
	EndpointType string `json:"endpointType"`

	Every           string              `json:"every"`
	Offset          string              `json:"offset"`
	MessageTemplate string              `json:"messageTemplate"`
	Status          influxdb.Status     `json:"status"`
	StatusRules     []SummaryStatusRule `json:"statusRules"`
	TagRules        []SummaryTagRule    `json:"tagRules"`
}

DiffNotificationRule is a diff of an individual notification rule. This resource is always new.

type DiffTask

type DiffTask struct {
	Name        string          `json:"name"`
	Cron        string          `json:"cron"`
	Description string          `json:"description"`
	Every       string          `json:"every"`
	Offset      string          `json:"offset"`
	Query       string          `json:"query"`
	Status      influxdb.Status `json:"status"`
}

DiffTask is a diff of an individual task. This resource is always new.

type DiffTelegraf

type DiffTelegraf struct {
	influxdb.TelegrafConfig
}

DiffTelegraf is a diff of an individual telegraf. This resource is always new.

type DiffVariable

type DiffVariable struct {
	ID   SafeID              `json:"id"`
	Name string              `json:"name"`
	New  DiffVariableValues  `json:"new"`
	Old  *DiffVariableValues `json:"old,omitempty"` // using omitempty here to signal there was no prev state with a nil
}

DiffVariable is a diff of an individual variable.

func (DiffVariable) IsNew

func (d DiffVariable) IsNew() bool

IsNew indicates whether a pkg variable is going to be new to the platform.

type DiffVariableValues

type DiffVariableValues struct {
	Description string                      `json:"description"`
	Args        *influxdb.VariableArguments `json:"args"`
}

DiffVariableValues are the varying values for a variable.

type Encoder

type Encoder interface {
	Encode(v interface{}) error
}

Encoder is an encodes a type.

type Encoding

type Encoding int

Encoding describes the encoding for the raw package data. The encoding determines how the raw data is parsed.

const (
	EncodingUnknown Encoding = iota
	EncodingJSON
	EncodingJsonnet
	EncodingSource // EncodingSource draws the encoding type by inferring it from the source.
	EncodingYAML
)

encoding types

func (Encoding) String

func (e Encoding) String() string

String provides the string representation of the encoding.

type HTTPRemoteService

type HTTPRemoteService struct {
	Client *httpc.Client
}

HTTPRemoteService provides an http client that is fluent in all things pkger.

func (*HTTPRemoteService) Apply

func (s *HTTPRemoteService) Apply(ctx context.Context, orgID, userID influxdb.ID, pkg *Pkg, opts ...ApplyOptFn) (Summary, error)

Apply will apply all the resources identified in the provided pkg. The entire pkg will be applied in its entirety. If a failure happens midway then the entire pkg will be rolled back to the state from before the pkg was applied.

func (*HTTPRemoteService) CreatePkg

func (s *HTTPRemoteService) CreatePkg(ctx context.Context, setters ...CreatePkgSetFn) (*Pkg, error)

CreatePkg will produce a pkg from the parameters provided.

func (*HTTPRemoteService) DryRun

func (s *HTTPRemoteService) DryRun(ctx context.Context, orgID, userID influxdb.ID, pkg *Pkg, opts ...ApplyOptFn) (Summary, Diff, error)

DryRun provides a dry run of the pkg application. The pkg will be marked verified for later calls to Apply. This func will be run on an Apply if it has not been run already.

type HTTPServer

type HTTPServer struct {
	chi.Router
	// contains filtered or unexported fields
}

HTTPServer is a server that manages the packages HTTP transport.

func NewHTTPServer

func NewHTTPServer(log *zap.Logger, svc SVC) *HTTPServer

NewHTTPServer constructs a new http server.

func (*HTTPServer) Prefix

func (s *HTTPServer) Prefix() string

Prefix provides the prefix to this route tree.

type Kind

type Kind string

Kind is a resource kind.

const (
	KindUnknown                       Kind = ""
	KindBucket                        Kind = "Bucket"
	KindCheck                         Kind = "Check"
	KindCheckDeadman                  Kind = "CheckDeadman"
	KindCheckThreshold                Kind = "CheckThreshold"
	KindDashboard                     Kind = "Dashboard"
	KindLabel                         Kind = "Label"
	KindNotificationEndpoint          Kind = "NotificationEndpoint"
	KindNotificationEndpointHTTP      Kind = "NotificationEndpointHTTP"
	KindNotificationEndpointPagerDuty Kind = "NotificationEndpointPagerDuty"
	KindNotificationEndpointSlack     Kind = "NotificationEndpointSlack"
	KindNotificationRule              Kind = "NotificationRule"
	KindPackage                       Kind = "Package"
	KindTask                          Kind = "Task"
	KindTelegraf                      Kind = "Telegraf"
	KindVariable                      Kind = "Variable"
)

Package kind types.

func (Kind) OK

func (k Kind) OK() error

OK validates the kind is valid.

func (Kind) ResourceType

func (k Kind) ResourceType() influxdb.ResourceType

ResourceType converts a kind to a known resource type (if applicable).

func (Kind) String

func (k Kind) String() string

String provides the kind in human readable form.

type Object

type Object struct {
	APIVersion string   `json:"apiVersion" yaml:"apiVersion"`
	Type       Kind     `json:"kind" yaml:"kind"`
	Metadata   Resource `json:"metadata" yaml:"metadata"`
	Spec       Resource `json:"spec" yaml:"spec"`
}

Object describes the metadata and raw spec for an entity of a package kind.

func DashboardToObject

func DashboardToObject(dash influxdb.Dashboard, name string) Object

DashboardToObject converts an influxdb.Dashboard to a pkger.Resource.

func VariableToObject

func VariableToObject(v influxdb.Variable, name string) Object

VariableToObject converts an influxdb.Variable to a pkger.Object.

func (Object) Name

func (k Object) Name() string

Name returns the name of the kind.

type ParseError

type ParseError interface {
	ValidationErrs() []ValidationErr
}

ParseError is the error from parsing the given package. The ParseError behavior provides a list of resources that failed and all validations that failed for that resource. A resource can multiple errors, and a parseErr can have multiple resources which themselves can have multiple validation failures.

type Pkg

type Pkg struct {
	Objects []Object `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

Pkg is the model for a package. The resources are more generic that one might expect at first glance. This was done on purpose. The way json/yaml/toml or w/e scripting you want to use, can have very different ways of parsing. The different parsers are limited for the parsers that do not come from the std lib (looking at you yaml/v2). This allows us to parse it and leave the matching to another power, the graphing of the package is handled within itself.

func Combine

func Combine(pkgs ...*Pkg) (*Pkg, error)

Combine combines pkgs together. Is useful when you want to take multiple disparate pkgs and compile them into one to take advantage of the parser and service guarantees.

func Parse

func Parse(encoding Encoding, readerFn ReaderFn, opts ...ValidateOptFn) (*Pkg, error)

Parse parses a pkg defined by the encoding and readerFns. As of writing this we can parse both a YAML, JSON, and Jsonnet formats of the Pkg model.

func (*Pkg) Encode

func (p *Pkg) Encode(encoding Encoding) ([]byte, error)

Encode is a helper for encoding the pkg correctly.

func (*Pkg) Summary

func (p *Pkg) Summary() Summary

Summary returns a package Summary that describes all the resources and associations the pkg contains. It is very useful for informing users of the changes that will take place when this pkg would be applied.

func (*Pkg) Validate

func (p *Pkg) Validate(opts ...ValidateOptFn) error

Validate will graph all resources and validate every thing is in a useful form.

type PkgRemote

type PkgRemote struct {
	URL         string `json:"url"`
	ContentType string `json:"contentType"`
}

PkgRemote provides a package via a remote (i.e. a gist). If content type is not provided then the service will do its best to discern the content type of the contents.

func (PkgRemote) Encoding

func (p PkgRemote) Encoding() Encoding

Encoding returns the encoding type that corresponds to the given content type.

type ReaderFn

type ReaderFn func() (io.Reader, error)

ReaderFn is used for functional inputs to abstract the individual entrypoints for the reader itself.

func FromFile

func FromFile(filePath string) ReaderFn

FromFile reads a file from disk and provides a reader from it.

func FromHTTPRequest

func FromHTTPRequest(addr string) ReaderFn

FromHTTPRequest parses a pkg from the request body of a HTTP request. This is very useful when using packages that are hosted..

func FromReader

func FromReader(r io.Reader) ReaderFn

FromReader simply passes the reader along. Useful when consuming this from an HTTP request body. There are a number of other useful places for this functional input.

func FromString

func FromString(s string) ReaderFn

FromString parses a pkg from a raw string value. This is very useful in tests.

type ReqApplyPkg

type ReqApplyPkg struct {
	DryRun  bool              `json:"dryRun" yaml:"dryRun"`
	OrgID   string            `json:"orgID" yaml:"orgID"`
	Remotes []PkgRemote       `json:"remotes" yaml:"remotes"`
	RawPkgs []json.RawMessage `json:"packages" yaml:"packages"`
	RawPkg  json.RawMessage   `json:"package" yaml:"package"`
	EnvRefs map[string]string `json:"envRefs"`
	Secrets map[string]string `json:"secrets"`
}

ReqApplyPkg is the request body for a json or yaml body for the apply pkg endpoint.

func (ReqApplyPkg) Pkgs

func (r ReqApplyPkg) Pkgs(encoding Encoding) (*Pkg, error)

Pkgs returns all pkgs associated with the request.

type ReqCreatePkg

type ReqCreatePkg struct {
	OrgIDs    []string          `json:"orgIDs"`
	Resources []ResourceToClone `json:"resources"`
}

ReqCreatePkg is a request body for the create pkg endpoint.

type Resource

type Resource map[string]interface{}

Resource is a pkger Resource kind. It can be one of any of available kinds that are supported.

func (Resource) Name

func (r Resource) Name() string

Name returns the name of the resource.

type ResourceToClone

type ResourceToClone struct {
	Kind Kind        `json:"kind"`
	ID   influxdb.ID `json:"id"`
	Name string      `json:"name"`
}

ResourceToClone is a resource that will be cloned.

func (ResourceToClone) OK

func (r ResourceToClone) OK() error

OK validates a resource clone is viable.

type RespApplyPkg

type RespApplyPkg struct {
	Diff    Diff    `json:"diff" yaml:"diff"`
	Summary Summary `json:"summary" yaml:"summary"`

	Errors []ValidationErr `json:"errors,omitempty" yaml:"errors,omitempty"`
}

RespApplyPkg is the response body for the apply pkg endpoint.

type RespCreatePkg

type RespCreatePkg []Object

RespCreatePkg is a response body for the create pkg endpoint.

type SVC

type SVC interface {
	CreatePkg(ctx context.Context, setters ...CreatePkgSetFn) (*Pkg, error)
	DryRun(ctx context.Context, orgID, userID influxdb.ID, pkg *Pkg, opts ...ApplyOptFn) (Summary, Diff, error)
	Apply(ctx context.Context, orgID, userID influxdb.ID, pkg *Pkg, opts ...ApplyOptFn) (Summary, error)
}

SVC is the packages service interface.

type SVCMiddleware

type SVCMiddleware func(SVC) SVC

SVCMiddleware is a service middleware func.

func MWLogging

func MWLogging(log *zap.Logger) SVCMiddleware

MWLogging adds logging functionality for the service.

func MWMetrics

func MWMetrics(reg *prom.Registry) SVCMiddleware

MWMetrics is a metrics service middleware for the notification endpoint service.

func MWTracing

func MWTracing() SVCMiddleware

MWTracing adds tracing functionality for the service.

type SafeID

type SafeID influxdb.ID

SafeID is an equivalent influxdb.ID that encodes safely with zero values (influxdb.ID == 0).

func (SafeID) Encode

func (s SafeID) Encode() ([]byte, error)

Encode will safely encode the id.

func (SafeID) String

func (s SafeID) String() string

String prints a encoded string representation of the id.

type Service

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

Service provides the pkger business logic including all the dependencies to make this resource sausage.

func NewService

func NewService(opts ...ServiceSetterFn) *Service

NewService is a constructor for a pkger Service.

func (*Service) Apply

func (s *Service) Apply(ctx context.Context, orgID, userID influxdb.ID, pkg *Pkg, opts ...ApplyOptFn) (sum Summary, e error)

Apply will apply all the resources identified in the provided pkg. The entire pkg will be applied in its entirety. If a failure happens midway then the entire pkg will be rolled back to the state from before the pkg were applied.

func (*Service) CreatePkg

func (s *Service) CreatePkg(ctx context.Context, setters ...CreatePkgSetFn) (*Pkg, error)

CreatePkg will produce a pkg from the parameters provided.

func (*Service) DryRun

func (s *Service) DryRun(ctx context.Context, orgID, userID influxdb.ID, pkg *Pkg, opts ...ApplyOptFn) (Summary, Diff, error)

DryRun provides a dry run of the pkg application. The pkg will be marked verified for later calls to Apply. This func will be run on an Apply if it has not been run already.

type ServiceSetterFn

type ServiceSetterFn func(opt *serviceOpt)

ServiceSetterFn is a means of setting dependencies on the Service type.

func WithBucketSVC

func WithBucketSVC(bktSVC influxdb.BucketService) ServiceSetterFn

WithBucketSVC sets the bucket service.

func WithCheckSVC

func WithCheckSVC(checkSVC influxdb.CheckService) ServiceSetterFn

WithCheckSVC sets the check service.

func WithDashboardSVC

func WithDashboardSVC(dashSVC influxdb.DashboardService) ServiceSetterFn

WithDashboardSVC sets the dashboard service.

func WithLabelSVC

func WithLabelSVC(labelSVC influxdb.LabelService) ServiceSetterFn

WithLabelSVC sets the label service.

func WithLogger

func WithLogger(log *zap.Logger) ServiceSetterFn

WithLogger sets the logger for the service.

func WithNotificationEndpointSVC

func WithNotificationEndpointSVC(endpointSVC influxdb.NotificationEndpointService) ServiceSetterFn

WithNotificationEndpointSVC sets the endpoint notification service.

func WithNotificationRuleSVC

func WithNotificationRuleSVC(ruleSVC influxdb.NotificationRuleStore) ServiceSetterFn

WithNotificationRuleSVC sets the endpoint rule service.

func WithSecretSVC

func WithSecretSVC(secretSVC influxdb.SecretService) ServiceSetterFn

WithSecretSVC sets the secret service.

func WithTaskSVC

func WithTaskSVC(taskSVC influxdb.TaskService) ServiceSetterFn

WithTaskSVC sets the task service.

func WithTelegrafSVC

func WithTelegrafSVC(telegrafSVC influxdb.TelegrafConfigStore) ServiceSetterFn

WithTelegrafSVC sets the telegraf service.

func WithVariableSVC

func WithVariableSVC(varSVC influxdb.VariableService) ServiceSetterFn

WithVariableSVC sets the variable service.

type Summary

type Summary struct {
	Buckets               []SummaryBucket               `json:"buckets"`
	Checks                []SummaryCheck                `json:"checks"`
	Dashboards            []SummaryDashboard            `json:"dashboards"`
	NotificationEndpoints []SummaryNotificationEndpoint `json:"notificationEndpoints"`
	NotificationRules     []SummaryNotificationRule     `json:"notificationRules"`
	Labels                []SummaryLabel                `json:"labels"`
	LabelMappings         []SummaryLabelMapping         `json:"labelMappings"`
	MissingEnvs           []string                      `json:"missingEnvRefs"`
	MissingSecrets        []string                      `json:"missingSecrets"`
	Tasks                 []SummaryTask                 `json:"summaryTask"`
	TelegrafConfigs       []SummaryTelegraf             `json:"telegrafConfigs"`
	Variables             []SummaryVariable             `json:"variables"`
}

Summary is a definition of all the resources that have or will be created from a pkg.

type SummaryBucket

type SummaryBucket struct {
	ID          SafeID `json:"id,omitempty"`
	OrgID       SafeID `json:"orgID,omitempty"`
	Name        string `json:"name"`
	Description string `json:"description"`
	// TODO: return retention rules?
	RetentionPeriod   time.Duration  `json:"retentionPeriod"`
	LabelAssociations []SummaryLabel `json:"labelAssociations"`
}

SummaryBucket provides a summary of a pkg bucket.

type SummaryChart

type SummaryChart struct {
	Properties influxdb.ViewProperties `json:"-"`

	XPosition int `json:"xPos"`
	YPosition int `json:"yPos"`
	Height    int `json:"height"`
	Width     int `json:"width"`
}

SummaryChart provides a summary of a pkg dashboard's chart.

func (*SummaryChart) MarshalJSON

func (s *SummaryChart) MarshalJSON() ([]byte, error)

MarshalJSON marshals a summary chart.

func (*SummaryChart) UnmarshalJSON

func (s *SummaryChart) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a view properities and other data.

type SummaryCheck

type SummaryCheck struct {
	Check             influxdb.Check  `json:"check"`
	Status            influxdb.Status `json:"status"`
	LabelAssociations []SummaryLabel  `json:"labelAssociations"`
}

SummaryCheck provides a summary of a pkg check.

func (*SummaryCheck) UnmarshalJSON

func (s *SummaryCheck) UnmarshalJSON(b []byte) error

type SummaryDashboard

type SummaryDashboard struct {
	ID          SafeID         `json:"id"`
	OrgID       SafeID         `json:"orgID"`
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Charts      []SummaryChart `json:"charts"`

	LabelAssociations []SummaryLabel `json:"labelAssociations"`
}

SummaryDashboard provides a summary of a pkg dashboard.

type SummaryLabel

type SummaryLabel struct {
	ID         SafeID `json:"id"`
	OrgID      SafeID `json:"orgID"`
	Name       string `json:"name"`
	Properties struct {
		Color       string `json:"color"`
		Description string `json:"description"`
	} `json:"properties"`
}

SummaryLabel provides a summary of a pkg label.

type SummaryLabelMapping

type SummaryLabelMapping struct {
	ResourceID   SafeID                `json:"resourceID"`
	ResourceName string                `json:"resourceName"`
	ResourceType influxdb.ResourceType `json:"resourceType"`
	LabelName    string                `json:"labelName"`
	LabelID      SafeID                `json:"labelID"`
	// contains filtered or unexported fields
}

SummaryLabelMapping provides a summary of a label mapped with a single resource.

type SummaryNotificationEndpoint

type SummaryNotificationEndpoint struct {
	NotificationEndpoint influxdb.NotificationEndpoint `json:"notificationEndpoint"`
	LabelAssociations    []SummaryLabel                `json:"labelAssociations"`
}

SummaryNotificationEndpoint provides a summary of a pkg notification endpoint.

func (*SummaryNotificationEndpoint) UnmarshalJSON

func (s *SummaryNotificationEndpoint) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the notificatio endpoint. This is necessary b/c of the notification endpoint does not have a means ot unmarshal itself.

type SummaryNotificationRule

type SummaryNotificationRule struct {
	ID          SafeID `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`

	// These 3 fields represent the relationship of the rule to the endpoint.
	EndpointID   SafeID `json:"endpointID"`
	EndpointName string `json:"endpointName"`
	EndpointType string `json:"endpointType"`

	Every             string              `json:"every"`
	LabelAssociations []SummaryLabel      `json:"labelAssociations"`
	Offset            string              `json:"offset"`
	MessageTemplate   string              `json:"messageTemplate"`
	Status            influxdb.Status     `json:"status"`
	StatusRules       []SummaryStatusRule `json:"statusRules"`
	TagRules          []SummaryTagRule    `json:"tagRules"`
}

Summary types for NotificationRules which provide a summary of a pkg notification rule.

type SummaryStatusRule

type SummaryStatusRule struct {
	CurrentLevel  string `json:"currentLevel"`
	PreviousLevel string `json:"previousLevel"`
}

Summary types for NotificationRules which provide a summary of a pkg notification rule.

type SummaryTagRule

type SummaryTagRule struct {
	Key      string `json:"key"`
	Value    string `json:"value"`
	Operator string `json:"operator"`
}

Summary types for NotificationRules which provide a summary of a pkg notification rule.

type SummaryTask

type SummaryTask struct {
	ID          SafeID          `json:"id"`
	Name        string          `json:"name"`
	Cron        string          `json:"cron"`
	Description string          `json:"description"`
	Every       string          `json:"every"`
	Offset      string          `json:"offset"`
	Query       string          `json:"query"`
	Status      influxdb.Status `json:"status"`

	LabelAssociations []SummaryLabel `json:"labelAssociations"`
}

SummaryTask provides a summary of a task.

type SummaryTelegraf

type SummaryTelegraf struct {
	TelegrafConfig    influxdb.TelegrafConfig `json:"telegrafConfig"`
	LabelAssociations []SummaryLabel          `json:"labelAssociations"`
}

SummaryTelegraf provides a summary of a pkg telegraf config.

type SummaryVariable

type SummaryVariable struct {
	ID                SafeID                      `json:"id,omitempty"`
	OrgID             SafeID                      `json:"orgID,omitempty"`
	Name              string                      `json:"name"`
	Description       string                      `json:"description"`
	Arguments         *influxdb.VariableArguments `json:"arguments"`
	LabelAssociations []SummaryLabel              `json:"labelAssociations"`
}

SummaryVariable provides a summary of a pkg variable.

type ValidateOptFn

type ValidateOptFn func(*validateOpt)

ValidateOptFn provides a means to disable desired validation checks.

func ValidSkipParseError

func ValidSkipParseError() ValidateOptFn

ValidSkipParseError ignores the validation check from the of resources. This is useful for the service Create to ignore this and allow the creation of a pkg without resources.

func ValidWithoutResources

func ValidWithoutResources() ValidateOptFn

ValidWithoutResources ignores the validation check for minimum number of resources. This is useful for the service Create to ignore this and allow the creation of a pkg without resources.

type ValidationErr

type ValidationErr struct {
	Kind    string   `json:"kind" yaml:"kind"`
	Fields  []string `json:"fields" yaml:"fields"`
	Indexes []*int   `json:"idxs" yaml:"idxs"`
	Reason  string   `json:"reason" yaml:"reason"`
}

ValidationErr represents an error during the parsing of a package.

func (ValidationErr) Error

func (v ValidationErr) Error() string

Jump to

Keyboard shortcuts

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