Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashboard): isolate dashboards service (remove URM interactions) #19852

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/gather"
"github.com/influxdata/influxdb/v2/http"
Expand Down Expand Up @@ -763,8 +765,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 @@ -1162,6 +1162,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 @@ -1331,6 +1341,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 @@ -1345,6 +1382,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