@@ -37,7 +37,6 @@ import (
3737 "github.com/GoogleContainerTools/config-sync/pkg/importer/reader"
3838 "github.com/GoogleContainerTools/config-sync/pkg/kinds"
3939 "github.com/GoogleContainerTools/config-sync/pkg/metadata"
40- "github.com/GoogleContainerTools/config-sync/pkg/metrics"
4140 "github.com/GoogleContainerTools/config-sync/pkg/remediator/conflict"
4241 remediatorfake "github.com/GoogleContainerTools/config-sync/pkg/remediator/fake"
4342 "github.com/GoogleContainerTools/config-sync/pkg/rootsync"
@@ -50,8 +49,6 @@ import (
5049 discoveryutil "github.com/GoogleContainerTools/config-sync/pkg/util/discovery"
5150 webhookconfiguration "github.com/GoogleContainerTools/config-sync/pkg/webhook/configuration"
5251 "github.com/stretchr/testify/require"
53- "go.opencensus.io/stats/view"
54- "go.opencensus.io/tag"
5552 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
5653 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5754 "k8s.io/apimachinery/pkg/runtime/schema"
@@ -658,6 +655,8 @@ func TestRootReconciler_ParseAndUpdate(t *testing.T) {
658655 t .Fatal (err )
659656 }
660657
658+ _ = testmetrics .NewTestExporter ()
659+
661660 for _ , tc := range testCases {
662661 t .Run (tc .name , func (t * testing.T ) {
663662 fakeClient := syncertest .NewClient (t , core .Scheme , tc .existingObjects ... )
@@ -1289,7 +1288,7 @@ func TestRootReconciler_Parse_SourceErrorMetricValidation(t *testing.T) {
12891288 name string
12901289 parseErrors status.MultiError
12911290 expectedError status.MultiError
1292- expectedMetrics []* view. Row
1291+ expectedMetrics []testmetrics. MetricData
12931292 }{
12941293 {
12951294 name : "single reconciler error in source component" ,
@@ -1299,10 +1298,11 @@ func TestRootReconciler_Parse_SourceErrorMetricValidation(t *testing.T) {
12991298 expectedError : status .Wrap (
13001299 status .SourceError .Sprintf ("source error" ).Build (),
13011300 ),
1302- expectedMetrics : []* view.Row {
1303- {Data : & view.LastValueData {Value : 0 }, Tags : []tag.Tag {{Key : metrics .KeyComponent , Value : "source" }, {Key : metrics .KeyErrorClass , Value : "1xxx" }}},
1304- {Data : & view.LastValueData {Value : 1 }, Tags : []tag.Tag {{Key : metrics .KeyComponent , Value : "source" }, {Key : metrics .KeyErrorClass , Value : "2xxx" }}},
1305- {Data : & view.LastValueData {Value : 0 }, Tags : []tag.Tag {{Key : metrics .KeyComponent , Value : "source" }, {Key : metrics .KeyErrorClass , Value : "9xxx" }}},
1301+ expectedMetrics : []testmetrics.MetricData {
1302+ {Name : "reconciler_errors" , Value : 0 , Labels : map [string ]string {"component" : "source" , "errorclass" : "1xxx" }},
1303+ {Name : "reconciler_errors" , Value : 1 , Labels : map [string ]string {"component" : "source" , "errorclass" : "2xxx" }},
1304+ {Name : "reconciler_errors" , Value : 0 , Labels : map [string ]string {"component" : "source" , "errorclass" : "9xxx" }},
1305+ {Name : "pipeline_error_observed" , Value : 1 , Labels : map [string ]string {"component" : "source" , "name" : "" , "reconciler" : "root-sync" }},
13061306 },
13071307 },
13081308 {
@@ -1315,18 +1315,20 @@ func TestRootReconciler_Parse_SourceErrorMetricValidation(t *testing.T) {
13151315 status .SourceError .Sprintf ("source error" ).Build (),
13161316 status .InternalError ("internal error" ),
13171317 ),
1318- expectedMetrics : []* view.Row {
1319- {Data : & view.LastValueData {Value : 0 }, Tags : []tag.Tag {{Key : metrics .KeyComponent , Value : "source" }, {Key : metrics .KeyErrorClass , Value : "1xxx" }}},
1320- {Data : & view.LastValueData {Value : 1 }, Tags : []tag.Tag {{Key : metrics .KeyComponent , Value : "source" }, {Key : metrics .KeyErrorClass , Value : "2xxx" }}},
1321- {Data : & view.LastValueData {Value : 1 }, Tags : []tag.Tag {{Key : metrics .KeyComponent , Value : "source" }, {Key : metrics .KeyErrorClass , Value : "9xxx" }}},
1318+ expectedMetrics : []testmetrics.MetricData {
1319+ {Name : "reconciler_errors" , Value : 0 , Labels : map [string ]string {"component" : "source" , "errorclass" : "1xxx" }},
1320+ {Name : "reconciler_errors" , Value : 1 , Labels : map [string ]string {"component" : "source" , "errorclass" : "2xxx" }},
1321+ {Name : "reconciler_errors" , Value : 1 , Labels : map [string ]string {"component" : "source" , "errorclass" : "9xxx" }},
1322+ {Name : "pipeline_error_observed" , Value : 1 , Labels : map [string ]string {"component" : "source" , "name" : "" , "reconciler" : "root-sync" }},
13221323 },
13231324 },
13241325 }
13251326
13261327 for _ , tc := range testCases {
13271328 t .Run (tc .name , func (t * testing.T ) {
13281329 require .Error (t , tc .parseErrors )
1329- m := testmetrics .RegisterMetrics (metrics .ReconcilerErrorsView )
1330+ testmetrics .ResetGlobalMetrics ()
1331+ exporter := testmetrics .NewTestExporter ()
13301332 fakeConfigParser := & fsfake.ConfigParser {
13311333 Outputs : []fsfake.ParserOutputs {
13321334 // One Parse call, with errors
@@ -1388,7 +1390,7 @@ func TestRootReconciler_Parse_SourceErrorMetricValidation(t *testing.T) {
13881390 errs := reconciler .parse (ctx , trigger )
13891391 testerrors .AssertEqual (t , tc .expectedError , errs , "expected parse errors to match" )
13901392
1391- if diff := m .ValidateMetrics (metrics . ReconcilerErrorsView , tc .expectedMetrics ); diff != "" {
1393+ if diff := exporter .ValidateMetrics (tc .expectedMetrics ); diff != "" {
13921394 t .Error (diff )
13931395 }
13941396 })
@@ -1400,21 +1402,21 @@ func TestRootReconciler_Update_ApplierErrorMetricValidation(t *testing.T) {
14001402 name string
14011403 applyErrors []status.Error
14021404 expectedError status.MultiError
1403- expectedMetrics []* view. Row
1405+ expectedMetrics []testmetrics. MetricData
14041406 }{
14051407 {
14061408 name : "single reconciler error in sync component" ,
14071409 applyErrors : []status.Error {
14081410 applier .Error (errors .New ("sync error" )),
14091411 },
14101412 expectedError : applier .Error (errors .New ("sync error" )),
1411- expectedMetrics : []* view. Row {
1412- {Data : & view. LastValueData { Value : 0 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "source" }, { Key : metrics . KeyErrorClass , Value : "1xxx" } }},
1413- {Data : & view. LastValueData { Value : 0 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "source" }, { Key : metrics . KeyErrorClass , Value : "2xxx" } }},
1414- {Data : & view. LastValueData { Value : 0 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "source" }, { Key : metrics . KeyErrorClass , Value : "9xxx" } }},
1415- {Data : & view. LastValueData { Value : 0 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "sync" }, { Key : metrics . KeyErrorClass , Value : "1xxx" } }},
1416- {Data : & view. LastValueData { Value : 1 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "sync" }, { Key : metrics . KeyErrorClass , Value : "2xxx" } }},
1417- {Data : & view. LastValueData { Value : 0 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "sync" }, { Key : metrics . KeyErrorClass , Value : "9xxx" } }},
1413+ expectedMetrics : []testmetrics. MetricData {
1414+ {Name : "reconciler_errors" , Value : 0 , Labels : map [ string ] string { "component" : "source" , "errorclass" : "1xxx" }},
1415+ {Name : "reconciler_errors" , Value : 0 , Labels : map [ string ] string { "component" : "source" , "errorclass" : "2xxx" }},
1416+ {Name : "reconciler_errors" , Value : 0 , Labels : map [ string ] string { "component" : "source" , "errorclass" : "9xxx" }},
1417+ {Name : "reconciler_errors" , Value : 0 , Labels : map [ string ] string { "component" : "sync" , "errorclass" : "1xxx" }},
1418+ {Name : "reconciler_errors" , Value : 1 , Labels : map [ string ] string { "component" : "sync" , "errorclass" : "2xxx" }},
1419+ {Name : "reconciler_errors" , Value : 0 , Labels : map [ string ] string { "component" : "sync" , "errorclass" : "9xxx" }},
14181420 },
14191421 },
14201422 {
@@ -1427,20 +1429,20 @@ func TestRootReconciler_Update_ApplierErrorMetricValidation(t *testing.T) {
14271429 applier .Error (errors .New ("sync error" )),
14281430 status .InternalError ("internal error" ),
14291431 ),
1430- expectedMetrics : []* view. Row {
1431- {Data : & view. LastValueData { Value : 0 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "source" }, { Key : metrics . KeyErrorClass , Value : "1xxx" } }},
1432- {Data : & view. LastValueData { Value : 0 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "source" }, { Key : metrics . KeyErrorClass , Value : "2xxx" } }},
1433- {Data : & view. LastValueData { Value : 0 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "source" }, { Key : metrics . KeyErrorClass , Value : "9xxx" } }},
1434- {Data : & view. LastValueData { Value : 0 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "sync" }, { Key : metrics . KeyErrorClass , Value : "1xxx" } }},
1435- {Data : & view. LastValueData { Value : 1 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "sync" }, { Key : metrics . KeyErrorClass , Value : "2xxx" } }},
1436- {Data : & view. LastValueData { Value : 1 }, Tags : []tag. Tag {{ Key : metrics . KeyComponent , Value : "sync" }, { Key : metrics . KeyErrorClass , Value : "9xxx" } }},
1432+ expectedMetrics : []testmetrics. MetricData {
1433+ {Name : "reconciler_errors" , Value : 0 , Labels : map [ string ] string { "component" : "source" , "errorclass" : "1xxx" }},
1434+ {Name : "reconciler_errors" , Value : 0 , Labels : map [ string ] string { "component" : "source" , "errorclass" : "2xxx" }},
1435+ {Name : "reconciler_errors" , Value : 0 , Labels : map [ string ] string { "component" : "source" , "errorclass" : "9xxx" }},
1436+ {Name : "reconciler_errors" , Value : 0 , Labels : map [ string ] string { "component" : "sync" , "errorclass" : "1xxx" }},
1437+ {Name : "reconciler_errors" , Value : 1 , Labels : map [ string ] string { "component" : "sync" , "errorclass" : "2xxx" }},
1438+ {Name : "reconciler_errors" , Value : 1 , Labels : map [ string ] string { "component" : "sync" , "errorclass" : "9xxx" }},
14371439 },
14381440 },
14391441 }
14401442
14411443 for _ , tc := range testCases {
14421444 t .Run (tc .name , func (t * testing.T ) {
1443- m := testmetrics .RegisterMetrics ( metrics . ReconcilerErrorsView )
1445+ exporter := testmetrics .NewTestExporter ( )
14441446 fakeConfigParser := & fsfake.ConfigParser {
14451447 Outputs : []fsfake.ParserOutputs {
14461448 {}, // One Parse call, no errors
@@ -1503,7 +1505,7 @@ func TestRootReconciler_Update_ApplierErrorMetricValidation(t *testing.T) {
15031505 errs = reconciler .update (ctx , trigger )
15041506 testerrors .AssertEqual (t , tc .expectedError , errs , "expected update errors to match" )
15051507
1506- if diff := m .ValidateMetrics (metrics . ReconcilerErrorsView , tc .expectedMetrics ); diff != "" {
1508+ if diff := exporter .ValidateMetrics (tc .expectedMetrics ); diff != "" {
15071509 t .Error (diff )
15081510 }
15091511 })
0 commit comments