Skip to content

Commit

Permalink
Merge branch 'master' into 15898/dashboard-api-tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dearyhud committed Dec 2, 2019
2 parents e09f09b + f27198c commit 937bc9e
Show file tree
Hide file tree
Showing 21 changed files with 762 additions and 339 deletions.
8 changes: 8 additions & 0 deletions authorizer/notification_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ func (s *NotificationEndpointService) FindNotificationEndpointByID(ctx context.C

// FindNotificationEndpoints retrieves all notification endpoints that match the provided filter and then filters the list down to only the resources that are authorized.
func (s *NotificationEndpointService) FindNotificationEndpoints(ctx context.Context, filter influxdb.NotificationEndpointFilter, opt ...influxdb.FindOptions) ([]influxdb.NotificationEndpoint, int, error) {
// TODO: This is a temporary fix as to not fetch the entire collection when no filter is provided.
if !filter.UserID.Valid() && filter.OrgID == nil {
return nil, 0, &influxdb.Error{
Code: influxdb.EUnauthorized,
Msg: "cannot process a request without a org or user filter",
}
}

// TODO: we'll likely want to push this operation into the database eventually since fetching the whole list of data
// will likely be expensive.
edps, _, err := s.s.FindNotificationEndpoints(ctx, filter, opt...)
Expand Down
62 changes: 2 additions & 60 deletions authorizer/notification_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,65 +138,6 @@ func TestNotificationEndpointService_FindNotificationEndpoints(t *testing.T) {
args args
wants wants
}{
{
name: "authorized to see all notificationEndpoints",
fields: fields{
NotificationEndpointService: &mock.NotificationEndpointService{
FindNotificationEndpointsF: func(ctx context.Context, filter influxdb.NotificationEndpointFilter, opt ...influxdb.FindOptions) ([]influxdb.NotificationEndpoint, int, error) {
return []influxdb.NotificationEndpoint{
&endpoint.Slack{
Base: endpoint.Base{
ID: 1,
OrgID: 10,
},
},
&endpoint.Slack{
Base: endpoint.Base{
ID: 2,
OrgID: 10,
},
},
&endpoint.HTTP{
Base: endpoint.Base{
ID: 3,
OrgID: 11,
},
},
}, 3, nil
},
},
},
args: args{
permission: influxdb.Permission{
Action: "read",
Resource: influxdb.Resource{
Type: influxdb.OrgsResourceType,
},
},
},
wants: wants{
notificationEndpoints: []influxdb.NotificationEndpoint{
&endpoint.Slack{
Base: endpoint.Base{
ID: 1,
OrgID: 10,
},
},
&endpoint.Slack{
Base: endpoint.Base{
ID: 2,
OrgID: 10,
},
},
&endpoint.HTTP{
Base: endpoint.Base{
ID: 3,
OrgID: 11,
},
},
},
},
},
{
name: "authorized to access a single orgs notificationEndpoints",
fields: fields{
Expand Down Expand Up @@ -262,7 +203,8 @@ func TestNotificationEndpointService_FindNotificationEndpoints(t *testing.T) {
ctx := context.Background()
ctx = influxdbcontext.SetAuthorizer(ctx, &Authorizer{[]influxdb.Permission{tt.args.permission}})

edps, _, err := s.FindNotificationEndpoints(ctx, influxdb.NotificationEndpointFilter{})
oid := influxdb.ID(10)
edps, _, err := s.FindNotificationEndpoints(ctx, influxdb.NotificationEndpointFilter{OrgID: &oid})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)

if diff := cmp.Diff(edps, tt.wants.notificationEndpoints, notificationEndpointCmpOptions...); diff != "" {
Expand Down
14 changes: 9 additions & 5 deletions http/notification_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,8 @@ func (h *NotificationEndpointHandler) handleGetNotificationEndpoint(w http.Respo
}

func decodeNotificationEndpointFilter(ctx context.Context, r *http.Request) (*influxdb.NotificationEndpointFilter, *influxdb.FindOptions, error) {
auth, err := pctx.GetAuthorizer(ctx)
if err != nil {
return nil, nil, err
}
f := &influxdb.NotificationEndpointFilter{
UserResourceMappingFilter: influxdb.UserResourceMappingFilter{
UserID: auth.GetUserID(),
ResourceType: influxdb.NotificationEndpointResourceType,
},
}
Expand All @@ -294,6 +289,15 @@ func decodeNotificationEndpointFilter(ctx context.Context, r *http.Request) (*in
} else if orgNameStr := q.Get("org"); orgNameStr != "" {
*f.Org = orgNameStr
}

if userID := q.Get("user"); userID != "" {
id, err := influxdb.IDFromString(userID)
if err != nil {
return f, opts, err
}
f.UserID = *id
}

return f, opts, err
}

Expand Down
5 changes: 5 additions & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7868,6 +7868,11 @@ components:
type: array
items:
type: string
aggregateFunctionType:
$ref: '#/components/schemas/BuilderAggregateFunctionType'
BuilderAggregateFunctionType:
type: string
enum: ['filter', 'group']
BuilderFunctionsType:
type: object
properties:
Expand Down
26 changes: 16 additions & 10 deletions storage/reads/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (r *storeReader) ReadFilter(ctx context.Context, spec influxdb.ReadFilterSp
ctx: ctx,
s: r.s,
spec: spec,
cache: newTagsCache(0),
alloc: alloc,
}, nil
}
Expand All @@ -45,6 +46,7 @@ func (r *storeReader) ReadGroup(ctx context.Context, spec influxdb.ReadGroupSpec
ctx: ctx,
s: r.s,
spec: spec,
cache: newTagsCache(0),
alloc: alloc,
}, nil
}
Expand Down Expand Up @@ -96,6 +98,7 @@ type filterIterator struct {
s Store
spec influxdb.ReadFilterSpec
stats cursors.CursorStats
cache *tagsCache
alloc *memory.Allocator
}

Expand Down Expand Up @@ -155,6 +158,7 @@ func (fi *filterIterator) handleRead(f func(flux.Table) error, rs ResultSet) err
cur.Close()
}
rs.Close()
fi.cache.Release()
}()

READ:
Expand All @@ -171,19 +175,19 @@ READ:
switch typedCur := cur.(type) {
case cursors.IntegerArrayCursor:
cols, defs := determineTableColsForSeries(rs.Tags(), flux.TInt)
table = newIntegerTable(done, typedCur, bnds, key, cols, rs.Tags(), defs, fi.alloc)
table = newIntegerTable(done, typedCur, bnds, key, cols, rs.Tags(), defs, fi.cache, fi.alloc)
case cursors.FloatArrayCursor:
cols, defs := determineTableColsForSeries(rs.Tags(), flux.TFloat)
table = newFloatTable(done, typedCur, bnds, key, cols, rs.Tags(), defs, fi.alloc)
table = newFloatTable(done, typedCur, bnds, key, cols, rs.Tags(), defs, fi.cache, fi.alloc)
case cursors.UnsignedArrayCursor:
cols, defs := determineTableColsForSeries(rs.Tags(), flux.TUInt)
table = newUnsignedTable(done, typedCur, bnds, key, cols, rs.Tags(), defs, fi.alloc)
table = newUnsignedTable(done, typedCur, bnds, key, cols, rs.Tags(), defs, fi.cache, fi.alloc)
case cursors.BooleanArrayCursor:
cols, defs := determineTableColsForSeries(rs.Tags(), flux.TBool)
table = newBooleanTable(done, typedCur, bnds, key, cols, rs.Tags(), defs, fi.alloc)
table = newBooleanTable(done, typedCur, bnds, key, cols, rs.Tags(), defs, fi.cache, fi.alloc)
case cursors.StringArrayCursor:
cols, defs := determineTableColsForSeries(rs.Tags(), flux.TString)
table = newStringTable(done, typedCur, bnds, key, cols, rs.Tags(), defs, fi.alloc)
table = newStringTable(done, typedCur, bnds, key, cols, rs.Tags(), defs, fi.cache, fi.alloc)
default:
panic(fmt.Sprintf("unreachable: %T", typedCur))
}
Expand Down Expand Up @@ -218,6 +222,7 @@ type groupIterator struct {
s Store
spec influxdb.ReadGroupSpec
stats cursors.CursorStats
cache *tagsCache
alloc *memory.Allocator
}

Expand Down Expand Up @@ -289,6 +294,7 @@ func (gi *groupIterator) handleRead(f func(flux.Table) error, rs GroupResultSet)
gc.Close()
}
rs.Close()
gi.cache.Release()
}()

gc = rs.Next()
Expand All @@ -313,19 +319,19 @@ READ:
switch typedCur := cur.(type) {
case cursors.IntegerArrayCursor:
cols, defs := determineTableColsForGroup(gc.Keys(), flux.TInt)
table = newIntegerGroupTable(done, gc, typedCur, bnds, key, cols, gc.Tags(), defs, gi.alloc)
table = newIntegerGroupTable(done, gc, typedCur, bnds, key, cols, gc.Tags(), defs, gi.cache, gi.alloc)
case cursors.FloatArrayCursor:
cols, defs := determineTableColsForGroup(gc.Keys(), flux.TFloat)
table = newFloatGroupTable(done, gc, typedCur, bnds, key, cols, gc.Tags(), defs, gi.alloc)
table = newFloatGroupTable(done, gc, typedCur, bnds, key, cols, gc.Tags(), defs, gi.cache, gi.alloc)
case cursors.UnsignedArrayCursor:
cols, defs := determineTableColsForGroup(gc.Keys(), flux.TUInt)
table = newUnsignedGroupTable(done, gc, typedCur, bnds, key, cols, gc.Tags(), defs, gi.alloc)
table = newUnsignedGroupTable(done, gc, typedCur, bnds, key, cols, gc.Tags(), defs, gi.cache, gi.alloc)
case cursors.BooleanArrayCursor:
cols, defs := determineTableColsForGroup(gc.Keys(), flux.TBool)
table = newBooleanGroupTable(done, gc, typedCur, bnds, key, cols, gc.Tags(), defs, gi.alloc)
table = newBooleanGroupTable(done, gc, typedCur, bnds, key, cols, gc.Tags(), defs, gi.cache, gi.alloc)
case cursors.StringArrayCursor:
cols, defs := determineTableColsForGroup(gc.Keys(), flux.TString)
table = newStringGroupTable(done, gc, typedCur, bnds, key, cols, gc.Tags(), defs, gi.alloc)
table = newStringGroupTable(done, gc, typedCur, bnds, key, cols, gc.Tags(), defs, gi.cache, gi.alloc)
default:
panic(fmt.Sprintf("unreachable: %T", typedCur))
}
Expand Down
30 changes: 20 additions & 10 deletions storage/reads/table.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ func newFloatTable(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *floatTable {
t := &floatTable{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
cur: cur,
}
t.readTags(tags)
Expand Down Expand Up @@ -113,10 +114,11 @@ func newFloatGroupTable(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *floatGroupTable {
t := &floatGroupTable{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
gc: gc,
cur: cur,
}
Expand Down Expand Up @@ -220,10 +222,11 @@ func newIntegerTable(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *integerTable {
t := &integerTable{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
cur: cur,
}
t.readTags(tags)
Expand Down Expand Up @@ -296,10 +299,11 @@ func newIntegerGroupTable(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *integerGroupTable {
t := &integerGroupTable{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
gc: gc,
cur: cur,
}
Expand Down Expand Up @@ -403,10 +407,11 @@ func newUnsignedTable(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *unsignedTable {
t := &unsignedTable{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
cur: cur,
}
t.readTags(tags)
Expand Down Expand Up @@ -479,10 +484,11 @@ func newUnsignedGroupTable(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *unsignedGroupTable {
t := &unsignedGroupTable{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
gc: gc,
cur: cur,
}
Expand Down Expand Up @@ -586,10 +592,11 @@ func newStringTable(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *stringTable {
t := &stringTable{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
cur: cur,
}
t.readTags(tags)
Expand Down Expand Up @@ -662,10 +669,11 @@ func newStringGroupTable(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *stringGroupTable {
t := &stringGroupTable{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
gc: gc,
cur: cur,
}
Expand Down Expand Up @@ -769,10 +777,11 @@ func newBooleanTable(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *booleanTable {
t := &booleanTable{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
cur: cur,
}
t.readTags(tags)
Expand Down Expand Up @@ -845,10 +854,11 @@ func newBooleanGroupTable(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *booleanGroupTable {
t := &booleanGroupTable{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
gc: gc,
cur: cur,
}
Expand Down
6 changes: 4 additions & 2 deletions storage/reads/table.gen.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ func new{{.Name}}Table(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *{{.name}}Table {
t := &{{.name}}Table{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
cur: cur,
}
t.readTags(tags)
Expand Down Expand Up @@ -107,10 +108,11 @@ func new{{.Name}}GroupTable(
cols []flux.ColMeta,
tags models.Tags,
defs [][]byte,
cache *tagsCache,
alloc *memory.Allocator,
) *{{.name}}GroupTable {
t := &{{.name}}GroupTable{
table: newTable(done, bounds, key, cols, defs, alloc),
table: newTable(done, bounds, key, cols, defs, cache, alloc),
gc: gc,
cur: cur,
}
Expand Down
Loading

0 comments on commit 937bc9e

Please sign in to comment.