Skip to content

Commit 1c1184c

Browse files
committed
Allow AggregationOptions to be set for a namespace.
1 parent 9db8dc2 commit 1c1184c

File tree

6 files changed

+304
-10
lines changed

6 files changed

+304
-10
lines changed

docs/api.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ This document enumerates the Custom Resource Definitions used by the M3DB Operat
1212
* [M3DBClusterList](#m3dbclusterlist)
1313
* [M3DBStatus](#m3dbstatus)
1414
* [NodeAffinityTerm](#nodeaffinityterm)
15+
* [AggregatedAttributes](#aggregatedattributes)
16+
* [Aggregation](#aggregation)
17+
* [AggregationOptions](#aggregationoptions)
18+
* [DownsampleOptions](#downsampleoptions)
1519
* [IndexOptions](#indexoptions)
1620
* [Namespace](#namespace)
1721
* [NamespaceOptions](#namespaceoptions)
@@ -145,6 +149,48 @@ NodeAffinityTerm represents a node label and a set of label values, any of which
145149

146150
[Back to TOC](#table-of-contents)
147151

152+
## AggregatedAttributes
153+
154+
AggregatedAttributes are attributes specifying how data points are aggregated.
155+
156+
| Field | Description | Scheme | Required |
157+
| ----- | ----------- | ------ | -------- |
158+
| resolution | Resolution is the time range to aggregate data across. | string | false |
159+
| downsampleOptions | DownsampleOptions stores options for downsampling data points. | *[DownsampleOptions](#downsampleoptions) | false |
160+
161+
[Back to TOC](#table-of-contents)
162+
163+
## Aggregation
164+
165+
Aggregation describes data points within a namespace.
166+
167+
| Field | Description | Scheme | Required |
168+
| ----- | ----------- | ------ | -------- |
169+
| aggregated | Aggregated indicates whether data points are aggregated or not. | bool | false |
170+
| attributes | Attributes defines how data is aggregated when Aggregated is set to true. This field is ignored when aggregated is false. | [AggregatedAttributes](#aggregatedattributes) | false |
171+
172+
[Back to TOC](#table-of-contents)
173+
174+
## AggregationOptions
175+
176+
AggregationOptions is a set of options for aggregating data within the namespace.
177+
178+
| Field | Description | Scheme | Required |
179+
| ----- | ----------- | ------ | -------- |
180+
| aggregations | Aggregations are the aggregations for a namespace. | [][Aggregation](#aggregation) | false |
181+
182+
[Back to TOC](#table-of-contents)
183+
184+
## DownsampleOptions
185+
186+
DownsampleOptions is a set of options related to downsampling data.
187+
188+
| Field | Description | Scheme | Required |
189+
| ----- | ----------- | ------ | -------- |
190+
| all | All indicates whether to send data points to this namespace. If set to false, this namespace will not receive data points. In this case, data will need to be sent to the namespace via another mechanism (e.g. rollup/recording rules). | bool | false |
191+
192+
[Back to TOC](#table-of-contents)
193+
148194
## IndexOptions
149195

150196
IndexOptions defines parameters for indexing.
@@ -183,6 +229,7 @@ NamespaceOptions defines parameters for an M3DB namespace. See https://m3db.gith
183229
| retentionOptions | RetentionOptions sets the retention parameters. | [RetentionOptions](#retentionoptions) | false |
184230
| indexOptions | IndexOptions sets the indexing parameters. | [IndexOptions](#indexoptions) | false |
185231
| coldWritesEnabled | ColdWritesEnabled controls whether cold writes are enabled. | bool | false |
232+
| aggregationOptions | AggregationOptions sets the aggregation parameters. | [AggregationOptions](#aggregationoptions) | false |
186233

187234
[Back to TOC](#table-of-contents)
188235

pkg/apis/m3dboperator/v1alpha1/namespace.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,41 @@ type IndexOptions struct {
6363
BlockSize string `json:"blockSize,omitempty"`
6464
}
6565

66+
// AggregationOptions is a set of options for aggregating data
67+
// within the namespace.
68+
type AggregationOptions struct {
69+
// Aggregations are the aggregations for a namespace.
70+
Aggregations []Aggregation `json:"aggregations,omitempty"`
71+
}
72+
73+
// Aggregation describes data points within a namespace.
74+
type Aggregation struct {
75+
// Aggregated indicates whether data points are aggregated or not.
76+
Aggregated bool `json:"aggregated,omitempty"`
77+
78+
// Attributes defines how data is aggregated when Aggregated is set to true.
79+
// This field is ignored when aggregated is false.
80+
Attributes AggregatedAttributes `json:"attributes,omitempty"`
81+
}
82+
83+
// AggregatedAttributes are attributes specifying how data points are aggregated.
84+
type AggregatedAttributes struct {
85+
// Resolution is the time range to aggregate data across.
86+
Resolution string `json:"resolution,omitempty"`
87+
88+
// DownsampleOptions stores options for downsampling data points.
89+
DownsampleOptions *DownsampleOptions `json:"downsampleOptions,omitempty"`
90+
}
91+
92+
// DownsampleOptions is a set of options related to downsampling data.
93+
type DownsampleOptions struct {
94+
// All indicates whether to send data points to this namespace.
95+
// If set to false, this namespace will not receive data points. In this
96+
// case, data will need to be sent to the namespace via another mechanism
97+
// (e.g. rollup/recording rules).
98+
All bool `json:"all,omitempty"`
99+
}
100+
66101
// NamespaceOptions defines parameters for an M3DB namespace. See
67102
// https://m3db.github.io/m3/operational_guide/namespace_configuration/ for more
68103
// details.
@@ -93,4 +128,7 @@ type NamespaceOptions struct {
93128

94129
// ColdWritesEnabled controls whether cold writes are enabled.
95130
ColdWritesEnabled bool `json:"coldWritesEnabled,omitempty"`
131+
132+
// AggregationOptions sets the aggregation parameters.
133+
AggregationOptions AggregationOptions `json:"aggregationOptions,omitempty"`
96134
}

pkg/apis/m3dboperator/v1alpha1/zz_generated.deepcopy.go

Lines changed: 79 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/m3admin/namespace/namespace.go

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,22 @@ func m3dbNamespaceOptsFromSpec(opts *myspec.NamespaceOptions) (*m3ns.NamespaceOp
9090
return nil, err
9191
}
9292

93+
aggOpts, err := m3dbAggregationOptsFromSpec(opts.AggregationOptions)
94+
if err != nil {
95+
return nil, err
96+
}
97+
9398
return &m3ns.NamespaceOptions{
94-
BootstrapEnabled: opts.BootstrapEnabled,
95-
FlushEnabled: opts.FlushEnabled,
96-
WritesToCommitLog: opts.WritesToCommitLog,
97-
CleanupEnabled: opts.CleanupEnabled,
98-
RepairEnabled: opts.RepairEnabled,
99-
RetentionOptions: retentionOpts,
100-
SnapshotEnabled: opts.SnapshotEnabled,
101-
IndexOptions: indexOpts,
102-
ColdWritesEnabled: opts.ColdWritesEnabled,
99+
BootstrapEnabled: opts.BootstrapEnabled,
100+
FlushEnabled: opts.FlushEnabled,
101+
WritesToCommitLog: opts.WritesToCommitLog,
102+
CleanupEnabled: opts.CleanupEnabled,
103+
RepairEnabled: opts.RepairEnabled,
104+
RetentionOptions: retentionOpts,
105+
SnapshotEnabled: opts.SnapshotEnabled,
106+
IndexOptions: indexOpts,
107+
ColdWritesEnabled: opts.ColdWritesEnabled,
108+
AggregationOptions: aggOpts,
103109
}, nil
104110
}
105111

@@ -150,3 +156,39 @@ func m3dbIndexOptsFromSpec(opts myspec.IndexOptions) (*m3ns.IndexOptions, error)
150156
BlockSizeNanos: blockSize.Nanoseconds(),
151157
}, nil
152158
}
159+
160+
func m3dbAggregationOptsFromSpec(opts myspec.AggregationOptions) (*m3ns.AggregationOptions, error) {
161+
if len(opts.Aggregations) == 0 {
162+
return nil, nil
163+
}
164+
165+
aggs := make([]*m3ns.Aggregation, 0, len(opts.Aggregations))
166+
for _, specAgg := range opts.Aggregations {
167+
agg := &m3ns.Aggregation{Aggregated: specAgg.Aggregated}
168+
if agg.Aggregated {
169+
resolution, err := time.ParseDuration(specAgg.Attributes.Resolution)
170+
if err != nil {
171+
return nil, fmt.Errorf("failed to parse aggregation option Resolution: %w", err)
172+
}
173+
174+
agg.Attributes = &m3ns.AggregatedAttributes{
175+
ResolutionNanos: resolution.Nanoseconds(),
176+
}
177+
178+
if specAgg.Attributes.DownsampleOptions == nil {
179+
agg.Attributes.DownsampleOptions = &m3ns.DownsampleOptions{All: true}
180+
} else {
181+
agg.Attributes.DownsampleOptions = &m3ns.DownsampleOptions{
182+
All: specAgg.Attributes.DownsampleOptions.All,
183+
}
184+
}
185+
}
186+
187+
aggs = append(aggs, agg)
188+
}
189+
190+
return &m3ns.AggregationOptions{
191+
Aggregations: aggs,
192+
}, nil
193+
194+
}

pkg/m3admin/namespace/namespace_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func TestRequestFromSpec(t *testing.T) {
7979
BlockSize: "1s",
8080
Enabled: true,
8181
},
82+
AggregationOptions: myspec.AggregationOptions{
83+
Aggregations: []myspec.Aggregation{
84+
{Aggregated: false},
85+
},
86+
},
8287
},
8388
},
8489
req: &admin.NamespaceAddRequest{
@@ -97,6 +102,70 @@ func TestRequestFromSpec(t *testing.T) {
97102
BlockSizeNanos: 1000000000,
98103
Enabled: true,
99104
},
105+
AggregationOptions: &m3ns.AggregationOptions{
106+
Aggregations: []*m3ns.Aggregation{
107+
{Aggregated: false},
108+
},
109+
},
110+
},
111+
},
112+
},
113+
{
114+
ns: myspec.Namespace{
115+
Name: "aggregated",
116+
Options: &myspec.NamespaceOptions{
117+
BootstrapEnabled: true,
118+
RetentionOptions: myspec.RetentionOptions{
119+
RetentionPeriod: "1s",
120+
BlockSize: "1s",
121+
BufferFuture: "1s",
122+
BufferPast: "1s",
123+
BlockDataExpiry: true,
124+
BlockDataExpiryAfterNotAccessPeriod: "1s",
125+
},
126+
IndexOptions: myspec.IndexOptions{
127+
BlockSize: "1s",
128+
Enabled: true,
129+
},
130+
AggregationOptions: myspec.AggregationOptions{
131+
Aggregations: []myspec.Aggregation{
132+
{
133+
Aggregated: true,
134+
Attributes: myspec.AggregatedAttributes{
135+
Resolution: "1s",
136+
},
137+
},
138+
},
139+
},
140+
},
141+
},
142+
req: &admin.NamespaceAddRequest{
143+
Name: "aggregated",
144+
Options: &m3ns.NamespaceOptions{
145+
BootstrapEnabled: true,
146+
RetentionOptions: &m3ns.RetentionOptions{
147+
RetentionPeriodNanos: 1000000000,
148+
BlockSizeNanos: 1000000000,
149+
BufferFutureNanos: 1000000000,
150+
BufferPastNanos: 1000000000,
151+
BlockDataExpiry: true,
152+
BlockDataExpiryAfterNotAccessPeriodNanos: 1000000000,
153+
},
154+
IndexOptions: &m3ns.IndexOptions{
155+
BlockSizeNanos: 1000000000,
156+
Enabled: true,
157+
},
158+
AggregationOptions: &m3ns.AggregationOptions{
159+
Aggregations: []*m3ns.Aggregation{
160+
{
161+
Aggregated: true,
162+
Attributes: &m3ns.AggregatedAttributes{
163+
ResolutionNanos: 1000000000,
164+
DownsampleOptions: &m3ns.DownsampleOptions{All: true},
165+
},
166+
},
167+
},
168+
},
100169
},
101170
},
102171
},

0 commit comments

Comments
 (0)