This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
/
metrics.go
128 lines (114 loc) · 4.1 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package publish contains OpenCensus metrics and views for publish operations
package publish
import (
"github.com/google/exposure-notifications-server/internal/metrics"
"github.com/google/exposure-notifications-server/pkg/observability"
"go.opencensus.io/plugin/ochttp"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
)
var (
publishMetricsPrefix = metrics.MetricRoot + "publish/"
mLatencyMs = stats.Float64(publishMetricsPrefix+"requests", "publish requests", stats.UnitMilliseconds)
mJWTNotYetValid = stats.Int64(publishMetricsPrefix+"jwt_not_yet_valid",
"a certificate was presented with an IAT or NBF time that is in the past according to thie server", stats.UnitDimensionless)
mNoPublicKey = stats.Int64(publishMetricsPrefix+"no_public_keys",
"uploads where there is no public key", stats.UnitDimensionless)
mExposuresCount = stats.Int64(publishMetricsPrefix+"exposures_count",
"exposure count", stats.UnitDimensionless)
mVerificationBypassed = stats.Int64(publishMetricsPrefix+"verification_bypassed",
"Instances of health authority verification being bypassed", stats.UnitDimensionless)
// v1 and v1alpha1
mPaddingFailed = stats.Int64(publishMetricsPrefix+"padding_failed",
"Instances of response padding failures", stats.UnitDimensionless)
exposureTypeTag = tag.MustNewKey("type")
requestTagKeys = []tag.Key{
observability.BuildIDTagKey,
observability.BuildTagTagKey,
observability.BlameTagKey,
observability.ResultTagKey,
}
exposureTagKeys = []tag.Key{
observability.BuildIDTagKey,
observability.BuildTagTagKey,
exposureTypeTag,
}
healthAuthorityIDTag = tag.MustNewKey("healthAuthorityID")
missingPublicKeyTags = []tag.Key{
healthAuthorityIDTag,
}
)
func exposureType(s string) tag.Mutator {
return tag.Upsert(exposureTypeTag, s)
}
var (
exposuresInserted = exposureType("INSERTED")
exposuresRevised = exposureType("REVISED")
exposuresDropped = exposureType("DROPPED")
)
func init() {
observability.CollectViews([]*view.View{
{
Name: metrics.MetricRoot + "requests_count",
Description: "Total count of publish requests",
Measure: mLatencyMs,
Aggregation: view.Count(),
TagKeys: requestTagKeys,
},
{
Name: metrics.MetricRoot + "requests_latency",
Description: "Latency distribution of publish requests",
Measure: mLatencyMs,
Aggregation: ochttp.DefaultLatencyDistribution,
TagKeys: requestTagKeys,
},
{
Name: metrics.MetricRoot + "exposures_count",
Description: "Total count of published exposures.",
Measure: mExposuresCount,
Aggregation: view.Count(),
TagKeys: exposureTagKeys,
},
{
Name: metrics.MetricRoot + "verification_bypassed_count",
Description: "Total count of health authority verification being bypassed",
Measure: mVerificationBypassed,
Aggregation: view.Sum(),
},
{
Name: metrics.MetricRoot + "jwt_not_yet_valid",
Description: "Total count of instances where a verification certificate is in the future",
Measure: mJWTNotYetValid,
Aggregation: view.Sum(),
TagKeys: missingPublicKeyTags,
},
// v1 and v1alpha1
{
Name: metrics.MetricRoot + "padding_failed",
Description: "Total count of response padding failures",
Measure: mPaddingFailed,
Aggregation: view.Sum(),
},
{
Name: metrics.MetricRoot + "no_public_key",
Description: "Publish request with no public key",
Measure: mNoPublicKey,
Aggregation: view.Count(),
TagKeys: missingPublicKeyTags,
},
}...)
}