gcpdiag icon indicating copy to clipboard operation
gcpdiag copied to clipboard

Crash on 0.60/0.61 if Compute Engine API not enabled

Open qgallet opened this issue 2 years ago • 2 comments

This was working fine on 0.59. When running gcpdiag on a project that hasn't enabled Compute Engine API, an exception is raised and cannot be bypassed, even if I try to exclude all GCE rules.

$ gcpdiag lint --project=myproject --exclude=gce

gcpdiag 🩺  0.61

Starting lint inspection (project: myproject)...

   ... fetching metadata of project myproject

Traceback (most recent call last):
  File "/opt/gcpdiag/gcpdiag/queries/gce.py", line 763, in get_project_metadata
    response = query.execute(num_retries=config.API_RETRIES)
  File "/opt/gcpdiag/.venv/lib/python3.9/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/opt/gcpdiag/.venv/lib/python3.9/site-packages/googleapiclient/http.py", line 938, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://compute.googleapis.com/compute/v1/projects/myproject?alt=json returned "Compute Engine API has not been used in project 1234567890 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/compute.googleapis.com/overview?project=1234567890 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.". Details: "[{'message': 'Compute Engine API has not been used in project 1234567890 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/compute.googleapis.com/overview?project=1234567890 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.', 'domain': 'usageLimits', 'reason': 'accessNotConfigured', 'extendedHelp': 'https://console.developers.google.com'}]">

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/gcpdiag/bin/gcpdiag", line 70, in <module>
    main(sys.argv)
  File "/opt/gcpdiag/bin/gcpdiag", line 43, in main
    lint_command.run(argv)
  File "/opt/gcpdiag/gcpdiag/lint/command.py", line 342, in run
    if not gce.is_project_serial_port_logging_enabled(context.project_id) and \
  File "/opt/gcpdiag/gcpdiag/queries/gce.py", line 959, in is_project_serial_port_logging_enabled
    value = get_project_metadata(
  File "/opt/gcpdiag/gcpdiag/caching.py", line 155, in _cached_api_call_wrapper
    result = func(*args, **kwargs)
  File "/opt/gcpdiag/gcpdiag/queries/gce.py", line 765, in get_project_metadata
    raise utils.GcpApiError(err) from err
gcpdiag.utils.GcpApiError: Compute Engine API has not been used in project 1234567890 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/compute.googleapis.com/overview?project=1234567890 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

qgallet avatar Jun 30 '23 08:06 qgallet

Thanks for reporting this. I updated the default version to be again 0.59 and we will work on a fix.

schweikert avatar Jun 30 '23 08:06 schweikert

the current version 0.63 includes a fix to prevent an exception when Compute Engine API is not enabled. Before closing this issue, can you check to confirm that it resolves your environment as well?

ropeck avatar Jul 31 '23 22:07 ropeck