1 // Copyright 2017, OpenCensus Authors
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
18 // AggType represents the type of aggregation function used on a View.
21 // All available aggregation types.
23 AggTypeNone AggType = iota // no aggregation; reserved for future use.
24 AggTypeCount // the count aggregation, see Count.
25 AggTypeSum // the sum aggregation, see Sum.
26 AggTypeDistribution // the distribution aggregation, see Distribution.
27 AggTypeLastValue // the last value aggregation, see LastValue.
30 func (t AggType) String() string {
34 var aggTypeName = map[AggType]string{
36 AggTypeCount: "Count",
38 AggTypeDistribution: "Distribution",
39 AggTypeLastValue: "LastValue",
42 // Aggregation represents a data aggregation method. Use one of the functions:
43 // Count, Sum, or Distribution to construct an Aggregation.
44 type Aggregation struct {
45 Type AggType // Type is the AggType of this Aggregation.
46 Buckets []float64 // Buckets are the bucket endpoints if this Aggregation represents a distribution, see Distribution.
48 newData func() AggregationData
52 aggCount = &Aggregation{
54 newData: func() AggregationData {
58 aggSum = &Aggregation{
60 newData: func() AggregationData {
66 // Count indicates that data collected and aggregated
67 // with this method will be turned into a count value.
68 // For example, total number of accepted requests can be
69 // aggregated by using Count.
70 func Count() *Aggregation {
74 // Sum indicates that data collected and aggregated
75 // with this method will be summed up.
76 // For example, accumulated request bytes can be aggregated by using
78 func Sum() *Aggregation {
82 // Distribution indicates that the desired aggregation is
83 // a histogram distribution.
85 // An distribution aggregation may contain a histogram of the values in the
86 // population. The bucket boundaries for that histogram are described
87 // by the bounds. This defines len(bounds)+1 buckets.
89 // If len(bounds) >= 2 then the boundaries for bucket index i are:
91 // [-infinity, bounds[i]) for i = 0
92 // [bounds[i-1], bounds[i]) for 0 < i < length
93 // [bounds[i-1], +infinity) for i = length
95 // If len(bounds) is 0 then there is no histogram associated with the
96 // distribution. There will be a single bucket with boundaries
97 // (-infinity, +infinity).
99 // If len(bounds) is 1 then there is no finite buckets, and that single
100 // element is the common boundary of the overflow and underflow buckets.
101 func Distribution(bounds ...float64) *Aggregation {
103 Type: AggTypeDistribution,
105 newData: func() AggregationData {
106 return newDistributionData(bounds)
111 // LastValue only reports the last value recorded using this
112 // aggregation. All other measurements will be dropped.
113 func LastValue() *Aggregation {
115 Type: AggTypeLastValue,
116 newData: func() AggregationData {
117 return &LastValueData{}