[Autoroller] Add alert for when Flutter license scripts fail

Bug: skia:8620
Change-Id: I4edcc78a8ccebd5cf5547068aa6ac28587fd210d
Reviewed-on: https://skia-review.googlesource.com/c/180563
Commit-Queue: Ravi Mistry <rmistry@google.com>
Reviewed-by: Eric Boren <borenet@google.com>
diff --git a/autoroll/PROD.md b/autoroll/PROD.md
index 7aab734..2cfb698 100644
--- a/autoroll/PROD.md
+++ b/autoroll/PROD.md
@@ -48,6 +48,13 @@
 file. This error may also prevent the roller from starting up, which is by
 design.
 
+If this happened on the Skia->Flutter roller then also take a look at the
+flutter_license_script_failure section below.
+
+
+flutter_license_script_failure
+------------------------------
+
 The Skia->Flutter roller may throw errors from Flutter's license script:
 "Failed to transition from "idle" to "active": Error when running pre-upload step: Error when running dart license script: Command exited with exit status 1: /data/engine/src/third_party/dart/tools/sdks/dart-sdk/bin/dart lib/main.dart --release --src ../../.. --out /data/engine/src/out/licenses"
 This alert means that the licence script is failing possibly due to a recent
diff --git a/autoroll/go/repo_manager/pre_upload_steps.go b/autoroll/go/repo_manager/pre_upload_steps.go
index 72b46c7..e917c91 100644
--- a/autoroll/go/repo_manager/pre_upload_steps.go
+++ b/autoroll/go/repo_manager/pre_upload_steps.go
@@ -17,6 +17,8 @@
 	"go.skia.org/infra/go/git"
 	"go.skia.org/infra/go/go_install"
 	"go.skia.org/infra/go/sklog"
+
+	"go.skia.org/infra/go/metrics2"
 )
 
 var cipdRoot = path.Join(os.TempDir(), "cipd")
@@ -85,6 +87,11 @@
 // https://github.com/flutter/engine/blob/master/tools/licenses/README.md
 func FlutterLicenseScripts(ctx context.Context, _ *http.Client, parentRepoDir string) error {
 	sklog.Info("Running flutter license scripts.")
+	licenseScriptFailure := int64(1)
+	defer func() {
+		metrics2.GetInt64Metric("flutter_license_script_failure", nil).Update(licenseScriptFailure)
+	}()
+
 	binariesPath := filepath.Join(parentRepoDir, "..", "third_party", "dart", "tools", "sdks", "dart-sdk", "bin")
 
 	// Step1: Run pub get.
@@ -148,6 +155,7 @@
 	}
 
 	sklog.Info("Done running flutter license scripts.")
+	licenseScriptFailure = 0
 	return nil
 }
 
diff --git a/promk/prometheus/alerts_public.yml b/promk/prometheus/alerts_public.yml
index 0c63a66..fa7ec8e 100644
--- a/promk/prometheus/alerts_public.yml
+++ b/promk/prometheus/alerts_public.yml
@@ -229,6 +229,19 @@
       https://console.cloud.google.com/logs/viewer?organizationId=433637338589&project={{ $labels.project }}&minLogLevel=500&resource=container&logName=projects%2Fskia-public%2Flogs%2F{{ $labels.app }}
       https://skia.googlesource.com/buildbot/%2B/master/autoroll/PROD.md#error_rate'
 
+
+  - alert: FlutterLicenseScriptFailure
+    expr: flutter_license_script_failure{app="autoroll-be-skia-flutter-autoroll"} > 0
+    for: 5m
+    labels:
+      category: infra
+      severity: critical
+      owner: rmistry@google.com
+    annotations:
+      description: 'The License scripts in the Skia->Flutter roller have failed.
+      https://console.cloud.google.com/logs/viewer?organizationId=433637338589&project={{ $labels.project }}&minLogLevel=500&resource=container&logName=projects%2Fskia-public%2Flogs%2F{{ $labels.app }}
+      https://skia.googlesource.com/buildbot/%2B/master/autoroll/PROD.md#flutter_license_script_failure'
+
 # skia-flutter-autoroll takes a long time to transition because it's pre-upload
 # scripts run flutter's license script which can take around 40 minutes.
   - alert: AutoRollLastTransition