Skip to content

Fix Cloud Monitoring list operators when format_ is set #73431

Description

@shahar1

Note

Currently Stackdriver's monitoring-related operators are being renamed to Cloud Monitoring in #73354.
You may independently implement the fix in Stackdriver's implementation, and I'll get it merged to #73354 before the latter is being merged.

Summary

Make the Cloud Monitoring list operators preserve the hook output when format_ is explicitly set. Currently, format_="dict" and format_="json" both fail with a TypeError.

Background

CloudMonitoringHook.list_alert_policies() and list_notification_channels() already honor format_: "dict" returns dictionaries, "json" returns JSON strings, and None returns protobuf objects. The corresponding operators then unconditionally call AlertPolicy.to_dict() or NotificationChannel.to_dict() on every result. That conversion only accepts protobuf objects, so passing an already-converted dictionary or JSON string raises TypeError.

The operators should return the hook result unchanged when format_ is set. With format_=None, they should continue converting protobuf objects to dictionaries so the value remains XCom-serializable. Update the operator-level format_ documentation to describe this behavior.

Where to look

  • providers/google/src/airflow/providers/google/cloud/operators/cloud_monitoring.py — CloudMonitoringListAlertPoliciesOperator.execute and CloudMonitoringListNotificationChannelsOperator.execute.
  • providers/google/src/airflow/providers/google/cloud/hooks/cloud_monitoring.py — the existing return-format behavior.
  • providers/google/tests/unit/google/cloud/operators/test_cloud_monitoring.py — unit tests for both operators.

Acceptance criteria

  • Both list operators return dictionaries unchanged with format_="dict".
  • Both list operators return JSON strings unchanged with format_="json".
  • With no format_, both operators still convert protobuf objects to dictionaries for XCom serialization.
  • Add focused unit-test coverage for the corrected behavior in both operators.
  • Update the operator format_ parameter documentation to accurately state the returned type.

Estimated effort

About 1–2 hours for someone new to the codebase.

Getting started

See Apache Airflow’s contributor quick start.


This issue was drafted with AI assistance and reviewed by a maintainer before filing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions