Skip to content

Commit 8ca2989

Browse files
committed
feat(dashboards): isolate service in own package (#19852)
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 b274e15 commit 8ca2989

22 files changed

+1114
-670
lines changed

cmd/influx/dashboard.go

Lines changed: 2 additions & 2 deletions
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

Lines changed: 40 additions & 2 deletions
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/fluxinit"
2830
"github.com/influxdata/influxdb/v2/gather"
@@ -766,8 +768,6 @@ func (m *Launcher) run(ctx context.Context) (err error) {
766768
var (
767769
variableSvc platform.VariableService = m.kvService
768770
sourceSvc platform.SourceService = m.kvService
769-
dashboardSvc platform.DashboardService = m.kvService
770-
dashboardLogSvc platform.DashboardOperationLogService = m.kvService
771771
userLogSvc platform.UserOperationLogService = m.kvService
772772
bucketLogSvc platform.BucketOperationLogService = m.kvService
773773
orgLogSvc platform.OrganizationOperationLogService = m.kvService
@@ -1165,6 +1165,16 @@ func (m *Launcher) run(ctx context.Context) (err error) {
11651165
}
11661166
}
11671167

1168+
var (
1169+
dashboardSvc platform.DashboardService
1170+
dashboardLogSvc platform.DashboardOperationLogService
1171+
)
1172+
{
1173+
dashboardService := dashboards.NewService(m.kvStore, m.kvService)
1174+
dashboardSvc = dashboardService
1175+
dashboardLogSvc = dashboardService
1176+
}
1177+
11681178
// resourceResolver is a deprecated type which combines the lookups
11691179
// of multiple resources into one type, used to resolve the resources
11701180
// associated org ID or name . It is a stop-gap while we move this
@@ -1334,6 +1344,33 @@ func (m *Launcher) run(ctx context.Context) (err error) {
13341344

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

1347+
var dashboardServer *dashboardTransport.DashboardHandler
1348+
{
1349+
urmHandler := tenant.NewURMHandler(
1350+
m.log.With(zap.String("handler", "urm")),
1351+
platform.DashboardsResourceType,
1352+
"id",
1353+
ts.UserService,
1354+
tenant.NewAuthedURMService(ts.OrganizationService, ts.UserResourceMappingService),
1355+
)
1356+
1357+
labelHandler := label.NewHTTPEmbeddedHandler(
1358+
m.log.With(zap.String("handler", "label")),
1359+
platform.DashboardsResourceType,
1360+
labelSvc,
1361+
)
1362+
1363+
dashboardServer = dashboardTransport.NewDashboardHandler(
1364+
m.log.With(zap.String("handler", "dashboards")),
1365+
authorizer.NewDashboardService(dashboardSvc),
1366+
labelSvc,
1367+
ts.UserService,
1368+
ts.OrganizationService,
1369+
urmHandler,
1370+
labelHandler,
1371+
)
1372+
}
1373+
13371374
{
13381375
platformHandler := http.NewPlatformHandler(m.apibackend,
13391376
http.WithResourceHandler(stacksHTTPServer),
@@ -1348,6 +1385,7 @@ func (m *Launcher) run(ctx context.Context) (err error) {
13481385
http.WithResourceHandler(orgHTTPServer),
13491386
http.WithResourceHandler(bucketHTTPServer),
13501387
http.WithResourceHandler(v1AuthHTTPServer),
1388+
http.WithResourceHandler(dashboardServer),
13511389
)
13521390

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

cmd/influxd/launcher/launcher_helpers.go

Lines changed: 3 additions & 2 deletions
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

Lines changed: 6 additions & 0 deletions
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)