Skip to content

Commit

Permalink
feat(dashboards): isolate service in own package (#19852)
Browse files Browse the repository at this point in the history
feat(dashboard): add owner ID to dashboard model

This adds the explicit OwnerID field to Dashboard and also adds a
migration which populates dashboard owners IDs based on dashboard owner
URMs.

feat(dashboards): isolate service in own package

This change isolates the dashboards service into its own package. It
also updates the API to no longer interface with user resource mappings.
Instead it defines new handlers which rely on the newly populated owner
ID field.

chore(dashboards): port tests from http package into new service transport package

chore(launcher): use dashboard transport package client in launcher tests

chore(kv): remove now defunkt dashboard service implementations
  • Loading branch information
GeorgeMac committed Nov 4, 2020
1 parent b274e15 commit 8ca2989
Show file tree
Hide file tree
Showing 22 changed files with 1,114 additions and 670 deletions.
4 changes: 2 additions & 2 deletions cmd/influx/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/cmd/influx/internal"
"github.com/influxdata/influxdb/v2/http"
"github.com/influxdata/influxdb/v2/dashboards/transport"
"github.com/influxdata/influxdb/v2/tenant"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -147,7 +147,7 @@ func newDashboardSVCs() (influxdb.DashboardService, influxdb.OrganizationService
orgSVC := &tenant.OrgClientService{
Client: httpClient,
}
dashSVC := &http.DashboardService{
dashSVC := &transport.DashboardService{
Client: httpClient,
}
return dashSVC, orgSVC, nil
Expand Down
42 changes: 40 additions & 2 deletions cmd/influxd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/influxdata/influxdb/v2/checks"
"github.com/influxdata/influxdb/v2/chronograf/server"
"github.com/influxdata/influxdb/v2/cmd/influxd/inspect"
"github.com/influxdata/influxdb/v2/dashboards"
dashboardTransport "github.com/influxdata/influxdb/v2/dashboards/transport"
"github.com/influxdata/influxdb/v2/dbrp"
"github.com/influxdata/influxdb/v2/fluxinit"
"github.com/influxdata/influxdb/v2/gather"
Expand Down Expand Up @@ -766,8 +768,6 @@ func (m *Launcher) run(ctx context.Context) (err error) {
var (
variableSvc platform.VariableService = m.kvService
sourceSvc platform.SourceService = m.kvService
dashboardSvc platform.DashboardService = m.kvService
dashboardLogSvc platform.DashboardOperationLogService = m.kvService
userLogSvc platform.UserOperationLogService = m.kvService
bucketLogSvc platform.BucketOperationLogService = m.kvService
orgLogSvc platform.OrganizationOperationLogService = m.kvService
Expand Down Expand Up @@ -1165,6 +1165,16 @@ func (m *Launcher) run(ctx context.Context) (err error) {
}
}

var (
dashboardSvc platform.DashboardService
dashboardLogSvc platform.DashboardOperationLogService
)
{
dashboardService := dashboards.NewService(m.kvStore, m.kvService)
dashboardSvc = dashboardService
dashboardLogSvc = dashboardService
}

// resourceResolver is a deprecated type which combines the lookups
// of multiple resources into one type, used to resolve the resources
// associated org ID or name . It is a stop-gap while we move this
Expand Down Expand Up @@ -1334,6 +1344,33 @@ func (m *Launcher) run(ctx context.Context) (err error) {

bucketHTTPServer := ts.NewBucketHTTPHandler(m.log, labelSvc)

var dashboardServer *dashboardTransport.DashboardHandler
{
urmHandler := tenant.NewURMHandler(
m.log.With(zap.String("handler", "urm")),
platform.DashboardsResourceType,
"id",
ts.UserService,
tenant.NewAuthedURMService(ts.OrganizationService, ts.UserResourceMappingService),
)

labelHandler := label.NewHTTPEmbeddedHandler(
m.log.With(zap.String("handler", "label")),
platform.DashboardsResourceType,
labelSvc,
)

dashboardServer = dashboardTransport.NewDashboardHandler(
m.log.With(zap.String("handler", "dashboards")),
authorizer.NewDashboardService(dashboardSvc),
labelSvc,
ts.UserService,
ts.OrganizationService,
urmHandler,
labelHandler,
)
}

{
platformHandler := http.NewPlatformHandler(m.apibackend,
http.WithResourceHandler(stacksHTTPServer),
Expand All @@ -1348,6 +1385,7 @@ func (m *Launcher) run(ctx context.Context) (err error) {
http.WithResourceHandler(orgHTTPServer),
http.WithResourceHandler(bucketHTTPServer),
http.WithResourceHandler(v1AuthHTTPServer),
http.WithResourceHandler(dashboardServer),
)

httpLogger := m.log.With(zap.String("service", "http"))
Expand Down
5 changes: 3 additions & 2 deletions cmd/influxd/launcher/launcher_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/bolt"
influxdbcontext "github.com/influxdata/influxdb/v2/context"
dashboardTransport "github.com/influxdata/influxdb/v2/dashboards/transport"
"github.com/influxdata/influxdb/v2/http"
"github.com/influxdata/influxdb/v2/kit/feature"
"github.com/influxdata/influxdb/v2/mock"
Expand Down Expand Up @@ -367,9 +368,9 @@ func (tl *TestLauncher) BucketService(tb testing.TB) *http.BucketService {
return &http.BucketService{Client: tl.HTTPClient(tb)}
}

func (tl *TestLauncher) DashboardService(tb testing.TB) *http.DashboardService {
func (tl *TestLauncher) DashboardService(tb testing.TB) influxdb.DashboardService {
tb.Helper()
return &http.DashboardService{Client: tl.HTTPClient(tb)}
return &dashboardTransport.DashboardService{Client: tl.HTTPClient(tb)}
}

func (tl *TestLauncher) LabelService(tb testing.TB) *http.LabelService {
Expand Down
6 changes: 6 additions & 0 deletions dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Dashboard struct {
Description string `json:"description"`
Cells []*Cell `json:"cells"`
Meta DashboardMeta `json:"meta"`
OwnerID *ID `json:"owner,omitempty"`
}

// DashboardMeta contains meta information about dashboards
Expand Down Expand Up @@ -197,6 +198,7 @@ type DashboardFilter struct {
IDs []*ID
OrganizationID *ID
Organization *string
OwnerID *ID
}

// QueryParams turns a dashboard filter into query params
Expand All @@ -218,6 +220,10 @@ func (f DashboardFilter) QueryParams() map[string][]string {
qp.Add("org", *f.Organization)
}

if f.OwnerID != nil {
qp.Add("owner", f.OwnerID.String())
}

return qp
}

Expand Down
Loading

0 comments on commit 8ca2989

Please sign in to comment.