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

Commit 1f78d5a

Browse files
committed
make fetch optimizations optional
1 parent b366e4b commit 1f78d5a

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

api/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828
getTargetsConcurrency int
2929
tagdbDefaultLimit uint
3030
speculationThreshold float64
31+
fetchOptimizations bool
3132

3233
graphiteProxy *httputil.ReverseProxy
3334
timeZone *time.Location
@@ -49,6 +50,7 @@ func ConfigSetup() {
4950
apiCfg.IntVar(&getTargetsConcurrency, "get-targets-concurrency", 20, "maximum number of concurrent threads for fetching data on the local node. Each thread handles a single series.")
5051
apiCfg.UintVar(&tagdbDefaultLimit, "tagdb-default-limit", 100, "default limit for tagdb query results, can be overridden with query parameter \"limit\"")
5152
apiCfg.Float64Var(&speculationThreshold, "speculation-threshold", 1, "ratio of peer responses after which speculation is used. Set to 1 to disable.")
53+
apiCfg.BoolVar(&fetchOptimizations, "fetch-optimization", false, "enable MaxDataPoints optimization and pre-normalization optimizations")
5254
globalconf.Register("http", apiCfg, flag.ExitOnError)
5355
}
5456

api/graphite.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (s *Server) renderMetrics(ctx *middleware.Context, request models.GraphiteR
225225
// as graphite needs high-res data to perform its processing.
226226
mdp = 0
227227
}
228-
plan, err := expr.NewPlan(exprs, fromUnix, toUnix, mdp, stable)
228+
plan, err := expr.NewPlan(exprs, fromUnix, toUnix, mdp, stable, fetchOptimizations)
229229
if err != nil {
230230
if fun, ok := err.(expr.ErrUnknownFunction); ok {
231231
if request.NoProxy {
@@ -1388,7 +1388,7 @@ func (s *Server) showPlan(ctx *middleware.Context, request models.GraphiteRender
13881388
stable := request.Process == "stable"
13891389
mdp := request.MaxDataPoints
13901390

1391-
plan, err := expr.NewPlan(exprs, fromUnix, toUnix, mdp, stable)
1391+
plan, err := expr.NewPlan(exprs, fromUnix, toUnix, mdp, stable, fetchOptimizations)
13921392
if err != nil {
13931393
response.Write(ctx, response.NewError(http.StatusBadRequest, err.Error()))
13941394
return

expr/funcs.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77

88
// Context describes a series timeframe and consolidator
99
type Context struct {
10-
from uint32
11-
to uint32
12-
consol consolidation.Consolidator // can be 0 to mean undefined
13-
PNGroup models.PNGroup // pre-normalization group. if the data can be safely pre-normalized
14-
MDP uint32 // if we can MDP-optimize, reflects runtime consolidation MaxDataPoints. 0 otherwise
10+
from uint32
11+
to uint32
12+
consol consolidation.Consolidator // can be 0 to mean undefined
13+
PNGroup models.PNGroup // pre-normalization group. if the data can be safely pre-normalized
14+
MDP uint32 // if we can MDP-optimize, reflects runtime consolidation MaxDataPoints. 0 otherwise
15+
fetchOptimizations bool // disable PNGroups and MDP
1516
}
1617

1718
// GraphiteFunc defines a graphite processing function

expr/plan.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ func NewReq(query string, from, to uint32, cons consolidation.Consolidator) Req
3434
}
3535

3636
func NewReqFromContext(query string, c Context) Req {
37-
return Req{
38-
Query: query,
39-
From: c.from,
40-
To: c.to,
41-
Cons: c.consol,
42-
PNGroup: c.PNGroup,
43-
MDP: c.MDP,
37+
r := Req{
38+
Query: query,
39+
From: c.from,
40+
To: c.to,
41+
Cons: c.consol,
42+
}
43+
if c.fetchOptimizations {
44+
r.PNGroup = c.PNGroup
45+
r.MDP = c.MDP
4446
}
47+
return r
4548
}
4649

4750
// NewReqFromSeries generates a Req back from a series
@@ -105,7 +108,7 @@ func (p Plan) Dump(w io.Writer) {
105108
// * validation of arguments
106109
// * allow functions to modify the Context (change data range or consolidation)
107110
// * future version: allow functions to mark safe to pre-aggregate using consolidateBy or not
108-
func NewPlan(exprs []*expr, from, to, mdp uint32, stable bool) (Plan, error) {
111+
func NewPlan(exprs []*expr, from, to, mdp uint32, stable, fetchOptimizations bool) (Plan, error) {
109112
plan := Plan{
110113
exprs: exprs,
111114
MaxDataPoints: mdp,
@@ -114,10 +117,11 @@ func NewPlan(exprs []*expr, from, to, mdp uint32, stable bool) (Plan, error) {
114117
}
115118
for _, e := range exprs {
116119
context := Context{
117-
from: from,
118-
to: to,
119-
MDP: mdp,
120-
PNGroup: 0, // making this explicit here for easy code grepping
120+
from: from,
121+
to: to,
122+
MDP: mdp,
123+
PNGroup: 0, // making this explicit here for easy code grepping
124+
fetchOptimizations: fetchOptimizations,
121125
}
122126
fn, reqs, err := newplan(e, context, stable, plan.Reqs)
123127
if err != nil {

metrictank-sample.ini

+2
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ get-targets-concurrency = 20
248248
tagdb-default-limit = 100
249249
# ratio of peer responses after which speculative querying (aka spec-exec) is used. Set to 1 to disable.
250250
speculation-threshold = 1
251+
# enable MaxDataPoints optimization and pre-normalization optimizations
252+
fetch-optimizations = false
251253

252254
## metric data inputs ##
253255

0 commit comments

Comments
 (0)