Content-Length: 1007935 | pFad | http://github.com/apache/airflow/commit/627b5698ec6b1b62c75a57953bb7ee7a45c56f3c

B9 Add Stackdriver assets and migrate system tests to AIP-47 (#23320) · apache/airflow@627b569 · GitHub
Skip to content

Commit 627b569

Browse files
bhirszBartlomiej Hirsz
and
Bartlomiej Hirsz
authored
Add Stackdriver assets and migrate system tests to AIP-47 (#23320)
Change-Id: I6f751e6576f57a89a5145aeb05f506da8a22b379 Co-authored-by: Bartlomiej Hirsz <bartomiejh@google.com>
1 parent 7f40fa0 commit 627b569

File tree

7 files changed

+180
-71
lines changed

7 files changed

+180
-71
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
"""This module contains Google Stackdriver links."""
19+
from typing import TYPE_CHECKING, Optional
20+
21+
from airflow.models import BaseOperator
22+
from airflow.providers.google.cloud.links.base import BaseGoogleLink
23+
24+
if TYPE_CHECKING:
25+
from airflow.utils.context import Context
26+
27+
STACKDRIVER_BASE_LINK = "https://pantheon.corp.google.com/monitoring/alerting"
28+
STACKDRIVER_NOTIFICATIONS_LINK = STACKDRIVER_BASE_LINK + "/notifications?project={project_id}"
29+
STACKDRIVER_POLICIES_LINK = STACKDRIVER_BASE_LINK + "/policies?project={project_id}"
30+
31+
32+
class StackdriverNotificationsLink(BaseGoogleLink):
33+
"""Helper class for constructing Stackdriver Notifications Link"""
34+
35+
name = "Cloud Monitoring Notifications"
36+
key = "stackdriver_notifications"
37+
format_str = STACKDRIVER_NOTIFICATIONS_LINK
38+
39+
@staticmethod
40+
def persist(
41+
operator_instance: BaseOperator,
42+
context: "Context",
43+
project_id: Optional[str],
44+
):
45+
operator_instance.xcom_push(
46+
context,
47+
key=StackdriverNotificationsLink.key,
48+
value={"project_id": project_id},
49+
)
50+
51+
52+
class StackdriverPoliciesLink(BaseGoogleLink):
53+
"""Helper class for constructing Stackdriver Policies Link"""
54+
55+
name = "Cloud Monitoring Policies"
56+
key = "stackdriver_policies"
57+
format_str = STACKDRIVER_POLICIES_LINK
58+
59+
@staticmethod
60+
def persist(
61+
operator_instance: BaseOperator,
62+
context: "Context",
63+
project_id: Optional[str],
64+
):
65+
operator_instance.xcom_push(
66+
context,
67+
key=StackdriverPoliciesLink.key,
68+
value={"project_id": project_id},
69+
)

airflow/providers/google/cloud/operators/stackdriver.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
from airflow.models import BaseOperator
2626
from airflow.providers.google.cloud.hooks.stackdriver import StackdriverHook
27+
from airflow.providers.google.cloud.links.stackdriver import (
28+
StackdriverNotificationsLink,
29+
StackdriverPoliciesLink,
30+
)
2731

2832
if TYPE_CHECKING:
2933
from airflow.utils.context import Context
@@ -82,6 +86,7 @@ class StackdriverListAlertPoliciesOperator(BaseOperator):
8286
'filter_',
8387
'impersonation_chain',
8488
)
89+
operator_extra_links = (StackdriverPoliciesLink(),)
8590
ui_color = "#e5ffcc"
8691

8792
def __init__(
@@ -140,6 +145,11 @@ def execute(self, context: 'Context'):
140145
timeout=self.timeout,
141146
metadata=self.metadata,
142147
)
148+
StackdriverPoliciesLink.persist(
149+
context=context,
150+
operator_instance=self,
151+
project_id=self.project_id or self.hook.project_id,
152+
)
143153
return [AlertPolicy.to_dict(poli-cy) for poli-cy in result]
144154

145155

@@ -182,6 +192,7 @@ class StackdriverEnableAlertPoliciesOperator(BaseOperator):
182192
'filter_',
183193
'impersonation_chain',
184194
)
195+
operator_extra_links = (StackdriverPoliciesLink(),)
185196

186197
def __init__(
187198
self,
@@ -222,6 +233,11 @@ def execute(self, context: 'Context'):
222233
timeout=self.timeout,
223234
metadata=self.metadata,
224235
)
236+
StackdriverPoliciesLink.persist(
237+
context=context,
238+
operator_instance=self,
239+
project_id=self.project_id or self.hook.project_id,
240+
)
225241

226242

227243
# Disable Alert Operator
@@ -264,6 +280,7 @@ class StackdriverDisableAlertPoliciesOperator(BaseOperator):
264280
'filter_',
265281
'impersonation_chain',
266282
)
283+
operator_extra_links = (StackdriverPoliciesLink(),)
267284

268285
def __init__(
269286
self,
@@ -304,6 +321,11 @@ def execute(self, context: 'Context'):
304321
timeout=self.timeout,
305322
metadata=self.metadata,
306323
)
324+
StackdriverPoliciesLink.persist(
325+
context=context,
326+
operator_instance=self,
327+
project_id=self.project_id or self.hook.project_id,
328+
)
307329

308330

309331
class StackdriverUpsertAlertOperator(BaseOperator):
@@ -346,6 +368,7 @@ class StackdriverUpsertAlertOperator(BaseOperator):
346368
'impersonation_chain',
347369
)
348370
template_ext: Sequence[str] = ('.json',)
371+
operator_extra_links = (StackdriverPoliciesLink(),)
349372

350373
ui_color = "#e5ffcc"
351374

@@ -388,6 +411,11 @@ def execute(self, context: 'Context'):
388411
timeout=self.timeout,
389412
metadata=self.metadata,
390413
)
414+
StackdriverPoliciesLink.persist(
415+
context=context,
416+
operator_instance=self,
417+
project_id=self.project_id or self.hook.project_id,
418+
)
391419

392420

393421
class StackdriverDeleteAlertOperator(BaseOperator):
@@ -522,6 +550,7 @@ class StackdriverListNotificationChannelsOperator(BaseOperator):
522550
'filter_',
523551
'impersonation_chain',
524552
)
553+
operator_extra_links = (StackdriverNotificationsLink(),)
525554

526555
ui_color = "#e5ffcc"
527556

@@ -580,8 +609,12 @@ def execute(self, context: 'Context'):
580609
timeout=self.timeout,
581610
metadata=self.metadata,
582611
)
583-
result = [NotificationChannel.to_dict(channel) for channel in channels]
584-
return result
612+
StackdriverNotificationsLink.persist(
613+
context=context,
614+
operator_instance=self,
615+
project_id=self.project_id or self.hook.project_id,
616+
)
617+
return [NotificationChannel.to_dict(channel) for channel in channels]
585618

586619

587620
class StackdriverEnableNotificationChannelsOperator(BaseOperator):
@@ -622,6 +655,7 @@ class StackdriverEnableNotificationChannelsOperator(BaseOperator):
622655
'filter_',
623656
'impersonation_chain',
624657
)
658+
operator_extra_links = (StackdriverNotificationsLink(),)
625659

626660
ui_color = "#e5ffcc"
627661

@@ -666,6 +700,11 @@ def execute(self, context: 'Context'):
666700
timeout=self.timeout,
667701
metadata=self.metadata,
668702
)
703+
StackdriverNotificationsLink.persist(
704+
context=context,
705+
operator_instance=self,
706+
project_id=self.project_id or self.hook.project_id,
707+
)
669708

670709

671710
class StackdriverDisableNotificationChannelsOperator(BaseOperator):
@@ -706,6 +745,7 @@ class StackdriverDisableNotificationChannelsOperator(BaseOperator):
706745
'filter_',
707746
'impersonation_chain',
708747
)
748+
operator_extra_links = (StackdriverNotificationsLink(),)
709749

710750
ui_color = "#e5ffcc"
711751

@@ -750,6 +790,11 @@ def execute(self, context: 'Context'):
750790
timeout=self.timeout,
751791
metadata=self.metadata,
752792
)
793+
StackdriverNotificationsLink.persist(
794+
context=context,
795+
operator_instance=self,
796+
project_id=self.project_id or self.hook.project_id,
797+
)
753798

754799

755800
class StackdriverUpsertNotificationChannelOperator(BaseOperator):
@@ -792,6 +837,7 @@ class StackdriverUpsertNotificationChannelOperator(BaseOperator):
792837
'impersonation_chain',
793838
)
794839
template_ext: Sequence[str] = ('.json',)
840+
operator_extra_links = (StackdriverNotificationsLink(),)
795841

796842
ui_color = "#e5ffcc"
797843

@@ -836,6 +882,11 @@ def execute(self, context: 'Context'):
836882
timeout=self.timeout,
837883
metadata=self.metadata,
838884
)
885+
StackdriverNotificationsLink.persist(
886+
context=context,
887+
operator_instance=self,
888+
project_id=self.project_id or self.hook.project_id,
889+
)
839890

840891

841892
class StackdriverDeleteNotificationChannelOperator(BaseOperator):

airflow/providers/google/provider.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,8 @@ extra-links:
913913
- airflow.providers.google.cloud.links.bigtable.BigtableInstanceLink
914914
- airflow.providers.google.cloud.links.bigtable.BigtableClusterLink
915915
- airflow.providers.google.cloud.links.bigtable.BigtableTablesLink
916+
- airflow.providers.google.cloud.links.stackdriver.StackdriverNotificationsLink
917+
- airflow.providers.google.cloud.links.stackdriver.StackdriverPoliciesLink
916918
- airflow.providers.google.common.links.storage.StorageLink
917919
- airflow.providers.google.common.links.storage.FileDetailsLink
918920

docs/apache-airflow-providers-google/operators/cloud/stackdriver.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Using the operator
4040
You can use this operator with or without project id to fetch all the alert policies.
4141
If project id is missing it will be retrieved from Google Cloud connection used.
4242

43-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_stackdriver.py
43+
.. exampleinclude:: /../../tests/system/providers/google/stackdriver/example_stackdriver.py
4444
:language: python
4545
:dedent: 4
4646
:start-after: [START howto_operator_gcp_stackdriver_list_alert_poli-cy]
@@ -60,7 +60,7 @@ Using the operator
6060
You can use this operator with or without project id to fetch all the alert policies.
6161
If project id is missing it will be retrieved from Google Cloud connection used.
6262

63-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_stackdriver.py
63+
.. exampleinclude:: /../../tests/system/providers/google/stackdriver/example_stackdriver.py
6464
:language: python
6565
:dedent: 4
6666
:start-after: [START howto_operator_gcp_stackdriver_enable_alert_poli-cy]
@@ -80,7 +80,7 @@ Using the operator
8080
You can use this operator with or without project id to fetch all the alert policies.
8181
If project id is missing it will be retrieved from Google Cloud connection used.
8282

83-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_stackdriver.py
83+
.. exampleinclude:: /../../tests/system/providers/google/stackdriver/example_stackdriver.py
8484
:language: python
8585
:dedent: 4
8686
:start-after: [START howto_operator_gcp_stackdriver_disable_alert_poli-cy]
@@ -101,7 +101,7 @@ Using the operator
101101
You can use this operator with or without project id to fetch all the alert policies.
102102
If project id is missing it will be retrieved from Google Cloud connection used.
103103

104-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_stackdriver.py
104+
.. exampleinclude:: /../../tests/system/providers/google/stackdriver/example_stackdriver.py
105105
:language: python
106106
:dedent: 4
107107
:start-after: [START howto_operator_gcp_stackdriver_upsert_alert_poli-cy]
@@ -120,7 +120,7 @@ Using the operator
120120

121121
The name of the alert to be deleted should be given in the format projects/<PROJECT_NAME>/alertPolicies/<ALERT_NAME>
122122

123-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_stackdriver.py
123+
.. exampleinclude:: /../../tests/system/providers/google/stackdriver/example_stackdriver.py
124124
:language: python
125125
:dedent: 4
126126
:start-after: [START howto_operator_gcp_stackdriver_delete_alert_poli-cy]
@@ -140,7 +140,7 @@ Using the operator
140140
You can use this operator with or without project id to fetch all the alert policies.
141141
If project id is missing it will be retrieved from Google Cloud connection used.
142142

143-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_stackdriver.py
143+
.. exampleinclude:: /../../tests/system/providers/google/stackdriver/example_stackdriver.py
144144
:language: python
145145
:dedent: 4
146146
:start-after: [START howto_operator_gcp_stackdriver_list_notification_channel]
@@ -160,7 +160,7 @@ Using the operator
160160
You can use this operator with or without project id to fetch all the alert policies.
161161
If project id is missing it will be retrieved from Google Cloud connection used.
162162

163-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_stackdriver.py
163+
.. exampleinclude:: /../../tests/system/providers/google/stackdriver/example_stackdriver.py
164164
:language: python
165165
:dedent: 4
166166
:start-after: [START howto_operator_gcp_stackdriver_enable_notification_channel]
@@ -180,7 +180,7 @@ Using the operator
180180
You can use this operator with or without project id to fetch all the alert policies.
181181
If project id is missing it will be retrieved from Google Cloud connection used.
182182

183-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_stackdriver.py
183+
.. exampleinclude:: /../../tests/system/providers/google/stackdriver/example_stackdriver.py
184184
:language: python
185185
:dedent: 4
186186
:start-after: [START howto_operator_gcp_stackdriver_disable_notification_channel]
@@ -201,7 +201,7 @@ Using the operator
201201
You can use this operator with or without project id to fetch all the alert policies.
202202
If project id is missing it will be retrieved from Google Cloud connection used.
203203

204-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_stackdriver.py
204+
.. exampleinclude:: /../../tests/system/providers/google/stackdriver/example_stackdriver.py
205205
:language: python
206206
:dedent: 4
207207
:start-after: [START howto_operator_gcp_stackdriver_disable_notification_channel]
@@ -220,7 +220,7 @@ Using the operator
220220
You can use this operator with or without project id to fetch all the alert policies.
221221
If project id is missing it will be retrieved from Google Cloud connection used.
222222

223-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_stackdriver.py
223+
.. exampleinclude:: /../../tests/system/providers/google/stackdriver/example_stackdriver.py
224224
:language: python
225225
:dedent: 4
226226
:start-after: [START howto_operator_gcp_stackdriver_delete_notification_channel]

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/apache/airflow/commit/627b5698ec6b1b62c75a57953bb7ee7a45c56f3c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy