2018-07-26 17:14:31 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2018-07-31 22:50:02 +00:00
|
|
|
"fmt"
|
2018-07-26 17:14:31 +00:00
|
|
|
"net/http"
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
"time"
|
2018-07-26 17:14:31 +00:00
|
|
|
|
2018-09-06 18:09:52 +00:00
|
|
|
"github.com/influxdata/flux/csv"
|
2018-09-11 22:56:51 +00:00
|
|
|
"github.com/influxdata/flux/lang"
|
2019-11-25 14:22:19 +00:00
|
|
|
"github.com/influxdata/httprouter"
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
2021-09-13 19:12:35 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform"
|
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/pkg/httpc"
|
|
|
|
"github.com/influxdata/influxdb/v2/query"
|
2019-01-08 00:37:16 +00:00
|
|
|
"go.uber.org/zap"
|
2018-07-26 17:14:31 +00:00
|
|
|
)
|
|
|
|
|
2018-07-31 22:50:02 +00:00
|
|
|
const (
|
2019-12-09 23:54:16 +00:00
|
|
|
prefixSources = "/api/v2/sources"
|
2018-07-31 22:50:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type sourceResponse struct {
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
*influxdb.Source
|
2018-07-31 22:50:02 +00:00
|
|
|
Links map[string]interface{} `json:"links"`
|
|
|
|
}
|
|
|
|
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
func newSourceResponse(s *influxdb.Source) *sourceResponse {
|
2018-07-31 22:50:02 +00:00
|
|
|
s.Password = ""
|
|
|
|
s.SharedSecret = ""
|
2018-11-16 00:03:15 +00:00
|
|
|
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
if s.Type == influxdb.SelfSourceType {
|
2018-11-16 00:03:15 +00:00
|
|
|
return &sourceResponse{
|
|
|
|
Source: s,
|
|
|
|
Links: map[string]interface{}{
|
2019-12-09 23:54:16 +00:00
|
|
|
"self": fmt.Sprintf("%s/%s", prefixSources, s.ID.String()),
|
|
|
|
"query": fmt.Sprintf("%s/%s/query", prefixSources, s.ID.String()),
|
|
|
|
"buckets": fmt.Sprintf("%s/%s/buckets", prefixSources, s.ID.String()),
|
|
|
|
"health": fmt.Sprintf("%s/%s/health", prefixSources, s.ID.String()),
|
2018-11-16 00:03:15 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 22:50:02 +00:00
|
|
|
return &sourceResponse{
|
|
|
|
Source: s,
|
|
|
|
Links: map[string]interface{}{
|
2019-12-09 23:54:16 +00:00
|
|
|
"self": fmt.Sprintf("%s/%s", prefixSources, s.ID.String()),
|
|
|
|
"query": fmt.Sprintf("%s/%s/query", prefixSources, s.ID.String()),
|
|
|
|
"buckets": fmt.Sprintf("%s/%s/buckets", prefixSources, s.ID.String()),
|
|
|
|
"health": fmt.Sprintf("%s/%s/health", prefixSources, s.ID.String()),
|
2018-07-31 22:50:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type sourcesResponse struct {
|
|
|
|
Sources []*sourceResponse `json:"sources"`
|
|
|
|
Links map[string]interface{} `json:"links"`
|
|
|
|
}
|
|
|
|
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
func newSourcesResponse(srcs []*influxdb.Source) *sourcesResponse {
|
2018-07-31 22:50:02 +00:00
|
|
|
res := &sourcesResponse{
|
|
|
|
Links: map[string]interface{}{
|
2019-12-09 23:54:16 +00:00
|
|
|
"self": prefixSources,
|
2018-07-31 22:50:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Sources = make([]*sourceResponse, 0, len(srcs))
|
|
|
|
for _, src := range srcs {
|
|
|
|
res.Sources = append(res.Sources, newSourceResponse(src))
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2019-01-16 12:57:33 +00:00
|
|
|
// SourceBackend is all services and associated parameters required to construct
|
|
|
|
// the SourceHandler.
|
|
|
|
type SourceBackend struct {
|
2021-03-30 18:10:02 +00:00
|
|
|
errors.HTTPErrorHandler
|
2019-12-04 23:10:23 +00:00
|
|
|
log *zap.Logger
|
2019-01-16 12:57:33 +00:00
|
|
|
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
SourceService influxdb.SourceService
|
|
|
|
LabelService influxdb.LabelService
|
|
|
|
BucketService influxdb.BucketService
|
|
|
|
NewQueryService func(s *influxdb.Source) (query.ProxyQueryService, error)
|
2019-01-16 12:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewSourceBackend returns a new instance of SourceBackend.
|
2019-12-04 23:10:23 +00:00
|
|
|
func NewSourceBackend(log *zap.Logger, b *APIBackend) *SourceBackend {
|
2019-01-16 12:57:33 +00:00
|
|
|
return &SourceBackend{
|
2019-06-27 01:33:20 +00:00
|
|
|
HTTPErrorHandler: b.HTTPErrorHandler,
|
2019-12-04 23:10:23 +00:00
|
|
|
log: log,
|
2019-01-16 12:57:33 +00:00
|
|
|
|
2019-03-18 15:48:00 +00:00
|
|
|
SourceService: b.SourceService,
|
|
|
|
LabelService: b.LabelService,
|
|
|
|
BucketService: b.BucketService,
|
|
|
|
NewQueryService: b.NewQueryService,
|
2019-01-16 12:57:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 17:14:31 +00:00
|
|
|
// SourceHandler is a handler for sources
|
|
|
|
type SourceHandler struct {
|
|
|
|
*httprouter.Router
|
2021-03-30 18:10:02 +00:00
|
|
|
errors.HTTPErrorHandler
|
2019-12-04 23:10:23 +00:00
|
|
|
log *zap.Logger
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
SourceService influxdb.SourceService
|
|
|
|
LabelService influxdb.LabelService
|
|
|
|
BucketService influxdb.BucketService
|
2018-08-28 19:53:20 +00:00
|
|
|
|
|
|
|
// TODO(desa): this was done so in order to remove an import cycle and to allow
|
|
|
|
// for http mocking.
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
NewQueryService func(s *influxdb.Source) (query.ProxyQueryService, error)
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewSourceHandler returns a new instance of SourceHandler.
|
2019-12-04 23:10:23 +00:00
|
|
|
func NewSourceHandler(log *zap.Logger, b *SourceBackend) *SourceHandler {
|
2018-07-26 17:14:31 +00:00
|
|
|
h := &SourceHandler{
|
2019-06-27 01:33:20 +00:00
|
|
|
Router: NewRouter(b.HTTPErrorHandler),
|
|
|
|
HTTPErrorHandler: b.HTTPErrorHandler,
|
2019-12-04 23:10:23 +00:00
|
|
|
log: log,
|
2019-01-16 12:57:33 +00:00
|
|
|
|
2019-03-18 15:48:00 +00:00
|
|
|
SourceService: b.SourceService,
|
|
|
|
LabelService: b.LabelService,
|
|
|
|
BucketService: b.BucketService,
|
|
|
|
NewQueryService: b.NewQueryService,
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 23:54:16 +00:00
|
|
|
h.HandlerFunc("POST", prefixSources, h.handlePostSource)
|
2018-09-26 08:49:19 +00:00
|
|
|
h.HandlerFunc("GET", "/api/v2/sources", h.handleGetSources)
|
|
|
|
h.HandlerFunc("GET", "/api/v2/sources/:id", h.handleGetSource)
|
|
|
|
h.HandlerFunc("PATCH", "/api/v2/sources/:id", h.handlePatchSource)
|
|
|
|
h.HandlerFunc("DELETE", "/api/v2/sources/:id", h.handleDeleteSource)
|
2018-07-30 18:35:04 +00:00
|
|
|
|
2018-09-26 08:49:19 +00:00
|
|
|
h.HandlerFunc("GET", "/api/v2/sources/:id/buckets", h.handleGetSourcesBuckets)
|
|
|
|
h.HandlerFunc("POST", "/api/v2/sources/:id/query", h.handlePostSourceQuery)
|
|
|
|
h.HandlerFunc("GET", "/api/v2/sources/:id/health", h.handleGetSourceHealth)
|
2018-08-28 19:53:20 +00:00
|
|
|
|
2018-07-26 17:14:31 +00:00
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
2018-09-11 22:56:51 +00:00
|
|
|
func decodeSourceQueryRequest(r *http.Request) (*query.ProxyRequest, error) {
|
2018-08-28 19:53:20 +00:00
|
|
|
// starts here
|
|
|
|
request := struct {
|
|
|
|
Query string `json:"query"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
DB string `json:"db"`
|
|
|
|
RP string `json:"rp"`
|
|
|
|
Cluster string `json:"cluster"`
|
2021-03-30 18:10:02 +00:00
|
|
|
OrganizationID platform.ID `json:"organizationID"`
|
2018-08-28 19:53:20 +00:00
|
|
|
// TODO(desa): support influxql dialect
|
|
|
|
Dialect csv.Dialect `json:"dialect"`
|
|
|
|
}{}
|
|
|
|
|
|
|
|
err := json.NewDecoder(r.Body).Decode(&request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-09-11 22:56:51 +00:00
|
|
|
req := &query.ProxyRequest{}
|
2018-08-28 19:53:20 +00:00
|
|
|
req.Dialect = request.Dialect
|
|
|
|
|
|
|
|
req.Request.OrganizationID = request.OrganizationID
|
|
|
|
|
|
|
|
switch request.Type {
|
2018-09-11 22:56:51 +00:00
|
|
|
case lang.FluxCompilerType:
|
|
|
|
req.Request.Compiler = lang.FluxCompiler{
|
2018-08-28 19:53:20 +00:00
|
|
|
Query: request.Query,
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("compiler type not supported")
|
|
|
|
}
|
|
|
|
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2018-09-26 08:49:19 +00:00
|
|
|
// handlePostSourceQuery is the HTTP handler for POST /api/v2/sources/:id/query
|
2018-07-31 22:50:02 +00:00
|
|
|
func (h *SourceHandler) handlePostSourceQuery(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := r.Context()
|
2018-08-28 19:53:20 +00:00
|
|
|
gsr, err := decodeGetSourceRequest(ctx, r)
|
2018-07-31 22:50:02 +00:00
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-31 22:50:02 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-28 19:53:20 +00:00
|
|
|
req, err := decodeSourceQueryRequest(r)
|
2018-07-31 22:50:02 +00:00
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-31 22:50:02 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-28 19:53:20 +00:00
|
|
|
s, err := h.SourceService.FindSourceByID(ctx, gsr.SourceID)
|
2018-07-31 22:50:02 +00:00
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-31 22:50:02 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-28 19:53:20 +00:00
|
|
|
querySvc, err := h.NewQueryService(s)
|
2018-07-31 22:50:02 +00:00
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-08-28 19:53:20 +00:00
|
|
|
return
|
2018-07-31 22:50:02 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 19:53:20 +00:00
|
|
|
_, err = querySvc.Query(ctx, w, req)
|
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-08-28 19:53:20 +00:00
|
|
|
return
|
2018-07-31 22:50:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-26 08:49:19 +00:00
|
|
|
// handleGetSourcesBuckets is the HTTP handler for the GET /api/v2/sources/:id/buckets route.
|
2018-07-30 18:35:04 +00:00
|
|
|
func (h *SourceHandler) handleGetSourcesBuckets(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := r.Context()
|
|
|
|
|
|
|
|
req, err := decodeGetSourceBucketsRequest(ctx, r)
|
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-30 18:35:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:03:24 +00:00
|
|
|
_, err = h.SourceService.FindSourceByID(ctx, req.getSourceRequest.SourceID)
|
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2019-03-25 18:03:24 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
bs, _, err := h.BucketService.FindBuckets(ctx, req.getBucketsRequest.filter)
|
2018-07-30 18:35:04 +00:00
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-30 18:35:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-03-18 15:48:00 +00:00
|
|
|
if err := encodeResponse(ctx, w, http.StatusOK, newBucketsResponse(ctx, req.opts, req.filter, bs, h.LabelService)); err != nil {
|
2019-12-04 23:10:23 +00:00
|
|
|
logEncodingError(h.log, r, err)
|
2018-07-30 18:35:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type getSourceBucketsRequest struct {
|
|
|
|
*getSourceRequest
|
|
|
|
*getBucketsRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeGetSourceBucketsRequest(ctx context.Context, r *http.Request) (*getSourceBucketsRequest, error) {
|
|
|
|
getSrcReq, err := decodeGetSourceRequest(ctx, r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-02-04 19:09:12 +00:00
|
|
|
getBucketsReq, err := decodeGetBucketsRequest(r)
|
2018-07-30 18:35:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &getSourceBucketsRequest{
|
|
|
|
getBucketsRequest: getBucketsReq,
|
|
|
|
getSourceRequest: getSrcReq,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
type getBucketsRequest struct {
|
|
|
|
filter influxdb.BucketFilter
|
|
|
|
opts influxdb.FindOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeGetBucketsRequest(r *http.Request) (*getBucketsRequest, error) {
|
|
|
|
qp := r.URL.Query()
|
|
|
|
req := &getBucketsRequest{}
|
|
|
|
|
|
|
|
opts, err := influxdb.DecodeFindOptions(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
req.opts = *opts
|
|
|
|
|
|
|
|
if orgID := qp.Get("orgID"); orgID != "" {
|
2021-03-30 18:10:02 +00:00
|
|
|
id, err := platform.IDFromString(orgID)
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
req.filter.OrganizationID = id
|
|
|
|
}
|
|
|
|
|
|
|
|
if org := qp.Get("org"); org != "" {
|
|
|
|
req.filter.Org = &org
|
|
|
|
}
|
|
|
|
|
|
|
|
if name := qp.Get("name"); name != "" {
|
|
|
|
req.filter.Name = &name
|
|
|
|
}
|
|
|
|
|
|
|
|
if bucketID := qp.Get("id"); bucketID != "" {
|
2021-03-30 18:10:02 +00:00
|
|
|
id, err := platform.IDFromString(bucketID)
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
req.filter.ID = id
|
|
|
|
}
|
|
|
|
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type bucketResponse struct {
|
|
|
|
bucket
|
|
|
|
Links map[string]string `json:"links"`
|
|
|
|
Labels []influxdb.Label `json:"labels"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type bucket struct {
|
2021-03-30 18:10:02 +00:00
|
|
|
ID platform.ID `json:"id,omitempty"`
|
|
|
|
OrgID platform.ID `json:"orgID,omitempty"`
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
Type string `json:"type"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
RetentionPolicyName string `json:"rp,omitempty"` // This to support v1 sources
|
|
|
|
RetentionRules []retentionRule `json:"retentionRules"`
|
|
|
|
influxdb.CRUDLog
|
|
|
|
}
|
|
|
|
|
|
|
|
func newBucket(pb *influxdb.Bucket) *bucket {
|
|
|
|
if pb == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-11 19:51:03 +00:00
|
|
|
rules := []retentionRule{
|
|
|
|
{
|
|
|
|
Type: "expire",
|
|
|
|
EverySeconds: int64(pb.RetentionPeriod.Round(time.Second) / time.Second),
|
|
|
|
ShardGroupDurationSeconds: int64(pb.ShardGroupDuration.Round(time.Second) / time.Second),
|
|
|
|
},
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &bucket{
|
|
|
|
ID: pb.ID,
|
|
|
|
OrgID: pb.OrgID,
|
|
|
|
Type: pb.Type.String(),
|
|
|
|
Name: pb.Name,
|
|
|
|
Description: pb.Description,
|
|
|
|
RetentionPolicyName: pb.RetentionPolicyName,
|
|
|
|
RetentionRules: rules,
|
|
|
|
CRUDLog: pb.CRUDLog,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// retentionRule is the retention rule action for a bucket.
|
|
|
|
type retentionRule struct {
|
2021-03-11 19:51:03 +00:00
|
|
|
Type string `json:"type"`
|
|
|
|
EverySeconds int64 `json:"everySeconds"`
|
|
|
|
ShardGroupDurationSeconds int64 `json:"shardGroupDurationSeconds"`
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewBucketResponse(b *influxdb.Bucket, labels []*influxdb.Label) *bucketResponse {
|
|
|
|
res := &bucketResponse{
|
|
|
|
Links: map[string]string{
|
|
|
|
"labels": fmt.Sprintf("/api/v2/buckets/%s/labels", b.ID),
|
|
|
|
"logs": fmt.Sprintf("/api/v2/buckets/%s/logs", b.ID),
|
|
|
|
"members": fmt.Sprintf("/api/v2/buckets/%s/members", b.ID),
|
|
|
|
"org": fmt.Sprintf("/api/v2/orgs/%s", b.OrgID),
|
|
|
|
"owners": fmt.Sprintf("/api/v2/buckets/%s/owners", b.ID),
|
|
|
|
"self": fmt.Sprintf("/api/v2/buckets/%s", b.ID),
|
|
|
|
"write": fmt.Sprintf("/api/v2/write?org=%s&bucket=%s", b.OrgID, b.ID),
|
|
|
|
},
|
|
|
|
bucket: *newBucket(b),
|
|
|
|
Labels: []influxdb.Label{},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, l := range labels {
|
|
|
|
res.Labels = append(res.Labels, *l)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
type bucketsResponse struct {
|
|
|
|
Links *influxdb.PagingLinks `json:"links"`
|
|
|
|
Buckets []*bucketResponse `json:"buckets"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func newBucketsResponse(ctx context.Context, opts influxdb.FindOptions, f influxdb.BucketFilter, bs []*influxdb.Bucket, labelService influxdb.LabelService) *bucketsResponse {
|
|
|
|
rs := make([]*bucketResponse, 0, len(bs))
|
|
|
|
for _, b := range bs {
|
|
|
|
labels, _ := labelService.FindResourceLabels(ctx, influxdb.LabelMappingFilter{ResourceID: b.ID, ResourceType: influxdb.BucketsResourceType})
|
|
|
|
rs = append(rs, NewBucketResponse(b, labels))
|
|
|
|
}
|
|
|
|
return &bucketsResponse{
|
|
|
|
Links: influxdb.NewPagingLinks(prefixBuckets, opts, f, len(bs)),
|
|
|
|
Buckets: rs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-26 08:49:19 +00:00
|
|
|
// handlePostSource is the HTTP handler for the POST /api/v2/sources route.
|
2018-07-26 17:14:31 +00:00
|
|
|
func (h *SourceHandler) handlePostSource(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := r.Context()
|
|
|
|
req, err := decodePostSourceRequest(ctx, r)
|
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := h.SourceService.CreateSource(ctx, req.Source); err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-13 19:12:57 +00:00
|
|
|
res := newSourceResponse(req.Source)
|
2019-12-04 23:10:23 +00:00
|
|
|
h.log.Debug("Source created", zap.String("source", fmt.Sprint(res)))
|
2018-11-13 19:12:57 +00:00
|
|
|
if err := encodeResponse(ctx, w, http.StatusCreated, res); err != nil {
|
2019-12-04 23:10:23 +00:00
|
|
|
logEncodingError(h.log, r, err)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type postSourceRequest struct {
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
Source *influxdb.Source
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func decodePostSourceRequest(ctx context.Context, r *http.Request) (*postSourceRequest, error) {
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
b := &influxdb.Source{}
|
2018-07-26 17:14:31 +00:00
|
|
|
if err := json.NewDecoder(r.Body).Decode(b); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &postSourceRequest{
|
|
|
|
Source: b,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2018-09-26 08:49:19 +00:00
|
|
|
// handleGetSource is the HTTP handler for the GET /api/v2/sources/:id route.
|
2018-07-26 17:14:31 +00:00
|
|
|
func (h *SourceHandler) handleGetSource(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := r.Context()
|
|
|
|
req, err := decodeGetSourceRequest(ctx, r)
|
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-31 22:50:02 +00:00
|
|
|
s, err := h.SourceService.FindSourceByID(ctx, req.SourceID)
|
2018-07-26 17:14:31 +00:00
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-31 22:50:02 +00:00
|
|
|
res := newSourceResponse(s)
|
2019-12-04 23:10:23 +00:00
|
|
|
h.log.Debug("Source retrieved", zap.String("source", fmt.Sprint(res)))
|
2018-07-31 22:50:02 +00:00
|
|
|
|
|
|
|
if err := encodeResponse(ctx, w, http.StatusOK, res); err != nil {
|
2019-12-04 23:10:23 +00:00
|
|
|
logEncodingError(h.log, r, err)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// handleGetSourceHealth is the HTTP handler for the GET /v1/sources/:id/health route.
|
|
|
|
func (h *SourceHandler) handleGetSourceHealth(w http.ResponseWriter, r *http.Request) {
|
2018-12-21 12:17:32 +00:00
|
|
|
ctx := r.Context()
|
|
|
|
|
2019-03-13 14:55:12 +00:00
|
|
|
msg := `{"name":"sources","message":"source is %shealthy","status":"%s","checks":[]}`
|
2018-12-21 12:17:32 +00:00
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
|
|
|
|
|
req, err := decodeGetSourceRequest(ctx, r)
|
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-12-21 12:17:32 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if _, err := h.SourceService.FindSourceByID(ctx, req.SourceID); err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-12-21 12:17:32 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
// todo(leodido) > check source is actually healthy and reply with 503 if not
|
|
|
|
// w.WriteHeader(http.StatusServiceUnavailable)
|
|
|
|
// fmt.Fprintln(w, fmt.Sprintf(msg, "not ", "fail"))
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
w.WriteHeader(http.StatusOK)
|
2018-12-21 12:17:32 +00:00
|
|
|
fmt.Fprintln(w, fmt.Sprintf(msg, "", "pass"))
|
2018-08-07 20:10:05 +00:00
|
|
|
}
|
|
|
|
|
2018-07-26 17:14:31 +00:00
|
|
|
type getSourceRequest struct {
|
2021-03-30 18:10:02 +00:00
|
|
|
SourceID platform.ID
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func decodeGetSourceRequest(ctx context.Context, r *http.Request) (*getSourceRequest, error) {
|
|
|
|
params := httprouter.ParamsFromContext(ctx)
|
|
|
|
id := params.ByName("id")
|
|
|
|
if id == "" {
|
2021-03-30 18:10:02 +00:00
|
|
|
return nil, &errors.Error{
|
|
|
|
Code: errors.EInvalid,
|
2019-01-03 16:37:38 +00:00
|
|
|
Msg: "url missing id",
|
|
|
|
}
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
var i platform.ID
|
2018-07-26 17:14:31 +00:00
|
|
|
if err := i.DecodeFromString(id); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
req := &getSourceRequest{
|
|
|
|
SourceID: i,
|
|
|
|
}
|
|
|
|
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2018-09-26 08:49:19 +00:00
|
|
|
// handleDeleteSource is the HTTP handler for the DELETE /api/v2/sources/:id route.
|
2018-07-26 17:14:31 +00:00
|
|
|
func (h *SourceHandler) handleDeleteSource(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := r.Context()
|
|
|
|
req, err := decodeDeleteSourceRequest(ctx, r)
|
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := h.SourceService.DeleteSource(ctx, req.SourceID); err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
2019-12-04 23:10:23 +00:00
|
|
|
h.log.Debug("Source deleted", zap.String("sourceID", fmt.Sprint(req.SourceID)))
|
2018-07-26 17:14:31 +00:00
|
|
|
|
2018-10-29 19:10:33 +00:00
|
|
|
w.WriteHeader(http.StatusNoContent)
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type deleteSourceRequest struct {
|
2021-03-30 18:10:02 +00:00
|
|
|
SourceID platform.ID
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func decodeDeleteSourceRequest(ctx context.Context, r *http.Request) (*deleteSourceRequest, error) {
|
|
|
|
params := httprouter.ParamsFromContext(ctx)
|
|
|
|
id := params.ByName("id")
|
|
|
|
if id == "" {
|
2021-03-30 18:10:02 +00:00
|
|
|
return nil, &errors.Error{
|
|
|
|
Code: errors.EInvalid,
|
2019-01-03 16:37:38 +00:00
|
|
|
Msg: "url missing id",
|
|
|
|
}
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
var i platform.ID
|
2018-07-26 17:14:31 +00:00
|
|
|
if err := i.DecodeFromString(id); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
req := &deleteSourceRequest{
|
|
|
|
SourceID: i,
|
|
|
|
}
|
|
|
|
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2018-09-26 08:49:19 +00:00
|
|
|
// handleGetSources is the HTTP handler for the GET /api/v2/sources route.
|
2018-07-26 17:14:31 +00:00
|
|
|
func (h *SourceHandler) handleGetSources(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := r.Context()
|
|
|
|
req, err := decodeGetSourcesRequest(ctx, r)
|
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-31 22:50:02 +00:00
|
|
|
srcs, _, err := h.SourceService.FindSources(ctx, req.findOptions)
|
2018-07-26 17:14:31 +00:00
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-31 22:50:02 +00:00
|
|
|
res := newSourcesResponse(srcs)
|
2019-12-04 23:10:23 +00:00
|
|
|
h.log.Debug("Sources retrieved", zap.String("sources", fmt.Sprint(res)))
|
2018-07-31 22:50:02 +00:00
|
|
|
|
|
|
|
if err := encodeResponse(ctx, w, http.StatusOK, res); err != nil {
|
2019-12-04 23:10:23 +00:00
|
|
|
logEncodingError(h.log, r, err)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type getSourcesRequest struct {
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
findOptions influxdb.FindOptions
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func decodeGetSourcesRequest(ctx context.Context, r *http.Request) (*getSourcesRequest, error) {
|
|
|
|
req := &getSourcesRequest{}
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2018-09-26 08:49:19 +00:00
|
|
|
// handlePatchSource is the HTTP handler for the PATH /api/v2/sources route.
|
2018-07-26 17:14:31 +00:00
|
|
|
func (h *SourceHandler) handlePatchSource(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := r.Context()
|
|
|
|
req, err := decodePatchSourceRequest(ctx, r)
|
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err := h.SourceService.UpdateSource(ctx, req.SourceID, req.Update)
|
|
|
|
if err != nil {
|
2019-06-27 01:33:20 +00:00
|
|
|
h.HandleHTTPError(ctx, err, w)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
2019-12-04 23:10:23 +00:00
|
|
|
h.log.Debug("Source updated", zap.String("source", fmt.Sprint(b)))
|
2018-07-26 17:14:31 +00:00
|
|
|
|
|
|
|
if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil {
|
2019-12-04 23:10:23 +00:00
|
|
|
logEncodingError(h.log, r, err)
|
2018-07-26 17:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type patchSourceRequest struct {
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
Update influxdb.SourceUpdate
|
2021-03-30 18:10:02 +00:00
|
|
|
SourceID platform.ID
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func decodePatchSourceRequest(ctx context.Context, r *http.Request) (*patchSourceRequest, error) {
|
|
|
|
params := httprouter.ParamsFromContext(ctx)
|
|
|
|
id := params.ByName("id")
|
|
|
|
if id == "" {
|
2021-03-30 18:10:02 +00:00
|
|
|
return nil, &errors.Error{
|
|
|
|
Code: errors.EInvalid,
|
2019-01-03 16:37:38 +00:00
|
|
|
Msg: "url missing id",
|
|
|
|
}
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
var i platform.ID
|
2018-07-26 17:14:31 +00:00
|
|
|
if err := i.DecodeFromString(id); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
var upd influxdb.SourceUpdate
|
2018-07-26 17:14:31 +00:00
|
|
|
if err := json.NewDecoder(r.Body).Decode(&upd); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &patchSourceRequest{
|
|
|
|
Update: upd,
|
|
|
|
SourceID: i,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SourceService connects to Influx via HTTP using tokens to manage sources
|
|
|
|
type SourceService struct {
|
2019-12-17 20:30:42 +00:00
|
|
|
Client *httpc.Client
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FindSourceByID returns a single source by ID.
|
2021-03-30 18:10:02 +00:00
|
|
|
func (s *SourceService) FindSourceByID(ctx context.Context, id platform.ID) (*influxdb.Source, error) {
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
var b influxdb.Source
|
2019-12-17 20:30:42 +00:00
|
|
|
err := s.Client.
|
|
|
|
Get(prefixSources, id.String()).
|
|
|
|
DecodeJSON(&b).
|
|
|
|
Do(ctx)
|
|
|
|
if err != nil {
|
2018-07-26 17:14:31 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &b, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindSources returns a list of sources that match filter and the total count of matching sources.
|
|
|
|
// Additional options provide pagination & sorting.
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
func (s *SourceService) FindSources(ctx context.Context, opt influxdb.FindOptions) ([]*influxdb.Source, int, error) {
|
|
|
|
var bs []*influxdb.Source
|
2019-12-17 20:30:42 +00:00
|
|
|
err := s.Client.
|
|
|
|
Get(prefixSources).
|
|
|
|
DecodeJSON(&bs).
|
|
|
|
Do(ctx)
|
|
|
|
if err != nil {
|
2018-07-26 17:14:31 +00:00
|
|
|
return nil, 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return bs, len(bs), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateSource creates a new source and sets b.ID with the new identifier.
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
func (s *SourceService) CreateSource(ctx context.Context, b *influxdb.Source) error {
|
2019-12-17 20:30:42 +00:00
|
|
|
return s.Client.
|
|
|
|
PostJSON(b, prefixSources).
|
|
|
|
DecodeJSON(b).
|
|
|
|
Do(ctx)
|
2018-07-26 17:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateSource updates a single source with changeset.
|
|
|
|
// Returns the new source state after update.
|
2021-03-30 18:10:02 +00:00
|
|
|
func (s *SourceService) UpdateSource(ctx context.Context, id platform.ID, upd influxdb.SourceUpdate) (*influxdb.Source, error) {
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
var b influxdb.Source
|
2019-12-17 20:30:42 +00:00
|
|
|
err := s.Client.
|
|
|
|
PatchJSON(upd, prefixSources, id.String()).
|
|
|
|
DecodeJSON(&b).
|
|
|
|
Do(ctx)
|
|
|
|
if err != nil {
|
2018-07-26 17:14:31 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &b, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteSource removes a source by ID.
|
2021-03-30 18:10:02 +00:00
|
|
|
func (s *SourceService) DeleteSource(ctx context.Context, id platform.ID) error {
|
2019-12-17 20:30:42 +00:00
|
|
|
return s.Client.
|
|
|
|
Delete(prefixSources, id.String()).
|
|
|
|
StatusFn(func(resp *http.Response) error {
|
|
|
|
return CheckErrorStatus(http.StatusNoContent, resp)
|
|
|
|
}).
|
|
|
|
Do(ctx)
|
2018-07-26 17:14:31 +00:00
|
|
|
|
|
|
|
}
|