Skip to content

Commit fab0549

Browse files
committed
feat(dashboards): isolate service in own package
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
1 parent 24c6526 commit fab0549

22 files changed

+1076
-632
lines changed

cmd/influx/dashboard.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/influxdata/influxdb/v2"
77
"github.com/influxdata/influxdb/v2/cmd/influx/internal"
8-
"github.com/influxdata/influxdb/v2/http"
8+
"github.com/influxdata/influxdb/v2/dashboards/transport"
99
"github.com/influxdata/influxdb/v2/tenant"
1010
"github.com/spf13/cobra"
1111
)
@@ -147,7 +147,7 @@ func newDashboardSVCs() (influxdb.DashboardService, influxdb.OrganizationService
147147
orgSVC := &tenant.OrgClientService{
148148
Client: httpClient,
149149
}
150-
dashSVC := &http.DashboardService{
150+
dashSVC := &transport.DashboardService{
151151
Client: httpClient,
152152
}
153153
return dashSVC, orgSVC, nil

cmd/influxd/launcher/launcher.go

+40-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"github.com/influxdata/influxdb/v2/checks"
2424
"github.com/influxdata/influxdb/v2/chronograf/server"
2525
"github.com/influxdata/influxdb/v2/cmd/influxd/inspect"
26+
"github.com/influxdata/influxdb/v2/dashboards"
27+
dashboardTransport "github.com/influxdata/influxdb/v2/dashboards/transport"
2628
"github.com/influxdata/influxdb/v2/dbrp"
2729
"github.com/influxdata/influxdb/v2/gather"
2830
"github.com/influxdata/influxdb/v2/http"
@@ -763,8 +765,6 @@ func (m *Launcher) run(ctx context.Context) (err error) {
763765
var (
764766
variableSvc platform.VariableService = m.kvService
765767
sourceSvc platform.SourceService = m.kvService
766-
dashboardSvc platform.DashboardService = m.kvService
767-
dashboardLogSvc platform.DashboardOperationLogService = m.kvService
768768
userLogSvc platform.UserOperationLogService = m.kvService
769769
bucketLogSvc platform.BucketOperationLogService = m.kvService
770770
orgLogSvc platform.OrganizationOperationLogService = m.kvService
@@ -1162,6 +1162,16 @@ func (m *Launcher) run(ctx context.Context) (err error) {
11621162
}
11631163
}
11641164

1165+
var (
1166+
dashboardSvc platform.DashboardService
1167+
dashboardLogSvc platform.DashboardOperationLogService
1168+
)
1169+
{
1170+
dashboardService := dashboards.NewService(m.kvStore, m.kvService)
1171+
dashboardSvc = dashboardService
1172+
dashboardLogSvc = dashboardService
1173+
}
1174+
11651175
// resourceResolver is a deprecated type which combines the lookups
11661176
// of multiple resources into one type, used to resolve the resources
11671177
// associated org ID or name . It is a stop-gap while we move this
@@ -1331,6 +1341,33 @@ func (m *Launcher) run(ctx context.Context) (err error) {
13311341

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

1344+
var dashboardServer *dashboardTransport.DashboardHandler
1345+
{
1346+
urmHandler := tenant.NewURMHandler(
1347+
m.log.With(zap.String("handler", "urm")),
1348+
platform.DashboardsResourceType,
1349+
"id",
1350+
ts.UserService,
1351+
tenant.NewAuthedURMService(ts.OrganizationService, ts.UserResourceMappingService),
1352+
)
1353+
1354+
labelHandler := label.NewHTTPEmbeddedHandler(
1355+
m.log.With(zap.String("handler", "label")),
1356+
platform.DashboardsResourceType,
1357+
labelSvc,
1358+
)
1359+
1360+
dashboardServer = dashboardTransport.NewDashboardHandler(
1361+
m.log.With(zap.String("handler", "dashboards")),
1362+
authorizer.NewDashboardService(dashboardSvc),
1363+
labelSvc,
1364+
ts.UserService,
1365+
ts.OrganizationService,
1366+
urmHandler,
1367+
labelHandler,
1368+
)
1369+
}
1370+
13341371
{
13351372
platformHandler := http.NewPlatformHandler(m.apibackend,
13361373
http.WithResourceHandler(stacksHTTPServer),
@@ -1345,6 +1382,7 @@ func (m *Launcher) run(ctx context.Context) (err error) {
13451382
http.WithResourceHandler(orgHTTPServer),
13461383
http.WithResourceHandler(bucketHTTPServer),
13471384
http.WithResourceHandler(v1AuthHTTPServer),
1385+
http.WithResourceHandler(dashboardServer),
13481386
)
13491387

13501388
httpLogger := m.log.With(zap.String("service", "http"))

cmd/influxd/launcher/launcher_helpers.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/influxdata/influxdb/v2"
2020
"github.com/influxdata/influxdb/v2/bolt"
2121
influxdbcontext "github.com/influxdata/influxdb/v2/context"
22+
dashboardTransport "github.com/influxdata/influxdb/v2/dashboards/transport"
2223
"github.com/influxdata/influxdb/v2/http"
2324
"github.com/influxdata/influxdb/v2/kit/feature"
2425
"github.com/influxdata/influxdb/v2/mock"
@@ -367,9 +368,9 @@ func (tl *TestLauncher) BucketService(tb testing.TB) *http.BucketService {
367368
return &http.BucketService{Client: tl.HTTPClient(tb)}
368369
}
369370

370-
func (tl *TestLauncher) DashboardService(tb testing.TB) *http.DashboardService {
371+
func (tl *TestLauncher) DashboardService(tb testing.TB) influxdb.DashboardService {
371372
tb.Helper()
372-
return &http.DashboardService{Client: tl.HTTPClient(tb)}
373+
return &dashboardTransport.DashboardService{Client: tl.HTTPClient(tb)}
373374
}
374375

375376
func (tl *TestLauncher) LabelService(tb testing.TB) *http.LabelService {

dashboard.go

+6
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type Dashboard struct {
7979
Description string `json:"description"`
8080
Cells []*Cell `json:"cells"`
8181
Meta DashboardMeta `json:"meta"`
82+
OwnerID *ID `json:"owner,omitempty"`
8283
}
8384

8485
// DashboardMeta contains meta information about dashboards
@@ -197,6 +198,7 @@ type DashboardFilter struct {
197198
IDs []*ID
198199
OrganizationID *ID
199200
Organization *string
201+
OwnerID *ID
200202
}
201203

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

223+
if f.OwnerID != nil {
224+
qp.Add("owner", f.OwnerID.String())
225+
}
226+
221227
return qp
222228
}
223229

0 commit comments

Comments
 (0)