influxdb/source.go

123 lines
4.5 KiB
Go
Raw Normal View History

package platform
feat(platform): add uniform query endpoint for sources Using query request struct to query resources Signed-off-by: Lorenzo Fontana <lo@linux.com> Use query.ProxyRequest instead query.Request Signed-off-by: Lorenzo Fontana <lo@linux.com> Proxy request from idpd Signed-off-by: Lorenzo Fontana <lo@linux.com> Comments about the desired results Signed-off-by: Lorenzo Fontana <lo@linux.com> V1 endpoints working with flux Signed-off-by: Lorenzo Fontana <lo@linux.com> Influxql working for v1 Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> V2 influxql query endpoint working Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> Signed-off-by: Lorenzo Fontana <lo@linux.com> V2 Flux compiler support Co-authored-by: Michael De Sa <mjdesa@gmail.com> Signed-off-by: Lorenzo Fontana <lo@linux.com> Improve comments in bolt sources and give error on self Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> Review tests failing Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> Avoid type casts for compiler types Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> Using nil instead of dbrp mapping service for influxql v1 Signed-off-by: Lorenzo Fontana <lo@linux.com> Check if compiler types are valid for influxql Signed-off-by: Lorenzo Fontana <lo@linux.com> Organization as query param in the flux external handler Signed-off-by: Lorenzo Fontana <lo@linux.com> feat(http): update swagger documentation for flux query endpoint feat(http): document query endpoint design The code documented does not currently work. It is indended that this will be implemented in follow up PRs. feat(platform): move source to platform package The source Query endpoint implements what's in the query swagger docs Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> feat(platform): allow for encoding and decoding of csv dialects feat(platform): specify dialect in flux page Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com>
2018-08-28 19:53:20 +00:00
import "context"
const (
2018-08-27 17:09:17 +00:00
ErrSourceNotFound = ChronografError("source not found")
)
// SourceType is a string for types of sources.
type SourceType string
const (
V2SourceType = "v2"
V1SourceType = "v1"
SelfSourceType = "self"
)
// Source is an external Influx with time series data.
// TODO(desa): do we still need default?
// TODO(desa): do sources belong
type Source struct {
ID ID `json:"id,string"` // ID is the unique ID of the source
OrganizationID ID `json:"organizationID"` // OrganizationID is the organization ID that resource belongs to
Default bool `json:"default"` // Default specifies the default source for the application
Name string `json:"name"` // Name is the user-defined name for the source
Type SourceType `json:"type,omitempty"` // Type specifies which kinds of source (enterprise vs oss vs 2.0)
URL string `json:"url"` // URL are the connections to the source
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"` // InsecureSkipVerify as true means any certificate presented by the source is accepted
Telegraf string `json:"telegraf"` // Telegraf is the db telegraf is written to. By default it is "telegraf"
SourceFields
V1SourceFields
}
// V1SourceFields are the fields for connecting to a 1.0 source (oss or enterprise)
type V1SourceFields struct {
Username string `json:"username,omitempty"` // Username is the username to connect to the source
Password string `json:"password,omitempty"` // Password is in CLEARTEXT
SharedSecret string `json:"sharedSecret,omitempty"` // ShareSecret is the optional signing secret for Influx JWT authorization
MetaURL string `json:"metaUrl,omitempty"` // MetaURL is the url for the meta node
DefaultRP string `json:"defaultRP"` // DefaultRP is the default retention policy used in database queries to this source
FluxURL string `json:"fluxURL,omitempty"` // FluxURL is the url for a flux connected to a 1x source
}
// SourceFields
type SourceFields struct {
Token string `json:"token"` // Token is the 2.0 authorization token associated with a source
}
// SourceService is a service for managing sources.
type SourceService interface {
// DefaultSource retrieves the default source.
DefaultSource(ctx context.Context) (*Source, error)
// FindSourceByID retrieves a source by its ID.
FindSourceByID(ctx context.Context, id ID) (*Source, error)
// FindSources returns a list of all sources.
FindSources(ctx context.Context, opts FindOptions) ([]*Source, int, error)
// CreateSource sets the sources ID and stores it.
CreateSource(ctx context.Context, s *Source) error
// UpdateSource updates the source.
UpdateSource(ctx context.Context, id ID, upd SourceUpdate) (*Source, error)
// DeleteSource removes the source.
DeleteSource(ctx context.Context, id ID) error
}
// SourceUpdate represents updates to a source.
type SourceUpdate struct {
Name *string `json:"name"`
Type *SourceType `json:"type,omitempty"`
Token *string `json:"token"`
URL *string `json:"url"`
InsecureSkipVerify *bool `json:"insecureSkipVerify,omitempty"`
Telegraf *string `json:"telegraf"`
Username *string `json:"username,omitempty"`
Password *string `json:"password,omitempty"`
SharedSecret *string `json:"sharedSecret,omitempty"`
MetaURL *string `json:"metaURL,omitempty"`
FluxURL *string `json:"fluxURL,omitempty"`
Role *string `json:"role,omitempty"`
DefaultRP *string `json:"defaultRP"`
}
// Apply applies an update to a source.
func (u SourceUpdate) Apply(s *Source) error {
if u.Name != nil {
s.Name = *u.Name
}
if u.Type != nil {
s.Type = *u.Type
}
if u.Token != nil {
s.Token = *u.Token
}
if u.URL != nil {
s.URL = *u.URL
}
if u.InsecureSkipVerify != nil {
s.InsecureSkipVerify = *u.InsecureSkipVerify
}
if u.Telegraf != nil {
s.Telegraf = *u.Telegraf
}
if u.Username != nil {
s.Username = *u.Username
}
if u.Password != nil {
s.Password = *u.Password
}
if u.SharedSecret != nil {
s.SharedSecret = *u.SharedSecret
}
if u.MetaURL != nil {
s.MetaURL = *u.MetaURL
}
if u.FluxURL != nil {
s.FluxURL = *u.FluxURL
}
if u.DefaultRP != nil {
s.DefaultRP = *u.DefaultRP
}
return nil
}