@@ -76,6 +76,7 @@ def setUp(self):
7676 'clusterfuzz._internal.base.persistent_cache.get_value' ,
7777 'clusterfuzz._internal.base.persistent_cache.set_value' ,
7878 'clusterfuzz._internal.base.persistent_cache.delete_value' ,
79+ 'clusterfuzz._internal.google_cloud_utils.compute_metadata.get' ,
7980 'clusterfuzz._internal.platforms.android.settings.is_google_device' ,
8081 'clusterfuzz._internal.platforms.android.fetch_artifact.get_latest_artifact_info' ,
8182 'clusterfuzz._internal.system.environment.is_android_cuttlefish' ,
@@ -116,37 +117,84 @@ def _setup_monitoring_daemon(self, mock_client):
116117 monitor ._monitoring_daemon .start ()
117118 return call_queue
118119
119- def _assert_cuttlefish_boot_metric (self , time_series , is_succeeded ):
120+ def _assert_cuttlefish_boot_metric (self , time_series , instance_id ,
121+ is_candidate , is_succeeded ):
120122 """Asserts Cuttlefish boot failure metric presence and correctness in time series."""
121123 for ts in time_series :
122124 if ts .metric .type == "custom.googleapis.com/tip_boot_failure" :
125+ if instance_id is not None and ts .metric .labels ['instance_id' ] != str (
126+ instance_id ):
127+ continue
128+ if is_candidate is not None and ts .metric .labels ['is_candidate' ] != str (
129+ is_candidate ):
130+ continue
123131 if is_succeeded is not None and ts .metric .labels ['is_succeeded' ] != str (
124132 is_succeeded ):
125133 continue
134+ self .assertEqual (ts .metric .labels ['instance_id' ], str (instance_id ))
135+ self .assertEqual (ts .metric .labels ['is_candidate' ], str (is_candidate ))
126136 self .assertEqual (ts .metric .labels ['is_succeeded' ], str (is_succeeded ))
127137 self .assertEqual (ts .metric .labels ['build_id' ], "test-bid" )
128138
139+ def _fake_get (self , path ):
140+ if path == "instance/zone" :
141+ return "projects/1234567890/zones/us-central1-b"
142+ if path == "instance/id" :
143+ return "1234567890"
144+ return ""
145+
146+ @patch (
147+ 'clusterfuzz._internal.metrics.monitor.monitoring_v3.MetricServiceClient' )
148+ def test_cuttlefish_boot_success_metric_for_candidate_fleet (
149+ self , mock_client ):
150+ """Tests the metric emission for a successful Cuttlefish boot."""
151+ self .mock .get .side_effect = self ._fake_get
152+ call_queue = self ._setup_monitoring_daemon (mock_client )
153+ self .mock .get_device_state .return_value = 'device'
154+ flash .flash_to_latest_build_if_needed ()
155+ args = call_queue .get (timeout = 20 )
156+ time_series = args ['time_series' ]
157+ self ._assert_cuttlefish_boot_metric (time_series , '1234567890' , True , True )
158+ monitor ._monitoring_daemon .stop ()
159+
160+ @patch (
161+ 'clusterfuzz._internal.metrics.monitor.monitoring_v3.MetricServiceClient' )
162+ def test_cuttlefish_boot_failure_metric_for_candidate_fleet (
163+ self , mock_client ):
164+ """Tests the metric emission for a failed Cuttlefish boot."""
165+ self .mock .get .side_effect = self ._fake_get
166+ call_queue = self ._setup_monitoring_daemon (mock_client )
167+ flash .flash_to_latest_build_if_needed ()
168+ args = call_queue .get (timeout = 20 )
169+ time_series = args ['time_series' ]
170+ self ._assert_cuttlefish_boot_metric (time_series , '1234567890' , True , False )
171+ monitor ._monitoring_daemon .stop ()
172+
129173 @patch (
130174 'clusterfuzz._internal.metrics.monitor.monitoring_v3.MetricServiceClient' )
131- def test_cuttlefish_boot_success_metric (self , mock_client ):
175+ def test_cuttlefish_boot_success_metric_for_production_fleet (
176+ self , mock_client ):
132177 """Tests the metric emission for a successful Cuttlefish boot."""
178+ self .mock .get .side_effect = self ._fake_get
133179 call_queue = self ._setup_monitoring_daemon (mock_client )
134180 self .mock .get_device_state .return_value = 'device'
135181 flash .flash_to_latest_build_if_needed ()
136182 args = call_queue .get (timeout = 20 )
137183 time_series = args ['time_series' ]
138- self ._assert_cuttlefish_boot_metric (time_series , True )
184+ self ._assert_cuttlefish_boot_metric (time_series , '1234567890' , False , True )
139185 monitor ._monitoring_daemon .stop ()
140186
141187 @patch (
142188 'clusterfuzz._internal.metrics.monitor.monitoring_v3.MetricServiceClient' )
143- def test_cuttlefish_boot_failure_metric (self , mock_client ):
189+ def test_cuttlefish_boot_failure_metric_for_production_fleet (
190+ self , mock_client ):
144191 """Tests the metric emission for a failed Cuttlefish boot."""
192+ self .mock .get .side_effect = self ._fake_get
145193 call_queue = self ._setup_monitoring_daemon (mock_client )
146194 flash .flash_to_latest_build_if_needed ()
147195 args = call_queue .get (timeout = 20 )
148196 time_series = args ['time_series' ]
149- self ._assert_cuttlefish_boot_metric (time_series , False )
197+ self ._assert_cuttlefish_boot_metric (time_series , '1234567890' , False , False )
150198 monitor ._monitoring_daemon .stop ()
151199
152200 def test_counter_metric_success (self ):
0 commit comments