HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: //lib/google-cloud-sdk/lib/surface/storage/__pycache__/diagnose.cpython-312.pyc
�

��f<���dZddlZddlZddlmZddlmZddl	m
Z
ddl	mZddlmZ
ddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZdZdej>dej@fd�Z!d�Z"Gd�dejF�Z$ejJGd�dejL��Z'y)z,Diagnose Google Cloud Storage common issues.�N)�errors)�client)�arg_parsers)�base)�errors_util)�storage_url)�direct_connectivity_diagnostic)�download_throughput_diagnostic)�export_util)�latency_diagnostic)�system_info)�upload_throughput_diagnostic)�gcs_resource_reference)�log�1GB�
bucket_url�returnc���tj�}	|j|j�S#tj
$r(}t
jd|j���|�d}~wwxYw)aFetches the bucket resource for the given bucket storage URL.

  Args:
    bucket_url: The URL object to get the bucket resource for.

  Returns:
    The bucket resource for the given URL.

  Raises:
    FatalError: If the bucket resource could not be fetched.
  z)Bucket metadata could not be fetched for N)�gcs_json_client�
JsonClient�
get_bucket�bucket_name�
api_errors�
CloudApiError�command_errors�
FatalError)r�
gcs_client�es   �lib/surface/storage/diagnose.py�get_bucket_resourcer (sk���)�)�+�*�
�� � ��!7�!7�8�8��	�	!�	!�
�
�
#�
#�
3�J�4J�4J�3K�L���
��
�s�1�A,�#A'�'A,c��tj|jtj|j
��|jry|jrltjj|j�r)tjj|j�std|j�d���yyy)z@Validates and raises error if the command arguments are invalid.zInvalid destination path: z. Please provide a valid path.N)
r�raise_error_if_not_gcs_bucket�command_pathr�storage_url_from_string�url�export�destination�os�path�exists�isdir�
ValueError)�argss r�_validate_argsr.?s���
�+�+�
����<�<�T�X�X�F��
�k�k�
�
�
�
�'�'�.�.��)�)�
*�r�w�w�}�}�T�=M�=M�/N��
$�T�%5�%5�$6�7�	���0O���c� �eZdZdZdZdZdZdZy)�TestTypezEEnum class for specifying performance test type for diagnostic tests.�DIRECT_CONNECTIVITY�DOWNLOAD_THROUGHPUT�UPLOAD_THROUGHPUT�LATENCYN)�__name__�
__module__�__qualname__�__doc__r2r3r4r5�r/rr1r1Rs��M�-��-��)���'r/r1c�6�eZdZdZddd�Zed��Zd�Zd�Zy)	�DiagnosezDiagnose Google Cloud Storage.a�
      The diagnose command runs a series of diagnostic tests for common gcloud
      storage issues.

      The `URL` argument must name an exisiting bucket for which the user
      already has write permissions. Standard billing also applies.
      Several test files/objects will be uploaded and downloaded to this bucket
      to gauge out the performance metrics. All the temporary files will be
      deleted on successfull completion of the command.

      By default, the command executes `DOWNLOAD_THROUGHPUT`,
      `UPLOAD_THROUGHPUT` and `LATENCY` tests. Tests to execute can be overriden
      by using the `--test-type` flag.
      Each test uses the command defaults or gcloud CLI configurations for
      performing the operations. This command also provides a way to override
      these values via means of different flags like `--process-count`,
      `--thread-count`, `--download-type`, etc.

      The command outputs a diagnostic report with sytem information like free
      memory, available CPU, average CPU load per test, disk counter deltas and
      diagnostic information specific to individual tests on successful
      completion.

      a

      The following command runs the default diagnostic tests on ``my-bucket''
      bucket:

      $ {command} gs://my-bucket

      The following command runs only UPLOAD_THROUGHPUT and DOWNLOAD_THROUGHPUT
      diagnostic tests:

      $ {command} gs://my-bucket --test-type=UPLOAD_THROUGHPUT,DOWNLOAD_THROUGHPUT

      The following command runs the diagnostic tests using ``10'' objects of
      ``1MiB'' size each with ``10'' threads and ``10'' processes at max:

      $ {command} gs://my-bucket --no-of-objects=10 --object-size=1MiB
      --process-count=10 --thread-count=10

      The following command can be used to bundle and export the diagnostic
      information to a user defined ``PATH'' destination:

      $ {command} gs://my-bucket --export --destination=<PATH>
      )�DESCRIPTION�EXAMPLESc�z�|jd�|jdtd��|jdtjttD�cgc]}|j��c}���ddg�	�|jd
ttjD�cgc]}|j��c}�tjjd��|jd
d��|jdttjD�cgc]}|j��c}�tjjd��|jdtjd��d��|jdtjd��d��|jdd��}|jddtjd��d��|jdddd��}|jd tjt �!�d"��|jd#d$tjtjt �!��%�d&�'�|jdd(��}|jd)d*dd+�,�|jd-td.��|j"j%d/�ycc}wcc}wcc}w)0NFr%z+Bucket URL to use for the diagnostic tests.)�type�helpz--test-type)�choices�
TEST_TYPESaq
        Tests to run as part of this diagnosis. Following tests are supported:

        DIRECT_CONNECTIVITY: Run a test upload over the Direct Connectivity
        network path and run other diagnostics if the upload fails.

        DOWNLOAD_THROUGHPUT: Upload objects to the specified bucket and record
        the number of bytes transferred per second.

        UPLOAD_THROUGHPUT: Download objects from the specified bucket and
        record the number of bytes transferred per second.

        LATENCY: Write the objects, retrieve their metadata, read the objects,
        and record latency of each operation.
        )r@�metavarrA�defaultz--download-typeau
        Download strategy to use for the DOWNLOAD_THROUGHPUT diagnostic test.

        STREAMING: Downloads the file in memory, does not use parallelism.
        `--process-count` and `--thread-count` flag values will be ignored if
        provided.

        SLICED: Performs a [sliced download](https://cloud.google.com/storage/docs/sliced-object-downloads)
        of objects to a directory.
        Parallelism can be controlled via `--process-count` and `--thread-count`
        flags.

        FILE: Download objects as files. Parallelism can be controlled via
        `--process-count` and `--thread-count` flags.
        )rBrErAz--logs-pathzNIf the diagnostic supports writing logs, write the logs to this file location.)rAz
--upload-typea�
        Upload strategy to use for the _UPLOAD_THROUGHPUT_ diagnostic test.

        FILE: Uploads files to a bucket. Parallelism can be controlled via
        `--process-count` and `--thread-count` flags.

        PARALLEL_COMPOSITE: Uploads files using a [parallel
        composite strategy](https://cloud.google.com/storage/docs/parallel-composite-uploads).
        Parallelism can be controlled via `--process-count` and `--thread-count`
        flags.

        STREAMING: Streams the data to the bucket, does not use parallelism.
        `--process-count` and `--thread-count` flag values will be ignored if
        provided.
        z--process-count�)�lower_boundz;Number of processes at max to use for each diagnostic test.z--thread-countz9Number of threads at max to use for each diagnostic test.zObject properties:)�	sort_argsrAz--object-countTz2Number of objects to use for each diagnostic test.)�requiredr@rAzObject size properties:)�mutexrHrArIz
--object-size)�upper_boundz,Object size to use for the diagnostic tests.z--object-sizes�OBJECT_SIZES)�element_typez�
        List of object sizes to use for the tests. Sizes should be
        provided for each object specified using `--object-count` flag.
        )rDr@rAzExport diagnostic bundle.z--export�
store_truea
        Generate and export a diagnostic bundle. The following
        information will be bundled and exported into a gzipped tarball
        (.tar.gz):

        - Latest gcloud CLI logs.
        - Output of running the `gcloud storage diagnose` command.
        - Output of running the `gcloud info --anonymize` command.

        Note: This command generates a bundle containing system information like
        disk counter detlas, CPU information and system configurations. Please
        exercise caution while sharing.
        )�actionrIrAz
--destinationzCDestination file path where the diagnostic bundle will be exported.a
                                  table(
                                    name,
                                    operation_results[]:format='table[box](name,payload_description:wrap,result:wrap)'
                                  )
                                  )�SetSortArgs�add_argument�strr�ArgList�sortedr1�value�"download_throughput_diagnostic_lib�DownloadType�FILE� upload_throughput_diagnostic_lib�
UploadType�
BoundedInt�	add_group�
BinarySize�_OBJECT_SIZE_UPPER_BOUND�display_info�	AddFormat)�cls�parser�option�object_properties_group�object_size_properties_group�export_groups      r�Argsz
Diagnose.Args�s��
���u��
���
�
�
:���
����
�
 �
 ��x�@�x�V�F�L�L�x�@�A�
����+��.�����<�I�I�
�I��
�L�L�I�
��3�?�?�D�D����.����
��������:�E�E�
�E��
�L�L�E�
��1�;�;�@�@����0����
�
#�
#��
2�
J���
����
�
#�
#��
2�
H���%�.�.��2�/����(�(���
�
#�
#��
2�
A�	)��$;�#D�#D���
&��	$E�$� �!�-�-��
�
#�
#�0H�
I�
;�.��
!�-�-���
�
 �
 �$�/�/�4��
�
�.���#�#��9�$��L��������	��$����
�
�	�����!�!�#&�'��mA��,
��<
s�J.�J3�J8c���d}|jrl|jr:t|j�|jk7rtd��|j}n&|jr|jg|jz}tj�}g}tj||�5tjj|vrAtj||�}|j�|j|j�tj j|vrxt#j$|j&�}t#j(||||j*|j,��}	|	j�|j|	j�tj.j|vrxt1j2|j4�}
t1j6||
||j*|j,��}|j�|j|j�|jtj8|��|cddd�S#1swYyxYw)z+Runs test with system performance tracking.NzCNumber of object sizes provided should match the number of objects.)�
process_count�thread_count)�object_count�object_sizes�lenr,�object_sizer
�get_system_info_provider�)get_disk_io_stats_delta_diagnostic_resultr1r5rU�latency_diagnostic_lib�LatencyDiagnostic�execute�append�resultr3rVrW�
download_type�DownloadThroughputDiagnosticrirjr4rYrZ�upload_type�UploadThroughputDiagnostic�!get_system_info_diagnostic_result)�selfr-�
url_object�tests_to_runrl�system_info_provider�test_resultsrrvr
rxrs            r�$_run_tests_with_performance_trackingz-Diagnose._run_tests_with_performance_tracking:s!���L����	
�	�	��t� � �!�T�%6�%6�6�����
�*�*�,�����(�(�)�D�,=�,=�=��&�?�?�A���L�	�	>�	>��l�
�
�	�	�	�	�<�	/�3�E�E���
��	�"�"�$����.�5�5�6�	�	%�	%�	+�	+�|�	;�:�G�G����
�
�
/�K�K����"�0�0�!�.�.�
�	'�	'�.�.�0����:�A�A�B�	�	#�	#�	)�	)�\�	9�6�A�A����
��
-�G�G����"�0�0�!�.�.�
�	%�	%�,�,�.����8�?�?�@����
�
7�
7�8L�
M���a
�
�
�s
�'F+I�I%c��tjjtjjtjjg}t|�t
j|j�}t|�}tjjd|j�d��tjjd|j���tjjd|j���|j r
|j }n|}|tj"jgk(rg}n|j%|||�}tj"j|vrLt'j(||j*��}|j-�|j/|j0�|j2rntjjd�t5j6||j8�}tjjdj;|��ytjjd�|S)	NzUsing z! bucket for the diagnostic tests.zBucket location : zBucket storage class : )�	logs_pathzExporting diagnostic bundle...z-Successfully exported diagnostic bundle to {}zGenerating diagnostic report...)r1r3rUr5r4r.rr$r%r r�status�Print�name�location�default_storage_class�	test_typer2r�r	�DirectConnectivityDiagnosticr�rsrtrur&r�export_diagnostic_bundler'�format)	r{r-�
default_testsr|�bucket_resourcer}r�direct_connectivity�export_paths	         r�RunzDiagnose.Run�s���	�$�$�*�*�������"�"�(�(��M��4���4�4�T�X�X�>�J�)�*�5�O��J�J���
��%�%�&�&G�H���J�J���)�/�*B�*B�)C�D�E��J�J���
!�/�"G�"G�!H�I���~�~��^�^�l�"�l���4�4�:�:�;�;��l��>�>�
�
�L��l��#�#�)�)�\�9�
(�
E�
E��������!�!�#����-�4�4�5��{�{�	�j�j���7�8��8�8�
��(�(��k�
�j�j���
9�
@�
@��
M����J�J���6�7��r/N)	r6r7r8r9�
detailed_help�classmethodrgr�r�r:r/rr<r<[s:��&�
�0
�30�-�d�f'��f'�PD�L5r/r<)(r9�enumr(�googlecloudsdk.api_lib.storagerr�'googlecloudsdk.api_lib.storage.gcs_jsonrr�googlecloudsdk.callioperr�"googlecloudsdk.command_lib.storagerrr�+googlecloudsdk.command_lib.storage.diagnoser	r
rVrrrqr
rrY�,googlecloudsdk.command_lib.storage.resourcesr�googlecloudsdk.corerr^�
StorageUrl�GcsBucketResourcer r.�Enumr1�DefaultUniverseOnly�Commandr<r:r/r�<module>r�s��� 3��	�?�M�/�(�G�:�:�V�|�C�d�C�x�O�#� ��
��&�&�
��-�-�
�.�&�t�y�y�����Y�t�|�|�Y��Yr/