Skip to content

Commit

Permalink
Merge "Data Fusion rule: Instance State8"
Browse files Browse the repository at this point in the history
-- Branch commit log --
commit 66eb941bd2bf0c25d679911d50600541f78455ea
Author:  gcpdiag team <noreply@google.com>
Date:    2024-07-04T10:23:40Z

    Data Fusion rule: Instance State8

Change-Id: I32d2a5f3cd001dc5258869f59f61f21d89e4e090
GitOrigin-RevId: 15ba546d3faf8bc7a508c5aabac479df69ff1188
  • Loading branch information
gcpdiag team authored and Copybara-Service committed Jul 9, 2024
1 parent dcbfe49 commit 5a918b8
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gcpdiag/lint/datafusion/snapshots/WARN_2024_002.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* datafusion/WARN/2024_002: Data Fusion instance is in a running state.
- gcpdiag-datafusion1-aaaa/us-central1/my-instance [ OK ]

50 changes: 50 additions & 0 deletions gcpdiag/lint/datafusion/warn_2024_002_instance_state_running.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2024 Google LLC
#
# Licensed 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.
# Note that we don't have a general rule that checks this for all products,
# because the grant is done lazily, as soon as it is needed. So check that the
# grant is there only when resources of a certain product (like GKE clusters)
# are present, and we know that the grant is necessary for the correct
# operation of that product. Copy the rule for other products, as necessary.
"""Data Fusion instance is in a running state.
Data Fusion instance is not in a running state, The datafusion state is either
Disabled or Failed, The reason for this disabled or Failed state could be due to
configuration errors, KMS key disabled/denied access or key revoked etc...
"""
from gcpdiag import lint, models
from gcpdiag.queries import datafusion

instances_by_project = {}


def prefetch_rule(context: models.Context):
instances_by_project[context.project_id] = datafusion.get_instances(context)


def run_rule(context: models.Context, report: lint.LintReportRuleInterface):
instances = instances_by_project[context.project_id]
if len(instances) == 0:
report.add_skipped(None, 'no instances found')
for instance in instances.values():
if instance.status not in ('FAILED', 'DISABLED'):
report.add_ok(instance)
else:
if instance.status_details is not None:
report.add_failed(
instance,
(f'Instance is in state {instance.status} '
f'with reason: `{instance.status_details}`'),
)
else:
report.add_failed(instance, f'Instance is in state {instance.status} ')
6 changes: 6 additions & 0 deletions gcpdiag/queries/datafusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ def is_private(self) -> bool:
def status(self) -> str:
return self._resource_data['state']

@property
def status_details(self) -> Optional[str]:
if 'stateMessage' in self._resource_data:
return self._resource_data['stateMessage']
return None

@property
def is_running(self) -> bool:
return self.status == 'ACTIVE'
Expand Down
26 changes: 26 additions & 0 deletions website/content/en/rules/datafusion/WARN/2024_002.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: "datafusion/WARN/2024_002"
linkTitle: "WARN/2024_002"
weight: 1
type: docs
description: >
Data Fusion instance is not in a running state, The datafusion state is either Disabled or Failed, The reason for this disabled or Failed state could be due to configuration errors, KMS key disabled/denied access or key revoked etc...
---

**Product**: [Cloud Data Fusion](https://cloud.google.com/data-fusion)\
**Rule class**: WARN - Something that is possibly wrong

### Description
Data Fusion instance is not in a running state, The datafusion state is either Disabled or Failed, The reason for this disabled or Failed state could be due to configuration errors, KMS key disabled/denied access or key revoked etc...

### Remediation
There are many ways in which a Data Fusion instance might failed to be created.
Review the [Cloud Logs](https://cloud.google.com/data-fusion/docs/how-to/audit-logging) to identify the cause.

The reason for disabling the instance if the state is DISABLED.
https://cloud.google.com/data-fusion/docs/reference/rest/v1/projects.locations.instances#disabledreason

### Further information
- [Instance states](https://cloud.google.com/data-fusion/docs/reference/rest/v1/projects.locations.instances#state)

https://cloud.google.com/data-fusion/docs/how-to/customer-managed-encryption-keys

0 comments on commit 5a918b8

Please sign in to comment.