You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 23, 2023. It is now read-only.
* update docs to include tags and meta section
* fix a bunch of bugs where previously data wasn't being deeply copied
* cleanly copy the meta section where needed
* clean up code with some helper functions
Copy file name to clipboardexpand all lines: api/models/series.go
+32-8
Original file line number
Diff line number
Diff line change
@@ -16,9 +16,9 @@ import (
16
16
//go:generate msgp
17
17
18
18
typeSeriesstruct {
19
-
Targetstring// for fetched data, set from models.Req.Target, i.e. the metric graphite key. for function output, whatever should be shown as target string (legend)
20
-
Datapoints []schema.Point
19
+
Targetstring// for fetched data, set from models.Req.Target, i.e. the metric graphite key. for function output, whatever should be shown as target string (legend)
21
20
Tagsmap[string]string// Must be set initially via call to `SetTags()`
21
+
Datapoints []schema.Point
22
22
Intervaluint32
23
23
QueryPattstring// to tie series back to request it came from. e.g. foo.bar.*, or if series outputted by func it would be e.g. scale(foo.bar.*,0.123456)
24
24
QueryFromuint32// to tie series back to request it came from
@@ -163,26 +163,50 @@ func (s *Series) buildTargetFromTags() {
163
163
s.Target=buf.String()
164
164
}
165
165
166
+
// Copy returns a deep copy.
167
+
// The returned value does not link to the same memory space for any of the properties
166
168
func (sSeries) Copy(emptyDatapoints []schema.Point) Series {
Copy file name to clipboardexpand all lines: devdocs/expr.md
+12-8
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,23 @@
1
1
## Management of point slices
2
2
3
-
The `models.Series` attribute `Datapoints []schema.Point` needs special atention:
3
+
The `models.Series` type, even when passed by value, has a few fields that need special attention:
4
+
*`Datapoints []schema.Point`
5
+
*`Tags map[string]string`
6
+
*`Meta SeriesMeta`
4
7
5
-
many processing functions will transform some of the points in datapoint slices. logically speaking, some output values are different than their input values,
6
-
while some may remain the same. they need a place to store their output.
8
+
Many processing functions will want to return an output series that differs from the input, in terms of (some of the) datapoints may have changed value, tags or metadata.
9
+
They need a place to store their output but we cannot simply operate on the input series, or even a copy of it, as the underlying datastructures are shared.
7
10
8
11
Goals:
9
-
* processing functions should not modify data in slices if those slices need to remain original (e.g. because they're re-used later)
10
-
* minimize allocations of new slices foremost and data copying (if point in= point out) as a smaller concern
12
+
* processing functions should not modify data if that data needs to remain original (e.g. because of re-use of the same input data elsewhere)
13
+
* minimize allocations of new structures foremost
14
+
* minimize data copying as a smaller concern
11
15
* simple code
12
16
13
17
there's 2 main choices:
14
18
15
19
1) copy-on-write:
16
-
- each function does not modify data in their inputs, they allocate new slices (or better: get from pool) in which they should store their output point values
20
+
- each function does not modify data in their inputs, they allocate new structures (or possibly get from pool) if there's differences with input
17
21
- storing output data into new slice can typically be done in same pass as processing the input data
18
22
- if you have lots of processing steps (graphite function calls) in a row, we will be creating more slices and copy data (for unmodified points) than strictly necessary.
19
23
- getting a slice from the pool may cause a stall if it's not large enough and runtime needs to re-allocate and copy
@@ -42,8 +46,8 @@ e.g. an avg of 3 series will create 1 new series (from pool), but won't put the
42
46
another processing step may require the same input data.
43
47
44
48
function implementations:
45
-
* must not modify existing slices
46
-
* should use the pool to get new slices in which to store their new/modified data.
49
+
* must not modify existing slices or maps or other composite datastructures (at the time of writing, it's only slices/maps)
50
+
* should use the pool to get new slices in which to store their new/modified datapoints.
47
51
* should add said new slices into the cache so it can later be cleaned
0 commit comments