def run_rule()

in gcpdiag/lint/dataproc/err_2023_001_initialization_action_timeout.py [0:0]


def run_rule(context: models.Context, report: lint.LintReportRuleInterface):
  project = crm.get_project(context.project_id)

  # skip entire rule is logging disabled
  if not apis.is_enabled(context.project_id, 'logging'):
    report.add_skipped(project, 'logging api is disabled')
    return

  clusters = dataproc.get_clusters(context)
  name_to_cluster = {cluster.name: cluster for cluster in clusters}

  if not clusters:
    report.add_skipped(project, 'no clusters found')
    return


  if logs_by_project.get(context.project_id) and \
    logs_by_project[context.project_id].entries:
    for log_entry in logs_by_project[context.project_id].entries:
      # Filter out non-relevant log entries.
      if log_entry['severity'] != 'ERROR' or \
         CLASS_NAME not in get_path(log_entry,
                     ('jsonPayload', 'class'), default='') or \
         MATCH_STR not in get_path(log_entry,
                     ('jsonPayload',  'message'), default=''):
        continue

      cluster_name = get_path(log_entry, ('resource', 'labels', 'cluster_name'),
                              default='')

      if cluster_name and cluster_name not in clusters_by_project:
        clusters_by_project.append(cluster_name)

  for cluster_name in clusters_by_project:
    report.add_failed(name_to_cluster[cluster_name], MATCH_STR)
  for cluster_name in [
      cluster_name for cluster_name in name_to_cluster
      if cluster_name not in clusters_by_project
  ]:
    report.add_ok(name_to_cluster[cluster_name])