1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 type ExportMetricsServiceRequest struct {
13 Node *Node `json:"node,omitempty"`
14 Metrics []*Metric `json:"metrics,omitempty"`
15 Resource *Resource `json:"resource,omitempty"`
19 MetricDescriptor *MetricDescriptor `json:"metric_descriptor,omitempty"`
20 Timeseries []*TimeSeries `json:"timeseries,omitempty"`
21 Resource *Resource `json:"resource,omitempty"`
24 type MetricDescriptor struct {
25 Name string `json:"name,omitempty"`
26 Description string `json:"description,omitempty"`
27 Unit string `json:"unit,omitempty"`
28 Type MetricDescriptor_Type `json:"type,omitempty"`
29 LabelKeys []*LabelKey `json:"label_keys,omitempty"`
32 type MetricDescriptor_Type int32
35 MetricDescriptor_UNSPECIFIED MetricDescriptor_Type = 0
36 MetricDescriptor_GAUGE_INT64 MetricDescriptor_Type = 1
37 MetricDescriptor_GAUGE_DOUBLE MetricDescriptor_Type = 2
38 MetricDescriptor_GAUGE_DISTRIBUTION MetricDescriptor_Type = 3
39 MetricDescriptor_CUMULATIVE_INT64 MetricDescriptor_Type = 4
40 MetricDescriptor_CUMULATIVE_DOUBLE MetricDescriptor_Type = 5
41 MetricDescriptor_CUMULATIVE_DISTRIBUTION MetricDescriptor_Type = 6
42 MetricDescriptor_SUMMARY MetricDescriptor_Type = 7
45 type LabelKey struct {
46 Key string `json:"key,omitempty"`
47 Description string `json:"description,omitempty"`
50 type TimeSeries struct {
51 StartTimestamp *Timestamp `json:"start_timestamp,omitempty"`
52 LabelValues []*LabelValue `json:"label_values,omitempty"`
53 Points []*Point `json:"points,omitempty"`
56 type LabelValue struct {
57 Value string `json:"value,omitempty"`
58 HasValue bool `json:"has_value,omitempty"`
62 Timestamp *Timestamp `json:"timestamp,omitempty"`
63 Value PointValue `json:"value,omitempty"`
66 type PointInt64Value struct {
67 Int64Value int64 `json:"int64Value,omitempty"`
70 // MarshalJSON creates JSON formatted the same way as jsonpb so that the
71 // OpenCensus service can correctly determine the underlying value type.
72 // This custom MarshalJSON exists because,
73 // by default *Point is JSON marshalled as:
74 // {"value": {"int64Value": 1}}
75 // but it should be marshalled as:
77 func (p *Point) MarshalJSON() ([]byte, error) {
79 return []byte("null"), nil
82 switch d := p.Value.(type) {
84 return json.Marshal(&struct {
85 Timestamp *Timestamp `json:"timestamp,omitempty"`
86 Value int64 `json:"int64Value,omitempty"`
88 Timestamp: p.Timestamp,
91 case PointDoubleValue:
92 return json.Marshal(&struct {
93 Timestamp *Timestamp `json:"timestamp,omitempty"`
94 Value float64 `json:"doubleValue,omitempty"`
96 Timestamp: p.Timestamp,
99 case PointDistributionValue:
100 return json.Marshal(&struct {
101 Timestamp *Timestamp `json:"timestamp,omitempty"`
102 Value *DistributionValue `json:"distributionValue,omitempty"`
104 Timestamp: p.Timestamp,
105 Value: d.DistributionValue,
108 return nil, fmt.Errorf("unknown point type %T", p.Value)
112 type PointDoubleValue struct {
113 DoubleValue float64 `json:"doubleValue,omitempty"`
116 type PointDistributionValue struct {
117 DistributionValue *DistributionValue `json:"distributionValue,omitempty"`
120 type PointSummaryValue struct {
121 SummaryValue *SummaryValue `json:"summaryValue,omitempty"`
124 type PointValue interface {
128 func (PointInt64Value) labelPointValue() {}
129 func (PointDoubleValue) labelPointValue() {}
130 func (PointDistributionValue) labelPointValue() {}
131 func (PointSummaryValue) labelPointValue() {}
133 type DistributionValue struct {
134 Count int64 `json:"count,omitempty"`
135 Sum float64 `json:"sum,omitempty"`
136 SumOfSquaredDeviation float64 `json:"sum_of_squared_deviation,omitempty"`
137 BucketOptions BucketOptions `json:"bucket_options,omitempty"`
138 Buckets []*Bucket `json:"buckets,omitempty"`
141 type BucketOptionsExplicit struct {
142 Bounds []float64 `json:"bounds,omitempty"`
145 type BucketOptions interface {
149 func (*BucketOptionsExplicit) labelBucketOptions() {}
151 var _ BucketOptions = (*BucketOptionsExplicit)(nil)
152 var _ json.Marshaler = (*BucketOptionsExplicit)(nil)
154 // Declared for the purpose of custom JSON marshaling without cycles.
155 type bucketOptionsExplicitAlias BucketOptionsExplicit
157 // MarshalJSON creates JSON formatted the same way as jsonpb so that the
158 // OpenCensus service can correctly determine the underlying value type.
159 // This custom MarshalJSON exists because,
160 // by default BucketOptionsExplicit is JSON marshalled as:
161 // {"bounds":[1,2,3]}
162 // but it should be marshalled as:
163 // {"explicit":{"bounds":[1,2,3]}}
164 func (be *BucketOptionsExplicit) MarshalJSON() ([]byte, error) {
165 return json.Marshal(&struct {
166 Explicit *bucketOptionsExplicitAlias `json:"explicit,omitempty"`
168 Explicit: (*bucketOptionsExplicitAlias)(be),
173 Count int64 `json:"count,omitempty"`
174 Exemplar *Exemplar `json:"exemplar,omitempty"`
177 type Exemplar struct {
178 Value float64 `json:"value,omitempty"`
179 Timestamp *Timestamp `json:"timestamp,omitempty"`
180 Attachments map[string]string `json:"attachments,omitempty"`
183 type SummaryValue struct {
184 Count *Int64Value `json:"count,omitempty"`
185 Sum *DoubleValue `json:"sum,omitempty"`
186 Snapshot *Snapshot `json:"snapshot,omitempty"`
189 type Snapshot struct {
190 Count *Int64Value `json:"count,omitempty"`
191 Sum *DoubleValue `json:"sum,omitempty"`
192 PercentileValues []*SnapshotValueAtPercentile `json:"percentile_values,omitempty"`
195 type SnapshotValueAtPercentile struct {
196 Percentile float64 `json:"percentile,omitempty"`
197 Value float64 `json:"value,omitempty"`