You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/05/03 20:44:47 UTC

[GitHub] [airflow-ci-infra] mik-laj commented on a change in pull request #19: Add gcp cloud init

mik-laj commented on a change in pull request #19:
URL: https://github.com/apache/airflow-ci-infra/pull/19#discussion_r625356257



##########
File path: gcp/metrics/gcp_create_metrics_descriptor.py
##########
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import click
+from google.api import label_pb2 as ga_label, metric_pb2 as ga_metric
+from google.cloud import monitoring_v3
+
+DEFAULT_PROJECT = 'apache-airflow-ci-cd'
+DEFAULT_ZONE = 'us-central1-a'
+CUSTOM_METRICS_TYPE = 'custom.googleapis.com/github-actions/jobs-running'
+
+
+@click.command()
+@click.option('--project', default=DEFAULT_PROJECT)
+def main(project: str):
+    client = monitoring_v3.MetricServiceClient()
+    project_name = f"projects/{project}"
+    descriptor = ga_metric.MetricDescriptor()
+    descriptor.display_name = "GitHub Actions jobs"
+    descriptor.type = CUSTOM_METRICS_TYPE
+    descriptor.metric_kind = ga_metric.MetricDescriptor.MetricKind.GAUGE
+    descriptor.value_type = ga_metric.MetricDescriptor.ValueType.INT64
+    descriptor.description = "Number of Jobs running for GitHub Actions."

Review comment:
       ```suggestion
       descriptor = ga_metric.MetricDescriptor(
          display_name="GitHub Actions jobs",
          type=CUSTOM_METRICS_TYPE,
          metric_kind=ga_metric.MetricDescriptor.MetricKind.GAUGE.
          value_type=ga_metric.MetricDescriptor.ValueType.INT64,
          description="Number of Jobs running for GitHub Actions.",
       )
   ```
   This prevents you from creating an attribute that does not exist in the class. When data is passed through the constructor, the interpreter validates that the input is valid, but it does not when you set the attributes directly.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org