@@ -23,8 +23,10 @@ import (
2323 "github.com/tektoncd/chains/pkg/chains"
2424 "go.opencensus.io/stats"
2525 "go.opencensus.io/stats/view"
26+ "go.opencensus.io/tag"
2627 "knative.dev/pkg/logging"
2728 "knative.dev/pkg/metrics"
29+ "knative.dev/pkg/metrics/metricskey"
2830)
2931
3032var (
5153 stats .UnitDimensionless )
5254
5355 mrCountView * view.View
56+
57+ sgCountNS = stats .Float64 (chains .PipelineRunSignedMsgPerNamespace ,
58+ chains .PipelineRunSignedMsgDescPerNamespace ,
59+ stats .UnitDimensionless )
60+
61+ sgCountViewNS * view.View
62+
63+ plCountNS = stats .Float64 (chains .PipelineRunUplPayloadPerNamespace ,
64+ chains .PipelineRunUplPayloadDescPerNamespace ,
65+ stats .UnitDimensionless )
66+
67+ plCountViewNS * view.View
68+
69+ stCountNS = stats .Float64 (chains .PipelineRunPayloadStoredPerNamespace ,
70+ chains .PipelineRunPayloadStoredDescPerNamespace ,
71+ stats .UnitDimensionless )
72+
73+ stCountViewNS * view.View
74+
75+ mrCountNS = stats .Float64 (chains .PipelineRunMarkedSignedPerNamespace ,
76+ chains .PipelineRunMarkedDSigneDescPerNamespace ,
77+ stats .UnitDimensionless )
78+
79+ mrCountViewNS * view.View
80+
81+ // NamespaceTagKey marks metrics with a namespace.
82+ NamespaceTagKey = tag .MustNewKey (metricskey .LabelNamespaceName )
83+
84+ successTagKey = tag .MustNewKey ("success" )
5485)
5586
5687// Recorder holds keys for Tekton metrics
71102func NewRecorder (ctx context.Context ) (* Recorder , error ) {
72103 var errRegistering error
73104 logger := logging .FromContext (ctx )
105+
74106 once .Do (func () {
75107 r = & Recorder {
76108 initialized : true ,
@@ -110,11 +142,44 @@ func viewRegister() error {
110142 Measure : mrCount ,
111143 Aggregation : view .Count (),
112144 }
145+
146+ sgCountViewNS = & view.View {
147+ Description : sgCountNS .Description (),
148+ Measure : sgCountNS ,
149+ Aggregation : view .Count (),
150+ TagKeys : []tag.Key {NamespaceTagKey , successTagKey },
151+ }
152+
153+ plCountViewNS = & view.View {
154+ Description : plCountNS .Description (),
155+ Measure : plCountNS ,
156+ Aggregation : view .Count (),
157+ TagKeys : []tag.Key {NamespaceTagKey , successTagKey },
158+ }
159+
160+ stCountViewNS = & view.View {
161+ Description : stCountNS .Description (),
162+ Measure : stCountNS ,
163+ Aggregation : view .Count (),
164+ TagKeys : []tag.Key {NamespaceTagKey , successTagKey },
165+ }
166+
167+ mrCountViewNS = & view.View {
168+ Description : mrCountNS .Description (),
169+ Measure : mrCountNS ,
170+ Aggregation : view .Count (),
171+ TagKeys : []tag.Key {NamespaceTagKey , successTagKey },
172+ }
173+
113174 return view .Register (
114175 sgCountView ,
115176 plCountView ,
116177 stCountView ,
117178 mrCountView ,
179+ sgCountViewNS ,
180+ plCountViewNS ,
181+ stCountViewNS ,
182+ mrCountViewNS ,
118183 )
119184}
120185
@@ -133,6 +198,14 @@ func (r *Recorder) RecordCountMetrics(ctx context.Context, metricType string) {
133198 r .countMetrics (ctx , stCount )
134199 case chains .MarkedAsSignedCount :
135200 r .countMetrics (ctx , mrCount )
201+ case chains .SignedMessagesCountPerNamespace :
202+ r .countMetrics (ctx , sgCountNS )
203+ case chains .PayloadUploadeCountPerNamespace :
204+ r .countMetrics (ctx , plCountNS )
205+ case chains .SignsStoredCountPerNamespace :
206+ r .countMetrics (ctx , stCountNS )
207+ case chains .MarkedAsSignedCountPerNamespace :
208+ r .countMetrics (ctx , mrCountNS )
136209 default :
137210 logger .Errorf ("Ignoring the metrics recording as valid Metric type matching %v was not found" , mt )
138211 }
0 commit comments