Skip to content

Commit

Permalink
Merge "Fix building report with customized stepd names + add disable_…
Browse files Browse the repository at this point in the history
…paging parameters to the log queries"

-- Branch commit log --
commit b488c91ad7786b03c8e4ca07340bd58b64b1d061
Author:  Natalia Kaczor <[email protected]>
Date:    2025-02-05T17:40:29Z

    Fix building report with customized stepd names + add disable_paging parameters to the log queries

Change-Id: I8dfb09564f1535130342c9ebf01077f222e2cca0
GitOrigin-RevId: 32ba4f6cfbada92d2a70cd5ddc8b96c90c006257
  • Loading branch information
Natalia Kaczor authored and copybara-github committed Feb 7, 2025
1 parent 6ea66ec commit 706d4ca
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 214 deletions.
18 changes: 15 additions & 3 deletions gcpdiag/queries/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
from typing import (Any, Deque, Dict, List, Mapping, Optional, Sequence, Set,
Tuple, Union)

import apiclient.errors
import dateutil.parser
import ratelimit
from boltons.iterutils import get_path

from gcpdiag import caching, config, models
from gcpdiag import caching, config, models, utils
from gcpdiag.queries import apis


Expand Down Expand Up @@ -162,7 +163,12 @@ def query(project_id: str, resource_type: str, log_name: str,
period=config.get('logging_ratelimit_period_seconds'))
def _ratelimited_execute(req):
"""Wrapper to req.execute() with rate limiting to avoid hitting quotas."""
return req.execute(num_retries=config.API_RETRIES)
try:
return req.execute(num_retries=config.API_RETRIES)
except apiclient.errors.HttpError as err:
logging.error('failed to execute logging request for request %s. Error: %s',
req, err)
raise utils.GcpApiError(err) from err


def _execute_query_job(job: _LogsQueryJob):
Expand Down Expand Up @@ -240,7 +246,11 @@ def _execute_query_job(job: _LogsQueryJob):


@caching.cached_api_call
def realtime_query(project_id, filter_str, start_time, end_time):
def realtime_query(project_id,
filter_str,
start_time,
end_time,
disable_paging=False):
"""Intended for use in only runbooks. use logs.query() for lint rules."""
logging_api = apis.get_api('logging', 'v2', project_id)

Expand Down Expand Up @@ -283,6 +293,8 @@ def realtime_query(project_id, filter_str, start_time, end_time):
'maximum query runtime for log query reached (project: %s, query: %s).',
project_id, filter_str.replace('\n', ' AND '))
return deque
if disable_paging:
break
req = logging_api.entries().list_next(req, res)
if req is not None:
logging.info('still fetching logs (project: %s, max wait: %ds)',
Expand Down
8 changes: 4 additions & 4 deletions gcpdiag/runbook/lb/snapshots/unhealthy_backends.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ lb/unhealthy-backends: Load Balancer Unhealthy Backends Analyzer.
Group https://www.googleapis.com/compute/v1/projects/gcpdiag-lb2-aaaa/zones/us-east1-b/instanceGroups/lb-backend-example has 2/2 unhealthy backends


[GATEWAY]: Check if health check logging is enabled.
[GATEWAY]: Verify health check logging enabled for backend service "web-backend-service" in region "global".

- gcpdiag-lb2-aaaa/http-basic-check [OK]
[REASON]
Health check logging is enabled for health check projects/gcpdiag-lb1-aaaa/global/healthChecks/http-basic-check.

[GATEWAY]: Look for the latest health check logs and based on that decide what to do next.
[GATEWAY]: Analyze latest health check log for backend service "web-backend-service" in region "global".
[AUTOMATED STEP]: Analyze TIMEOUT health check logs for backend service "web-backend-service" in region "global".

- gcpdiag-lb2-aaaa/web-backend-service [UNCERTAIN]
Expand Down Expand Up @@ -276,13 +276,13 @@ lb/unhealthy-backends: Load Balancer Unhealthy Backends Analyzer.
Group https://www.googleapis.com/compute/v1/projects/gcpdiag-lb2-aaaa/zones/europe-west4-b/networkEndpointGroups/neg1 has 1/1 unhealthy backends


[GATEWAY]: Check if health check logging is enabled.
[GATEWAY]: Verify health check logging enabled for backend service "backend-service-2" in region "europe-west4".

- gcpdiag-lb2-aaaa/tcp-basic-check-2 [OK]
[REASON]
Health check logging is enabled for health check projects/gcpdiag-lb2-aaaa/regions/europe-west4/healthChecks/tcp-basic-check-2.

[GATEWAY]: Look for the latest health check logs and based on that decide what to do next.
[GATEWAY]: Analyze latest health check log for backend service "backend-service-2" in region "europe-west4".
[AUTOMATED STEP]: Analyze TIMEOUT health check logs for backend service "backend-service-2" in region "europe-west4".

- gcpdiag-lb2-aaaa/backend-service-2 [UNCERTAIN]
Expand Down
Loading

0 comments on commit 706d4ca

Please sign in to comment.