Skip to content

Commit

Permalink
bug fix and removing exit statement.
Browse files Browse the repository at this point in the history
fix:369552960

Change-Id: I9292c1297825273bba35645f86d1075782177990
GitOrigin-RevId: e50560e60dca4ce58e05c3a5aacfca96e63bf8b7
  • Loading branch information
vinay-vgs authored and copybara-github committed Sep 25, 2024
1 parent ca130d0 commit ee8e458
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion gcpdiag/queries/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ def laststarttimestamp(self) -> str:
return self._resource_data['lastStartTimestamp']

def laststoptimestamp(self) -> str:
return self._resource_data['lastStopTimestamp']
if 'lastStopTimestamp' in self._resource_data:
return self._resource_data['lastStopTimestamp']
return ''

def is_serial_port_logging_enabled(self) -> bool:
value = self.get_metadata('serial-port-logging-enable')
Expand Down
2 changes: 1 addition & 1 deletion gcpdiag/runbook/gce/generalized_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def execute(self):
elif mark_no_ops_agent:
op.add_skipped(vm,
reason='Ops Agent not installed on the VM, '
'Unable to fetch disk utilisation data via metrics. '
'Unable to fetch disk utilisation data via metrics.\n'
'Falling back to check for filesystem utilization related'
' messages in Serial logs')
# Fallback to check for filesystem utilization related messages in Serial logs
Expand Down
18 changes: 9 additions & 9 deletions gcpdiag/runbook/gce/vm_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""Module containing VM performance diagnostic tree and custom steps"""

import json
import sys
from datetime import datetime, timedelta, timezone

import googleapiclient.errors
Expand Down Expand Up @@ -244,8 +243,7 @@ def execute(self):
start_dt_utc_plus_5_mins = start_dt_utc + timedelta(minutes=5)
current_time_utc = datetime.now(timezone.utc)
within_hours = 9
if start_dt_utc_plus_5_mins > current_time_utc and (isinstance(
vm.laststoptimestamp(), str)):
if start_dt_utc_plus_5_mins > current_time_utc and vm.laststoptimestamp():
# Instance just starting up, CpuCount might not be available currently via metrics.
# Use instance's last stop time as EndTime for monitoring query
stop_dt_pst = datetime.strptime(vm.laststoptimestamp(),
Expand Down Expand Up @@ -282,9 +280,10 @@ def execute(self):
cpu_count = int(list(cpu_count_query.values())[0]['values'][0][0])
else:
op.info(
'CPU count info not available for the instance.'
' Please start the VM if it is not in running state.', vm)
sys.exit(21)
('CPU count info not available for the instance.\n'
'Please start the VM {} if it is not in running state.').format(
vm.short_path))
return

# an acceptable average Scheduler Wait Time is 20 ms/s per vCPU.
utilization_threshold = cpu_count * 20
Expand All @@ -307,6 +306,8 @@ def execute(self):
('CPU for the VM {} is over committed beyond acceptable limits: {} ms/s'
).format(vm.name, utilization_threshold),
remediation='')
else:
op.add_ok(vm, reason='VM CPU is not overcommited.\n')
else:
op.add_skipped(vm,
reason='VM is neither a Sole Tenent VM nor an E2 instance,'
Expand Down Expand Up @@ -355,8 +356,7 @@ def execute(self):
start_dt_utc_plus_5_mins = start_dt_utc + timedelta(minutes=5)
current_time_utc = datetime.now(timezone.utc)
within_hours = 9
if start_dt_utc_plus_5_mins > current_time_utc and (isinstance(
vm.laststoptimestamp(), str)):
if start_dt_utc_plus_5_mins > current_time_utc and vm.laststoptimestamp():
# Instance just starting up, CpuCount might not be available currently via metrics.
# Use instance's last stop time as EndTime for monitoring query
stop_dt_pst = datetime.strptime(vm.laststoptimestamp(),
Expand Down Expand Up @@ -395,7 +395,7 @@ def execute(self):
reason='\tCPU count info is not available for the instance via'
' Monitoring metric "guest_visible_vcpus"',
remediation=(
'\n\tPlease first start the VM {}, if it is not in running state'
'\tPlease first start the VM {}, if it is not in running state'
).format(vm.short_path))
return

Expand Down

0 comments on commit ee8e458

Please sign in to comment.