GoPLS Viewer

Home|gopls/internal/event/export/ocagent/wire/metrics.go
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.
4
5package wire
6
7import (
8    "encoding/json"
9    "fmt"
10)
11
12type ExportMetricsServiceRequest struct {
13    Node     *Node     `json:"node,omitempty"`
14    Metrics  []*Metric `json:"metrics,omitempty"`
15    Resource *Resource `json:"resource,omitempty"`
16}
17
18type Metric struct {
19    MetricDescriptor *MetricDescriptor `json:"metric_descriptor,omitempty"`
20    Timeseries       []*TimeSeries     `json:"timeseries,omitempty"`
21    Resource         *Resource         `json:"resource,omitempty"`
22}
23
24type 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"`
30}
31
32type MetricDescriptor_Type int32
33
34const (
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
43)
44
45type LabelKey struct {
46    Key         string `json:"key,omitempty"`
47    Description string `json:"description,omitempty"`
48}
49
50type TimeSeries struct {
51    StartTimestamp *Timestamp    `json:"start_timestamp,omitempty"`
52    LabelValues    []*LabelValue `json:"label_values,omitempty"`
53    Points         []*Point      `json:"points,omitempty"`
54}
55
56type LabelValue struct {
57    Value    string `json:"value,omitempty"`
58    HasValue bool   `json:"has_value,omitempty"`
59}
60
61type Point struct {
62    Timestamp *Timestamp `json:"timestamp,omitempty"`
63    Value     PointValue `json:"value,omitempty"`
64}
65
66type PointInt64Value struct {
67    Int64Value int64 `json:"int64Value,omitempty"`
68}
69
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//
75//    {"value": {"int64Value": 1}}
76//
77// but it should be marshalled as:
78//
79//    {"int64Value": 1}
80func (p *PointMarshalJSON() ([]byteerror) {
81    if p == nil {
82        return []byte("null"), nil
83    }
84
85    switch d := p.Value.(type) {
86    case PointInt64Value:
87        return json.Marshal(&struct {
88            Timestamp *Timestamp `json:"timestamp,omitempty"`
89            Value     int64      `json:"int64Value,omitempty"`
90        }{
91            Timestampp.Timestamp,
92            Value:     d.Int64Value,
93        })
94    case PointDoubleValue:
95        return json.Marshal(&struct {
96            Timestamp *Timestamp `json:"timestamp,omitempty"`
97            Value     float64    `json:"doubleValue,omitempty"`
98        }{
99            Timestampp.Timestamp,
100            Value:     d.DoubleValue,
101        })
102    case PointDistributionValue:
103        return json.Marshal(&struct {
104            Timestamp *Timestamp         `json:"timestamp,omitempty"`
105            Value     *DistributionValue `json:"distributionValue,omitempty"`
106        }{
107            Timestampp.Timestamp,
108            Value:     d.DistributionValue,
109        })
110    default:
111        return nilfmt.Errorf("unknown point type %T"p.Value)
112    }
113}
114
115type PointDoubleValue struct {
116    DoubleValue float64 `json:"doubleValue,omitempty"`
117}
118
119type PointDistributionValue struct {
120    DistributionValue *DistributionValue `json:"distributionValue,omitempty"`
121}
122
123type PointSummaryValue struct {
124    SummaryValue *SummaryValue `json:"summaryValue,omitempty"`
125}
126
127type PointValue interface {
128    labelPointValue()
129}
130
131func (PointInt64ValuelabelPointValue()        {}
132func (PointDoubleValuelabelPointValue()       {}
133func (PointDistributionValuelabelPointValue() {}
134func (PointSummaryValuelabelPointValue()      {}
135
136type DistributionValue struct {
137    Count                 int64         `json:"count,omitempty"`
138    Sum                   float64       `json:"sum,omitempty"`
139    SumOfSquaredDeviation float64       `json:"sum_of_squared_deviation,omitempty"`
140    BucketOptions         BucketOptions `json:"bucket_options,omitempty"`
141    Buckets               []*Bucket     `json:"buckets,omitempty"`
142}
143
144type BucketOptionsExplicit struct {
145    Bounds []float64 `json:"bounds,omitempty"`
146}
147
148type BucketOptions interface {
149    labelBucketOptions()
150}
151
152func (*BucketOptionsExplicitlabelBucketOptions() {}
153
154var _ BucketOptions = (*BucketOptionsExplicit)(nil)
155var _ json.Marshaler = (*BucketOptionsExplicit)(nil)
156
157// Declared for the purpose of custom JSON marshaling without cycles.
158type bucketOptionsExplicitAlias BucketOptionsExplicit
159
160// MarshalJSON creates JSON formatted the same way as jsonpb so that the
161// OpenCensus service can correctly determine the underlying value type.
162// This custom MarshalJSON exists because,
163// by default BucketOptionsExplicit is JSON marshalled as:
164//
165//    {"bounds":[1,2,3]}
166//
167// but it should be marshalled as:
168//
169//    {"explicit":{"bounds":[1,2,3]}}
170func (be *BucketOptionsExplicitMarshalJSON() ([]byteerror) {
171    return json.Marshal(&struct {
172        Explicit *bucketOptionsExplicitAlias `json:"explicit,omitempty"`
173    }{
174        Explicit: (*bucketOptionsExplicitAlias)(be),
175    })
176}
177
178type Bucket struct {
179    Count    int64     `json:"count,omitempty"`
180    Exemplar *Exemplar `json:"exemplar,omitempty"`
181}
182
183type Exemplar struct {
184    Value       float64           `json:"value,omitempty"`
185    Timestamp   *Timestamp        `json:"timestamp,omitempty"`
186    Attachments map[string]string `json:"attachments,omitempty"`
187}
188
189type SummaryValue struct {
190    Count    *Int64Value  `json:"count,omitempty"`
191    Sum      *DoubleValue `json:"sum,omitempty"`
192    Snapshot *Snapshot    `json:"snapshot,omitempty"`
193}
194
195type Snapshot struct {
196    Count            *Int64Value                  `json:"count,omitempty"`
197    Sum              *DoubleValue                 `json:"sum,omitempty"`
198    PercentileValues []*SnapshotValueAtPercentile `json:"percentile_values,omitempty"`
199}
200
201type SnapshotValueAtPercentile struct {
202    Percentile float64 `json:"percentile,omitempty"`
203    Value      float64 `json:"value,omitempty"`
204}
205
MembersX
ExportMetricsServiceRequest
MetricDescriptor_UNSPECIFIED
MetricDescriptor_CUMULATIVE_DOUBLE
MetricDescriptor_CUMULATIVE_DISTRIBUTION
TimeSeries.Points
BucketOptionsExplicit.MarshalJSON
Bucket
Bucket.Exemplar
Snapshot.Count
Exemplar.Value
Exemplar.Timestamp
SummaryValue.Count
SummaryValue.Sum
Metric.MetricDescriptor
bucketOptionsExplicitAlias
SummaryValue.Snapshot
MetricDescriptor_CUMULATIVE_INT64
LabelValue.HasValue
Point.Value
PointDoubleValue.DoubleValue
PointDistributionValue
Snapshot.Sum
SnapshotValueAtPercentile
MetricDescriptor_GAUGE_INT64
PointDistributionValue.DistributionValue
BucketOptionsExplicit.MarshalJSON.be
Bucket.Count
Exemplar
Metric.Resource
LabelKey.Key
LabelValue.Value
Point.Timestamp
DistributionValue.Buckets
BucketOptionsExplicit
MetricDescriptor_Type
TimeSeries
Point
DistributionValue.Sum
Snapshot.PercentileValues
json
Metric
MetricDescriptor.LabelKeys
PointSummaryValue.SummaryValue
DistributionValue.BucketOptions
SnapshotValueAtPercentile.Value
MetricDescriptor.Unit
MetricDescriptor.Type
LabelKey.Description
LabelValue
PointInt64Value
PointInt64Value.labelPointValue
Exemplar.Attachments
PointDoubleValue.labelPointValue
MetricDescriptor.Name
LabelKey
PointDoubleValue
PointDistributionValue.labelPointValue
PointSummaryValue.labelPointValue
fmt
ExportMetricsServiceRequest.Metrics
MetricDescriptor
PointValue
DistributionValue.Count
SummaryValue
ExportMetricsServiceRequest.Resource
MetricDescriptor_SUMMARY
SnapshotValueAtPercentile.Percentile
ExportMetricsServiceRequest.Node
Metric.Timeseries
PointInt64Value.Int64Value
BucketOptionsExplicit.Bounds
MetricDescriptor_GAUGE_DISTRIBUTION
TimeSeries.StartTimestamp
PointSummaryValue
DistributionValue.SumOfSquaredDeviation
MetricDescriptor.Description
MetricDescriptor_GAUGE_DOUBLE
TimeSeries.LabelValues
Point.MarshalJSON.p
Point.MarshalJSON
DistributionValue
BucketOptions
BucketOptionsExplicit.labelBucketOptions
Snapshot
Members
X