feat(http): Add bucket types (#15045)
parent
51b1c58aaa
commit
c1cd152363
17
bucket.go
17
bucket.go
|
@ -13,6 +13,11 @@ const (
|
|||
TasksSystemBucketID = ID(10)
|
||||
// MonitoringSystemBucketID is the fixed ID for our monitoring system bucket
|
||||
MonitoringSystemBucketID = ID(11)
|
||||
|
||||
// BucketTypeUser is a user created bucket
|
||||
BucketTypeUser = BucketType(0)
|
||||
// BucketTypeSystem is an internally created bucket that cannot be deleted/renamed.
|
||||
BucketTypeSystem = BucketType(1)
|
||||
)
|
||||
|
||||
// InfiniteRetention is default infinite retention period.
|
||||
|
@ -22,6 +27,7 @@ const InfiniteRetention = 0
|
|||
type Bucket struct {
|
||||
ID ID `json:"id,omitempty"`
|
||||
OrgID ID `json:"orgID,omitempty"`
|
||||
Type BucketType `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
RetentionPolicyName string `json:"rp,omitempty"` // This to support v1 sources
|
||||
|
@ -29,6 +35,17 @@ type Bucket struct {
|
|||
CRUDLog
|
||||
}
|
||||
|
||||
// BucketType differentiates system buckets from user buckets.
|
||||
type BucketType int
|
||||
|
||||
// String converts a BucketType into a human-readable string.
|
||||
func (bt BucketType) String() string {
|
||||
if bt == BucketTypeSystem {
|
||||
return "system"
|
||||
}
|
||||
return "user"
|
||||
}
|
||||
|
||||
// TODO(jade): move this logic to a type set directly on Bucket.
|
||||
// IsSystem returns true if a bucket is a known system bucket
|
||||
func (b *Bucket) IsSystem() bool {
|
||||
|
|
|
@ -134,6 +134,7 @@ func NewBucketHandler(b *BucketBackend) *BucketHandler {
|
|||
type bucket struct {
|
||||
ID influxdb.ID `json:"id,omitempty"`
|
||||
OrgID influxdb.ID `json:"orgID,omitempty"`
|
||||
Type string `json:"type"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Name string `json:"name"`
|
||||
RetentionPolicyName string `json:"rp,omitempty"` // This to support v1 sources
|
||||
|
@ -193,6 +194,7 @@ func newBucket(pb *influxdb.Bucket) *bucket {
|
|||
return &bucket{
|
||||
ID: pb.ID,
|
||||
OrgID: pb.OrgID,
|
||||
Type: pb.Type.String(),
|
||||
Name: pb.Name,
|
||||
Description: pb.Description,
|
||||
RetentionPolicyName: pb.RetentionPolicyName,
|
||||
|
|
|
@ -118,6 +118,7 @@ func TestService_handleGetBuckets(t *testing.T) {
|
|||
"updatedAt": "0001-01-01T00:00:00Z",
|
||||
"id": "0b501e7e557ab1ed",
|
||||
"orgID": "50f7ba1150f7ba11",
|
||||
"type": "user",
|
||||
"name": "hello",
|
||||
"retentionRules": [{"type": "expire", "everySeconds": 2}],
|
||||
"labels": [
|
||||
|
@ -144,6 +145,7 @@ func TestService_handleGetBuckets(t *testing.T) {
|
|||
"updatedAt": "0001-01-01T00:00:00Z",
|
||||
"id": "c0175f0077a77005",
|
||||
"orgID": "7e55e118dbabb1ed",
|
||||
"type": "user",
|
||||
"name": "example",
|
||||
"retentionRules": [{"type": "expire", "everySeconds": 86400}],
|
||||
"labels": [
|
||||
|
@ -286,6 +288,7 @@ func TestService_handleGetBucket(t *testing.T) {
|
|||
"updatedAt": "0001-01-01T00:00:00Z",
|
||||
"id": "020f755c3c082000",
|
||||
"orgID": "020f755c3c082000",
|
||||
"type": "user",
|
||||
"name": "hello",
|
||||
"retentionRules": [{"type": "expire", "everySeconds": 30}],
|
||||
"labels": []
|
||||
|
@ -418,6 +421,7 @@ func TestService_handlePostBucket(t *testing.T) {
|
|||
"updatedAt": "0001-01-01T00:00:00Z",
|
||||
"id": "020f755c3c082000",
|
||||
"orgID": "6f626f7274697320",
|
||||
"type": "user",
|
||||
"name": "hello",
|
||||
"retentionRules": [],
|
||||
"labels": []
|
||||
|
@ -640,6 +644,7 @@ func TestService_handlePatchBucket(t *testing.T) {
|
|||
"updatedAt": "0001-01-01T00:00:00Z",
|
||||
"id": "020f755c3c082000",
|
||||
"orgID": "020f755c3c082000",
|
||||
"type": "user",
|
||||
"name": "example",
|
||||
"retentionRules": [{"type": "expire", "everySeconds": 2}],
|
||||
"labels": []
|
||||
|
@ -718,6 +723,7 @@ func TestService_handlePatchBucket(t *testing.T) {
|
|||
"updatedAt": "0001-01-01T00:00:00Z",
|
||||
"id": "020f755c3c082000",
|
||||
"orgID": "020f755c3c082000",
|
||||
"type": "user",
|
||||
"name": "bucket with no retention",
|
||||
"retentionRules": [],
|
||||
"labels": []
|
||||
|
@ -777,6 +783,7 @@ func TestService_handlePatchBucket(t *testing.T) {
|
|||
"updatedAt": "0001-01-01T00:00:00Z",
|
||||
"id": "020f755c3c082000",
|
||||
"orgID": "020f755c3c082000",
|
||||
"type": "user",
|
||||
"name": "b1",
|
||||
"retentionRules": [],
|
||||
"labels": []
|
||||
|
|
|
@ -6731,6 +6731,13 @@ components:
|
|||
id:
|
||||
readOnly: true
|
||||
type: string
|
||||
type:
|
||||
readOnly: true
|
||||
type: string
|
||||
default: user
|
||||
enum:
|
||||
- user
|
||||
- system
|
||||
name:
|
||||
type: string
|
||||
description:
|
||||
|
|
|
@ -233,6 +233,7 @@ func (s *Service) findSystemBucket(n string) (*platform.Bucket, error) {
|
|||
case "_tasks":
|
||||
return &platform.Bucket{
|
||||
ID: platform.TasksSystemBucketID,
|
||||
Type: platform.BucketTypeSystem,
|
||||
Name: "_tasks",
|
||||
RetentionPeriod: time.Hour * 24 * 3,
|
||||
Description: "System bucket for task logs",
|
||||
|
@ -240,6 +241,7 @@ func (s *Service) findSystemBucket(n string) (*platform.Bucket, error) {
|
|||
case "_monitoring":
|
||||
return &platform.Bucket{
|
||||
ID: platform.MonitoringSystemBucketID,
|
||||
Type: platform.BucketTypeSystem,
|
||||
Name: "_monitoring",
|
||||
RetentionPeriod: time.Hour * 24 * 7,
|
||||
Description: "System bucket for monitoring logs",
|
||||
|
|
|
@ -147,6 +147,7 @@ func (s *Service) findSystemBucket(n string) (*influxdb.Bucket, error) {
|
|||
case "_tasks":
|
||||
return &influxdb.Bucket{
|
||||
ID: influxdb.TasksSystemBucketID,
|
||||
Type: influxdb.BucketTypeSystem,
|
||||
Name: "_tasks",
|
||||
RetentionPeriod: time.Hour * 24 * 3,
|
||||
Description: "System bucket for task logs",
|
||||
|
@ -154,6 +155,7 @@ func (s *Service) findSystemBucket(n string) (*influxdb.Bucket, error) {
|
|||
case "_monitoring":
|
||||
return &influxdb.Bucket{
|
||||
ID: influxdb.MonitoringSystemBucketID,
|
||||
Type: influxdb.BucketTypeSystem,
|
||||
Name: "_monitoring",
|
||||
RetentionPeriod: time.Hour * 24 * 7,
|
||||
Description: "System bucket for monitoring logs",
|
||||
|
@ -502,6 +504,9 @@ func (s *Service) putBucket(ctx context.Context, tx Tx, b *influxdb.Bucket) erro
|
|||
span, _ := tracing.StartSpanFromContext(ctx)
|
||||
defer span.Finish()
|
||||
|
||||
// TODO(jade): remove this after we support storing system buckets
|
||||
b.Type = influxdb.BucketTypeUser
|
||||
|
||||
v, err := json.Marshal(b)
|
||||
if err != nil {
|
||||
return &influxdb.Error{
|
||||
|
|
Loading…
Reference in New Issue