Skip to content

Commit 39e8403

Browse files
authored
Use GCLOUD_PROJECT for setting the BigQuery projcet to use. (#8797)
In prod, we can't use the mozdata project since our service account is defined in a separate one. This patch fixes the issue by using the setting from `GCLOUD_PROJECT` to specify which project we should be querying in.
1 parent aa3aead commit 39e8403

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ services:
3232
- BUG_FILER_API_KEY=${BUG_FILER_API_KEY:-}
3333
- TLS_CERT_PATH=${TLS_CERT_PATH:-}
3434
- TELEMETRY_ENABLE_ALERTS=${TELEMETRY_ENABLE_ALERTS:-}
35+
- GCLOUD_PROJECT=${GCLOUD_PROJECT:-}
3536
entrypoint: './docker/entrypoint.sh'
3637
# We *ONLY* initialize the data when we're running the backend
3738
command: './initialize_data.sh ./manage.py runserver 0.0.0.0:8000'

treeherder/perf/auto_perf_sheriffing/sherlock.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,17 @@ def telemetry_alert(self):
250250
import mozdetect
251251
from mozdetect.telemetry_query import get_metric_table
252252

253-
if (
254-
not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS")
255-
and settings.SITE_HOSTNAME == "treeherder.mozilla.org"
256-
):
253+
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS") and self._is_prod():
257254
raise Exception(
258255
"GOOGLE_APPLICATION_CREDENTIALS must be defined in production. "
259256
"Use GCLOUD_DIR for local testing."
260257
)
261258

259+
project = "mozdata"
260+
if self._is_prod():
261+
# Defined from the GCLOUD_PROJECT env variable
262+
project = None
263+
262264
ts_detectors = mozdetect.get_timeseries_detectors()
263265

264266
metric_definitions = self._get_metric_definitions()
@@ -287,6 +289,7 @@ def telemetry_alert(self):
287289
platform,
288290
android=(platform == "Mobile"),
289291
use_fog=True,
292+
project=project,
290293
)
291294
if data.empty:
292295
logger.info("No data found")
@@ -307,8 +310,11 @@ def telemetry_alert(self):
307310
except Exception:
308311
logger.info(f"Failed: {traceback.format_exc()}")
309312

313+
def _is_prod(self):
314+
return settings.SITE_HOSTNAME == "treeherder.mozilla.org"
315+
310316
def _can_run_telemetry(self):
311-
return time(22, 0) <= datetime.utcnow().time() < time(23, 0)
317+
return not self._is_prod() or (time(22, 0) <= datetime.utcnow().time() < time(23, 0))
312318

313319
def _create_detection_alert(
314320
self,

0 commit comments

Comments
 (0)