Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Grafana's fork changes #686

Merged
merged 120 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 111 commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
39ec0ce
Update go.mod with new path
carrieedwards Jun 14, 2022
b7dbb6f
Merge pull request #19 from grafana/cedwards/update-go-mod
carrieedwards Jun 14, 2022
b4f114b
Update dependencies for CarbonAPI
carrieedwards Jun 15, 2022
f61c410
Merge pull request #20 from grafana/cedwards/update-dependencies
carrieedwards Jun 15, 2022
af21cba
Update imports to use grafana/carbonapi
carrieedwards Jun 15, 2022
a7fbdaa
Merge pull request #21 from grafana/cedwards/update-imports
carrieedwards Jun 15, 2022
4c11a5a
Add configuration for tests, coverage and linting on drone (#23)
carrieedwards Jul 8, 2022
718cc5d
Add support for Graphite web exp() function (#2)
carrieedwards Jul 12, 2022
40f705f
Remove references to pidfiles (#30)
carrieedwards Jul 13, 2022
92d075e
Add support for Graphite web logit() function (#14)
carrieedwards Jul 18, 2022
28ae5c2
Add support for Graphite web unique() function (#10)
carrieedwards Jul 18, 2022
160f16f
Update tags handling in expr functions to match Graphite web (#22)
carrieedwards Jul 19, 2022
695fb3f
Revert test changes so they fail on input mutability
npazosmendez Jul 19, 2022
d6e2e70
Clone MetricData to avoid mutating input when needed
npazosmendez Jul 19, 2022
4d8e542
Delete obsolete function
npazosmendez Jul 19, 2022
8c74625
Delete obsolete function
npazosmendez Jul 19, 2022
89fda16
Correct test assertions
npazosmendez Jul 19, 2022
ecb1570
Fix failing tests
npazosmendez Jul 19, 2022
5aafd59
Fix mutamility in logit function
npazosmendez Jul 19, 2022
fb037b2
Fix filing tests
npazosmendez Jul 19, 2022
af4020b
Copy metric slice on alignment
npazosmendez Jul 19, 2022
ac97c47
Merge pull request #31 from grafana/npazosmendez/dont-mutate-input
npazosmendez Jul 20, 2022
06d3807
Fix timeStack function
npazosmendez Jul 20, 2022
a212c8c
Merge branch 'main' into npazosmendez/dont-mutate-input
npazosmendez Jul 20, 2022
6d961d0
Fix other functions mutating input
npazosmendez Jul 20, 2022
9fb499c
Merge pull request #32 from grafana/npazosmendez/dont-mutate-input
npazosmendez Jul 20, 2022
f0b0db2
filterSeries should add 'name' tag
npazosmendez Jul 21, 2022
ddbff9b
aliasByMetric: set 'name' tag correctly
npazosmendez Jul 21, 2022
598f2f0
aliasByNode: always set 'name' tag
npazosmendez Jul 21, 2022
8d18608
Prefer arg.Name for metric name
npazosmendez Jul 21, 2022
cd6459e
Revert "filterSeries should add 'name' tag"
npazosmendez Jul 21, 2022
8100462
Revert "aliasByNode: always set 'name' tag"
npazosmendez Jul 21, 2022
faf9910
Fix groupByNode handling of queries with no callback provided (#34)
carrieedwards Jul 22, 2022
74ee465
Merge branch 'main' into npazosmendez/various-fixes
npazosmendez Jul 25, 2022
da64eae
Fix summarize function handling of tags (#35)
carrieedwards Jul 25, 2022
90386ae
Fix e2e tests: '@' is a valid character for names
npazosmendez Jul 25, 2022
4fa361d
Merge pull request #33 from grafana/npazosmendez/various-fixes
npazosmendez Jul 25, 2022
62d60dd
Fix .name in aggregation with wildcard functions
npazosmendez Jul 27, 2022
cdfb110
Merge pull request #37 from grafana/npazosmendez/aggregate-with-wildc…
npazosmendez Jul 27, 2022
8468b38
Add support for Graphite web sinFunction (#39)
carrieedwards Jul 27, 2022
2487ecd
Fix legendValue function so that optional system parameters are corre…
carrieedwards Jul 27, 2022
3f952f6
Add support for Graphite web's aggregateWithWildcards function (#4)
carrieedwards Jul 29, 2022
7e14877
Add powSeries function
leizor Jul 29, 2022
3e79874
Add support for Graphite web averageOutsidePercentile function (#44)
carrieedwards Aug 1, 2022
2dde0b6
Add support for Graphite web sigmoid() function (#15)
carrieedwards Aug 1, 2022
cce3163
Cache series values
leizor Aug 1, 2022
b82ff49
Add benchmark
leizor Aug 1, 2022
577ad8b
Add support for xFilesFactor and setXFilesFactor (#8)
carrieedwards Aug 1, 2022
cff82c6
Minor variable renaming
leizor Aug 2, 2022
5ff1e97
Merge pull request #42 from grafana/leizor/pow-series
leizor Aug 2, 2022
d3bd455
Add support for Graphite web removeBetweenPercentile() function (#24)
carrieedwards Aug 2, 2022
23be4f9
Add support for Graphite web identity function (#47)
carrieedwards Aug 2, 2022
2e11a50
Add support for Graphite web minMax() function (#18)
carrieedwards Aug 2, 2022
d59c9f5
Update COMPATIBILITY.md to reflect newly supported functions (#45)
carrieedwards Aug 2, 2022
0771e43
Add aggregateSeriesLists function
leizor Aug 2, 2022
c4d464a
Add tests that cause panics
npazosmendez Aug 3, 2022
aa8c074
Fix various functions panicking for empty input
npazosmendez Aug 3, 2022
1e641f6
Copy Tags to avoid mutating input (and panics)
npazosmendez Aug 3, 2022
7c77d61
Add failing and panicking tests
npazosmendez Aug 3, 2022
5f96514
Use GetNodeOrTagArgs helper for groupByNode
npazosmendez Aug 3, 2022
0e2942f
Merge pull request #51 from grafana/npazosmendez/fix-nil-tags-assignment
npazosmendez Aug 3, 2022
0dd4873
Merge pull request #53 from grafana/npazosmendez/fix-groupByNodes-panic
npazosmendez Aug 3, 2022
1fa2058
Default to xfilesfactor from input series
leizor Aug 3, 2022
4018fb6
Merge pull request #49 from grafana/leizor/aggregate-series-list
leizor Aug 3, 2022
8138b60
Merge pull request #50 from grafana/npazosmendez/fix-out-of-range-panics
npazosmendez Aug 4, 2022
40310c2
Add support for Graphite web movingWindow() function (#26)
carrieedwards Aug 4, 2022
9d91243
Add support for Graphite web exponentialMovingAverage function (#16)
carrieedwards Aug 8, 2022
2b62fc1
Add Github Actions workflow for syncing with upstream (#55)
carrieedwards Aug 8, 2022
dfa2c72
Set target's tag name to string version of window size (#58)
carrieedwards Aug 8, 2022
babf638
Fix error when no series exists in nested functions (#56)
carrieedwards Aug 8, 2022
0a50700
Pin version of ubuntu used for GH actions tests
leizor Aug 9, 2022
3640a73
Merge pull request #63 from grafana/leizor/flaky-tests
leizor Aug 9, 2022
064b23d
Implement verticalLine function
leizor Aug 3, 2022
e81ff9d
Add non-cairo version of verticalLine
leizor Aug 4, 2022
f7e907b
Clarify function for unsupported builds
leizor Aug 9, 2022
80622bb
Add aggregatedBy tag to *SeriesWithWildcards functions
leizor Aug 8, 2022
f862d03
Merge pull request #54 from grafana/leizor/vertical-line
leizor Aug 9, 2022
aa5337a
Merge pull request #59 from grafana/leizor/transmog/issue-1423
leizor Aug 9, 2022
0bcdac8
Add missing tags based on MetricData.Name
leizor Aug 8, 2022
a5b8ada
Add newly supported functions to compatibility doc (#67)
carrieedwards Aug 10, 2022
67f0e64
Merge pull request #66 from grafana/leizor/transmog/issue-1419
leizor Aug 10, 2022
0333910
Merge remote-tracking branch 'upstream/main' into npazosmendez/sync-u…
npazosmendez Aug 10, 2022
cab938e
Merge branch 'main' into npazosmendez/sync-upstream
npazosmendez Aug 10, 2022
8455d27
Pin ubuntu-22.04 to fix build
npazosmendez Aug 10, 2022
e18e46e
Please fix the e2e tests
npazosmendez Aug 10, 2022
ff089eb
Don't run e2e tests with go1.19
npazosmendez Aug 10, 2022
23e4e7e
Fix ubuntu tag again
npazosmendez Aug 10, 2022
65e84f0
Merge pull request #69 from grafana/npazosmendez/sync-upstream
npazosmendez Aug 11, 2022
ed01aa6
Merge branch 'go-graphite:main' into main
leizor Aug 22, 2022
454bfe0
Fix issue with version when syncing upstreaming in Github Actions (#74)
carrieedwards Aug 22, 2022
dd4a8e2
Update divideSeries handling of missing denominators (#73)
carrieedwards Aug 22, 2022
f0faed3
Fix tag handling in nested functions (#76)
carrieedwards Aug 23, 2022
adff392
Revert "Add missing tags based on MetricData.Name"
leizor Aug 23, 2022
70c5ee5
Merge pull request #79 from grafana/revert-66-leizor/transmog/issue-1419
leizor Aug 24, 2022
1cf8078
Allow inf as value for limit parameter in keepLastValue (#83)
carrieedwards Aug 26, 2022
a418fbd
Fix asPercent error when series has more values than totalSeries (#87)
carrieedwards Aug 30, 2022
c627d84
Use ExtractMetric for name parsing in aliasByMetric and sumSeriesWith…
carrieedwards Aug 30, 2022
072c479
Add consolidation function aliases to function mapping (#91)
carrieedwards Aug 30, 2022
299dc9d
Update spacing in removeBelowSeries assignment of name to match Graph…
carrieedwards Aug 31, 2022
5e17caf
Revert module identity change (#94)
npazosmendez Sep 2, 2022
7d90fad
Revert removal of pidfile and implement our own (#95)
npazosmendez Sep 5, 2022
45cf761
Merge remote-tracking branch 'upstream/main' into njpm/merge-upstream
npazosmendez Sep 5, 2022
9485b87
Fix GetCommonTags and its usage in aggregate
npazosmendez Sep 5, 2022
af3bd4c
Merge pull request #96 from grafana/njpm/merge-upstream
npazosmendez Sep 6, 2022
846e900
Delete Drone files and Sync Upstream Action
npazosmendez Sep 7, 2022
14050d5
Fix readme to refernce upstream
npazosmendez Sep 7, 2022
5d001e9
Merge pull request #98 from grafana/njpm/fix-readme
npazosmendez Sep 7, 2022
4ae1e1f
Merge branch 'main' into njpm/upstream-preparation
npazosmendez Sep 7, 2022
d511d4c
Uncomment 1.19 go tests in workflow
npazosmendez Sep 7, 2022
1c79b04
aliasByBase64: use CopyName to set name tag
npazosmendez Sep 9, 2022
9eb0a9e
Avoid fmt.SPrintf calls
npazosmendez Sep 9, 2022
1ecf628
cairo dashed: move arg parse out of cycle
npazosmendez Sep 9, 2022
58d7087
integralByInterval: avoid .Args() call
npazosmendez Sep 9, 2022
6b03de9
AggDiff consolidation: preallocate slice
npazosmendez Sep 9, 2022
d77e3ee
Fix metric name extracting in AggKey
npazosmendez Sep 12, 2022
7b2a1ee
Replace ExtractMetric calls with ExtractNameTag
npazosmendez Sep 12, 2022
4214530
Fix xFilesFactor handling in AggregateSeries and add tests (#107)
carrieedwards Sep 12, 2022
9faff07
Avoid double copy of tags in rangeOfSeries
npazosmendez Sep 12, 2022
2f8c064
Remove redundant isNaN check
leizor Sep 12, 2022
25738b8
Merge remote-tracking branch 'upstream/main' into njpm/upstream-prepa…
npazosmendez Sep 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ name = "go"
enabled = true

[analyzers.meta]
import_root = "github.com/go-graphite/carbonapi"
import_path = "github.com/go-graphite/carbonapi"
dependencies_vendored = true
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

tests:
name: Test code
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
go:
Expand Down
33 changes: 15 additions & 18 deletions COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,10 @@ _When `format=png`_ (default if not specified)
### Unsupported functions
| Function |
| :------------------------------------------------------------------------ |
| aggregateWithWildcards |
| aliasQuery |
| averageOutsidePercentile |
| events |
| exp |
| exponentialMovingAverage |
| holtWintersConfidenceArea |
| identity |
| logit |
| minMax |
| movingWindow |
| pct |
| powSeries |
| removeBetweenPercentile |
| setXFilesFactor |
| sigmoid |
| sin |
| sinFunction |
| unique |
| verticalLine |
| xFilesFactor |


### Partly supported functions
| Function | Incompatibilities |
Expand Down Expand Up @@ -187,6 +169,7 @@ reverse: default value mismatch: got (empty), should be false |
| add(seriesList, constant) | no |
| aggregate(seriesList, func, xFilesFactor=None) | no |
| aggregateLine(seriesList, func='average', keepStep=False) | no |
| aggregateWithWildcards(seriesList, func, *positions) | no |
| alias(seriesList, newName) | no |
| aliasByMetric(seriesList) | no |
| aliasByNode(seriesList, *nodes) | no |
Expand All @@ -198,6 +181,7 @@ reverse: default value mismatch: got (empty), should be false |
| asPercent(seriesList, total=None, *nodes) | no |
| averageAbove(seriesList, n) | no |
| averageBelow(seriesList, n) | no |
| averageOutsidePercentile(seriesList, n) | no |
| averageSeries(*seriesLists) | no |
| averageSeriesWithWildcards(seriesList, *position) | no |
| avg(*seriesLists) | no |
Expand All @@ -218,6 +202,8 @@ reverse: default value mismatch: got (empty), should be false |
| divideSeriesLists(dividendSeriesList, divisorSeriesList) | no |
| drawAsInfinite(seriesList) | no |
| exclude(seriesList, pattern) | no |
| exp(seriesList) | no |
| exponentialMovingAverage(seriesList, windowSize) | no |
| fallbackSeries(seriesList, fallback) | no |
| filterSeries(seriesList, func, operator, threshold) | no |
| grep(seriesList, pattern) | no |
Expand All @@ -233,6 +219,8 @@ reverse: default value mismatch: got (empty), should be false |
| holtWintersAberration(seriesList, delta=3, bootstrapInterval='7d') | no |
| holtWintersConfidenceBands(seriesList, delta=3, bootstrapInterval='7d') | no |
| holtWintersForecast(seriesList, bootstrapInterval='7d') | no |
| logit(seriesList) | no |
| identity(name) | no |
| integral(seriesList) | no |
| integralByInterval(seriesList, intervalString) | no |
| interpolate(seriesList, limit) | no |
Expand All @@ -255,12 +243,14 @@ reverse: default value mismatch: got (empty), should be false |
| minSeries(*seriesLists) | no |
| minimumAbove(seriesList, n) | no |
| minimumBelow(seriesList, n) | no |
| minMax(seriesList) | no |
| mostDeviant(seriesList, n) | no |
| movingAverage(seriesList, windowSize, xFilesFactor=None) | no |
| movingMax(seriesList, windowSize, xFilesFactor=None) | no |
| movingMedian(seriesList, windowSize, xFilesFactor=None) | no |
| movingMin(seriesList, windowSize, xFilesFactor=None) | no |
| movingSum(seriesList, windowSize, xFilesFactor=None) | no |
| movingWindow(seriesList, windowSize, func='average', xFilesFactor=None) | no |
| multiplySeries(*seriesLists) | no |
| multiplySeriesWithWildcards(seriesList, *position) | no |
| nPercentile(seriesList, n) | no |
Expand All @@ -270,6 +260,7 @@ reverse: default value mismatch: got (empty), should be false |
| perSecond(seriesList, maxValue=None) | no |
| percentileOfSeries(seriesList, n, interpolate=False) | no |
| pow(seriesList, factor) | no |
| powSeries(*seriesLists) | no |
| randomWalk(name, step=60) | no |
| randomWalkFunction(name, step=60) | no |
| rangeOfSeries(*seriesLists) | no |
Expand All @@ -279,12 +270,16 @@ reverse: default value mismatch: got (empty), should be false |
| removeAboveValue(seriesList, n) | no |
| removeBelowPercentile(seriesList, n) | no |
| removeBelowValue(seriesList, n) | no |
| removeBelowValue(seriesList, n) | no |
| removeEmptySeries(seriesList, xFilesFactor=None) | no |
| round(seriesList, precision) | no |
| scale(seriesList, factor) | no |
| scaleToSeconds(seriesList, seconds) | no |
| secondYAxis(seriesList) | no |
| seriesByTag(*tagExpressions) | no |
| setXFilesFactor(seriesList, xFilesFactor) | no |
| sigmoid(seriesList) | no |
| sinFunction(seriesList, amplitude=1, step=60) | no |
| smartSummarize(seriesList, intervalString, func='sum', alignTo=None) | no |
| sortBy(seriesList, func='average', reverse=False) | no |
| sortByMaxima(seriesList) | no |
Expand All @@ -307,8 +302,10 @@ reverse: default value mismatch: got (empty), should be false |
| timeSlice(seriesList, startSliceAt, endSliceAt='now') | no |
| timeStack(seriesList, timeShiftUnit='1d', timeShiftStart=0, timeShiftEnd=7) | no |
| transformNull(seriesList, default=0, referenceSeries=None) | no |
| unique(*seriesLists) | no |
| useSeriesAbove(seriesList, value, search, replace) | no |
| weightedAverage(seriesListAvg, seriesListWeight, *nodes) | no |
| verticalLine(ts, label=None, color=None) | no |
| aliasByBase64(seriesList) | yes |
| aliasByPostgres(seriesList, *nodes) | yes |
| aliasByRedis(seriesList. keyName) | yes |
Expand Down
7 changes: 3 additions & 4 deletions cmd/carbonapi/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"time"
"unicode"

"github.com/go-graphite/carbonapi/util/pidfile"
zipperConfig "github.com/go-graphite/carbonapi/zipper/config"

"github.com/ansel1/merry"
"github.com/facebookgo/pidfile"
"github.com/go-graphite/carbonapi/cache"
"github.com/go-graphite/carbonapi/expr/functions"
"github.com/go-graphite/carbonapi/expr/functions/cairo/png"
Expand Down Expand Up @@ -241,10 +241,9 @@ func SetUpConfig(logger *zap.Logger, BuildVersion string) {
}

if Config.PidFile != "" {
pidfile.SetPidfilePath(Config.PidFile)
err := pidfile.Write()
err := pidfile.WritePidFile(Config.PidFile)
if err != nil {
logger.Fatal("error during pidfile.Write()",
logger.Fatal("error when writing pidfile",
zap.Error(err),
)
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/carbonzipper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/ansel1/merry"

"github.com/dgryski/httputil"
"github.com/facebookgo/pidfile"
protov2 "github.com/go-graphite/protocol/carbonapi_v2_pb"
protov3 "github.com/go-graphite/protocol/carbonapi_v3_pb"
"github.com/lomik/zapwriter"
Expand All @@ -29,6 +28,7 @@ import (
"github.com/go-graphite/carbonapi/intervalset"
"github.com/go-graphite/carbonapi/mstats"
util "github.com/go-graphite/carbonapi/util/ctx"
"github.com/go-graphite/carbonapi/util/pidfile"
"github.com/go-graphite/carbonapi/zipper"
zipperConfig "github.com/go-graphite/carbonapi/zipper/config"
"github.com/go-graphite/carbonapi/zipper/types"
Expand Down Expand Up @@ -793,10 +793,9 @@ func main() {
}

if *pidFile != "" {
pidfile.SetPidfilePath(*pidFile)
err = pidfile.Write()
err := pidfile.WritePidFile(*pidFile)
if err != nil {
logger.Fatal("error during pidfile.Write()",
logger.Fatal("error when writing pidfile",
zap.Error(err),
)
}
Expand Down
47 changes: 32 additions & 15 deletions expr/consolidations/consolidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ var ConsolidationToFunc = map[string]func([]float64) float64{
"minimum": AggMin,
"multiply": summarizeToAggregate("multiply"),
"range": summarizeToAggregate("range"),
"rangeOf": summarizeToAggregate("rangeOf"),
"sum": AggSum,
"total": AggSum,
"stddev": summarizeToAggregate("stddev"),
"first": AggFirst,
"last": AggLast,
"current": AggLast,
}

var AvailableSummarizers = []string{"sum", "total", "avg", "average", "avg_zero", "max", "min", "last", "range", "median", "multiply", "diff", "count", "stddev"}
var AvailableSummarizers = []string{"sum", "total", "avg", "average", "avg_zero", "max", "min", "last", "current", "range", "rangeOf", "median", "multiply", "diff", "count", "stddev"}

// AvgValue returns average of list of values
func AvgValue(f64s []float64) float64 {
Expand Down Expand Up @@ -167,10 +170,10 @@ func SummarizeValues(f string, values []float64, XFilesFactor float32) float64 {
}
}
}
case "last":
case "last", "current":
rv = values[len(values)-1]
total = notNans(values)
case "range":
case "range", "rangeOf":
vMax := math.Inf(-1)
vMin := math.Inf(1)
isNaN := true
Expand All @@ -195,11 +198,14 @@ func SummarizeValues(f string, values []float64, XFilesFactor float32) float64 {
rv = Percentile(values, 50, true)
total = notNans(values)
case "multiply":
rv = values[0]
for _, av := range values[1:] {
if !math.IsNaN(av) {
rv = 1.0
for _, v := range values {
if math.IsNaN(v) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be add tests for this ?

rv = math.NaN()
break
} else {
total++
rv *= av
rv *= v
}
}
case "diff":
Expand Down Expand Up @@ -375,19 +381,30 @@ func AggCount(v []float64) float64 {
return float64(n)
}

// AggCount counts non-NaN points
func AggDiff(v []float64) float64 {
res := v[0]
if len(v) == 1 {
return res
}
for _, vv := range v[1:] {
safeValues := make([]float64, 0)
npazosmendez marked this conversation as resolved.
Show resolved Hide resolved
for _, vv := range v {
if !math.IsNaN(vv) {
res -= vv
safeValues = append(safeValues, vv)
}
}

return res
if len(safeValues) > 0 {
res := safeValues[0]
if len(safeValues) == 1 {
return res
}

for _, vv := range safeValues[1:] {
if !math.IsNaN(vv) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check really needed ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be simplified with one-pass scan and boolean flags is all is NaN ? It's more simple and has better performance (no copy slice elements).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oop, nice catch! Yep, this check is redundant; I suspect I accidentally left the original check in when I added the new safeValues slice. I think that safeValues slice is actually performing double duty here though:

  • It's useful for checking if all elements in v are NaN
  • It also helps us locate the first non-NaN value to initialize res with

res -= vv
}
}

return res
} else {
return math.NaN()
}
}

// MaxValue returns maximum from the list
Expand Down
1 change: 0 additions & 1 deletion expr/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func EvalExpr(ctx context.Context, e parser.Expr, from, until int64, values map[
parser.ErrBadType,
parser.ErrMissingArgument,
parser.ErrMissingTimeseries,
parser.ErrSeriesDoesNotExist,
parser.ErrUnknownTimeUnits,
) {
err = merry.WithHTTPCode(err, 400)
Expand Down
1 change: 1 addition & 0 deletions expr/functions/absolute/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (f *absolute) Do(ctx context.Context, e parser.Expr, from, until int64, val
}
r.Values[i] = math.Abs(v)
}
r.Tags["absolute"] = "1"
return r
})
}
Expand Down
42 changes: 29 additions & 13 deletions expr/functions/aggregate/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func New(configFile string) []interfaces.FunctionMetadata {
// aggregate(*seriesLists)
func (f *aggregate) Do(ctx context.Context, e parser.Expr, from, until int64, values map[parser.MetricRequest][]*types.MetricData) ([]*types.MetricData, error) {
var args []*types.MetricData
var xFilesFactor float64
isAggregateFunc := true

callback, err := e.GetStringArg(1)
Expand All @@ -52,23 +53,28 @@ func (f *aggregate) Do(ctx context.Context, e parser.Expr, from, until int64, va
if err != nil {
return nil, err
}
if len(args) == 0 {
return []*types.MetricData{}, nil
}
callback = strings.Replace(e.Target(), "Series", "", 1)
isAggregateFunc = false
xFilesFactor = -1 // xFilesFactor is not used by the ...Series functions
}
} else {
args, err = helper.GetSeriesArg(ctx, e.Arg(0), from, until, values)
if err != nil {
return nil, err
}
}
if len(args) == 0 {
return []*types.MetricData{}, nil
}

// TODO: Implement xFilesFactor
/*
xFilesFactor, err := e.GetFloatArgDefault(2, 0)
xFilesFactor, err = e.GetFloatArgDefault(2, float64(args[0].XFilesFactor)) // If set by setXFilesFactor, all series in a list will have the same value
if err != nil {
return false, nil, err
return nil, err
}
*/
}

aggFunc, ok := consolidations.ConsolidationToFunc[callback]
if !ok {
return nil, fmt.Errorf("unsupported consolidation function %s", callback)
Expand All @@ -79,7 +85,17 @@ func (f *aggregate) Do(ctx context.Context, e parser.Expr, from, until int64, va
if isAggregateFunc {
e.SetRawArgs(e.Arg(0).Target())
}
return helper.AggregateSeries(e, args, aggFunc, fconfig.Config.ExtractTagsFromArgs)

results, err := helper.AggregateSeries(e, args, aggFunc, xFilesFactor, fconfig.Config.ExtractTagsFromArgs)
if err != nil {
return nil, err
}

for _, result := range results {
result.Tags["aggregatedBy"] = callback
}

return results, nil
}

// Description is auto-generated description, based on output of https://github.com/graphite-project/graphite-web
Expand All @@ -105,12 +121,12 @@ func (f *aggregate) Description() map[string]types.FunctionDescription {
Required: true,
Options: types.StringsToSuggestionList(consolidations.AvailableConsolidationFuncs()),
},
/*
{
Name: "xFilesFactor",
Type: types.Float,
},
*/
{

Name: "xFilesFactor",
Type: types.Float,
Required: false,
},
},
SeriesChange: true, // function aggregate metrics or change series items count
NameChange: true, // name changed
Expand Down
Loading