Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 7198dfb

Browse files
committed
robert feedback
1 parent d5c4228 commit 7198dfb

File tree

6 files changed

+36
-17
lines changed

6 files changed

+36
-17
lines changed

api/graphite.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ func (s *Server) renderMetrics(ctx *middleware.Context, request models.GraphiteR
226226
mdp = 0
227227
}
228228

229-
opts := optimizations.ApplyUserPrefs(request.Optimizations)
229+
opts, err := optimizations.ApplyUserPrefs(request.Optimizations)
230+
if err != nil {
231+
response.Write(ctx, response.NewError(http.StatusBadRequest, err.Error()))
232+
return
233+
}
230234
plan, err := expr.NewPlan(exprs, fromUnix, toUnix, mdp, stable, opts)
231235
if err != nil {
232236
if fun, ok := err.(expr.ErrUnknownFunction); ok {
@@ -1422,7 +1426,11 @@ func (s *Server) showPlan(ctx *middleware.Context, request models.GraphiteRender
14221426
stable := request.Process == "stable"
14231427
mdp := request.MaxDataPoints
14241428

1425-
opts := optimizations.ApplyUserPrefs(request.Optimizations)
1429+
opts, err := optimizations.ApplyUserPrefs(request.Optimizations)
1430+
if err != nil {
1431+
response.Write(ctx, response.NewError(http.StatusBadRequest, err.Error()))
1432+
return
1433+
}
14261434
plan, err := expr.NewPlan(exprs, fromUnix, toUnix, mdp, stable, opts)
14271435
if err != nil {
14281436
response.Write(ctx, response.NewError(http.StatusBadRequest, err.Error()))

api/graphite_req.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func NewReqMap() *ReqMap {
2121
}
2222
}
2323

24+
// Add adds a models.Req to the ReqMap
2425
func (r *ReqMap) Add(req models.Req) {
2526
r.cnt++
2627
if req.PNGroup == 0 {
@@ -29,6 +30,8 @@ func (r *ReqMap) Add(req models.Req) {
2930
}
3031
r.pngroups[req.PNGroup] = append(r.pngroups[req.PNGroup], req)
3132
}
33+
34+
// Dump provides a human readable string representation of the ReqsMap
3235
func (r ReqMap) Dump() string {
3336
out := fmt.Sprintf("ReqsMap (%d entries):\n", r.cnt)
3437
out += " Groups:\n"
@@ -51,13 +54,14 @@ type PNGroupSplit struct {
5154
mdpno []models.Req // not MDP-optimizable reqs
5255
}
5356

54-
// ReqsPlan holds requests that have been planned
57+
// ReqsPlan holds requests that have been planned, broken down by PNGroup and MDP-optimizability
5558
type ReqsPlan struct {
5659
pngroups map[models.PNGroup]PNGroupSplit
5760
single PNGroupSplit
5861
cnt uint32
5962
}
6063

64+
// NewReqsPlan generates a ReqsPlan based on the provided ReqMap.
6165
func NewReqsPlan(reqs ReqMap) ReqsPlan {
6266
rp := ReqsPlan{
6367
pngroups: make(map[models.PNGroup]PNGroupSplit),
@@ -84,6 +88,7 @@ func NewReqsPlan(reqs ReqMap) ReqsPlan {
8488
return rp
8589
}
8690

91+
// PointsFetch returns how many points this plan will fetch when executed
8792
func (rp ReqsPlan) PointsFetch() uint32 {
8893
var cnt uint32
8994
for _, r := range rp.single.mdpyes {
@@ -103,6 +108,7 @@ func (rp ReqsPlan) PointsFetch() uint32 {
103108
return cnt
104109
}
105110

111+
// Dump provides a human readable string representation of the ReqsPlan
106112
func (rp ReqsPlan) Dump() string {
107113
out := fmt.Sprintf("ReqsPlan (%d entries):\n", rp.cnt)
108114
out += " Groups:\n"
@@ -148,6 +154,7 @@ func (rp ReqsPlan) PointsReturn(planMDP uint32) uint32 {
148154
return cnt
149155
}
150156

157+
// List returns the requests contained within the plan as a slice
151158
func (rp ReqsPlan) List() []models.Req {
152159
l := make([]models.Req, 0, rp.cnt)
153160
l = append(l, rp.single.mdpno...)

api/models/request.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type Req struct {
5252
// PNGroup is an identifier for a pre-normalization group: data that can be pre-normalized together
5353
type PNGroup uint64
5454

55-
// NewReq creates a new request. It sets all properties minus the ones that need request planning
55+
// NewReq creates a new request. It sets all properties except the ones that need request planning
5656
func NewReq(key schema.MKey, target, patt string, from, to, maxPoints, rawInterval uint32, pngroup PNGroup, cons, consReq consolidation.Consolidator, node cluster.Node, schemaId, aggId uint16) Req {
5757
return Req{
5858
MKey: key,
@@ -72,7 +72,7 @@ func NewReq(key schema.MKey, target, patt string, from, to, maxPoints, rawInterv
7272
}
7373

7474
// Init initializes a request based on the metadata that we know of.
75-
// It sets all properties minus the ones that need request planning
75+
// It sets all properties except the ones that need request planning
7676
func (r *Req) Init(archive idx.Archive, cons consolidation.Consolidator, node cluster.Node) {
7777
r.MKey = archive.Id
7878
r.Target = archive.NameWithTags()
@@ -97,6 +97,7 @@ func (r *Req) Plan(i int, ret conf.Retention) {
9797
r.AggNum = 1
9898
}
9999

100+
// PlanNormalization updates the planning parameters to accommodate normalization to the specified interval
100101
func (r *Req) PlanNormalization(interval uint32) {
101102
r.OutInterval = interval
102103
r.AggNum = interval / r.ArchInterval
@@ -130,6 +131,7 @@ func (r *Req) AdjustTo(interval, from uint32, rets []conf.Retention) {
130131
r.PlanNormalization(interval)
131132
}
132133

134+
// PointsFetch returns how many points this request will fetch when executed
133135
func (r Req) PointsFetch() uint32 {
134136
return (r.To - r.From) / r.ArchInterval
135137
}

devdocs/render-request-handling.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121

2222
## MDP-optimization
2323

24-
MDP at the leaf of the expr tree (fetch request) 0 means don't optimize, set it to >0 means, can be optimized.
24+
MDP at the leaf of the expr tree (fetch request) of 0 means don't optimize. If set it to >0 it means the request can be optimized.
2525
When the data may be subjected to a GR-function, we set it to 0.
2626
How do we achieve this?
27-
* MDP at the root is set 0 if request came from graphite or to MaxDataPoints otherwise.
28-
* as the context flows from root through the processing functions to the data requests, if we hit a GR function, we set to MDP to 0 on the context (and thus also on any subsequent requests)
27+
* MDP at the root is set 0 if the request came from graphite or to MaxDataPoints otherwise.
28+
* as the context flows from root through the processing functions to the data requests, if we hit a GR function, we set MDP to 0 on the context (and thus also on any subsequent requests)
2929

3030
## Pre-normalization
3131

3232
Any data requested (checked at the leaf node of the expr tree) should have its own independent interval.
33-
However, multiple series getting fetched that then get aggregated together, may be pre-normalized if they are part of the same pre-normalization-group. ( have a common PNGroup that is > 0 )
33+
However, multiple series getting fetched that then get aggregated together may be pre-normalized if they are part of the same pre-normalization-group (have a common PNGroup that is > 0).
3434
(for more details see devdocs/alignrequests-too-course-grained.txt)
3535
The mechanics here are:
3636
* we set PNGroup to 0 by default on the context, which gets inherited down the tree

expr/func_divideseries.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (s *FuncDivideSeries) Exec(cache map[Req][]models.Series) ([]models.Series,
6161
// and we'll possibly need to normalize it to different intervals (if the dividends have differing intervals)
6262
// (we also need to normalize if there's only 1 dividend but it has a different interval than the divisor)
6363
// so let's keep track of the different "versions" of the divisor that we have available.
64-
// (the dividend(s) may also need to be normalized but we only use them once so the require no special attention)
64+
// (the dividend(s) may also need to be normalized but we only use them once so they don't require special attention)
6565
divisorsByRes := make(map[uint32]models.Series)
6666
divisorsByRes[divisors[0].Interval] = divisors[0]
6767
for _, dividend := range dividends {

expr/plan.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,29 @@ type Optimizations struct {
1515
MDP bool
1616
}
1717

18-
func (o Optimizations) ApplyUserPrefs(s string) Optimizations {
18+
func (o Optimizations) ApplyUserPrefs(s string) (Optimizations, error) {
1919
// no user override. stick to what we have
2020
if s == "" {
21-
return o
21+
return o, nil
2222
}
2323
// user passed an override. it's either 'none' (no optimizations) or a list of the ones that should be enabled
2424
o.PreNormalization = false
2525
o.MDP = false
2626
if s == "none" {
27-
return o
27+
return o, nil
2828
}
2929
prefs := strings.Split(s, ",")
3030
for _, pref := range prefs {
31-
if pref == "pn" {
31+
switch pref {
32+
case "pn":
3233
o.PreNormalization = true
33-
}
34-
if pref == "mdp" {
34+
case "mdp":
3535
o.MDP = true
36+
default:
37+
return o, fmt.Errorf("unrecognized optimization %q", pref)
3638
}
3739
}
38-
return o
40+
return o, nil
3941
}
4042

4143
// Req represents a request for one/more series

0 commit comments

Comments
 (0)