
                         v   S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  \R$                  \R&                  " \R(                  R*                  \R(                  R,                  \R(                  R.                  5       " S S\R0                  5      5       5       rg)z,The gcloud Firestore databases ping command.    )absolute_import)division)unicode_literalsN)	databases)base)connection_util)flags)
propertiesc                   6    \ rS rSrSrSrSr\S 5       rS r	Sr
g)	Ping    zTimes the connection and ping time for a Firestore with MongoDB compatibility database.

## EXAMPLES

To time the connection and ping times for a Firestore with MongoDB
compatibility database `testdb`:

    $ {command} --database=testdb
   
   c                 .    [         R                  " U SS9  g )NTrequired)r	   AddDatabaseIdFlag)parsers    'lib/surface/firestore/databases/ping.pyArgs	Ping.Args2   s    	FT2    c                    [         R                  R                  R                  R	                  SS9n[
        R                  " X!R                  5      nUR                   SUR                   S3n/ n[        SU S35        [        U R                  5       H3  n UR                  [        R                  " X@R                   5      5        M5     [)        [+        S U Vs/ s H  o(       d  M  US	   PM     sn5      5      n	U	(       a  [-        U	5      [/        U	5      -  S
 OSn
U Vs/ s H  o(       d  M  US   PM     nn[)        [+        S [0        R2                  R5                  U5      5      5      nU(       a  [-        U5      [/        U5      -  S
 OSn[/        U5      S:  a  [6        R8                  " U5      S
 OSnS[/        U	5       SU R                   SU
 S[/        U5       SU R                   U R                  -   SU SU S3n[        [:        R<                  " U5      5        g ! ["         a3  n[        SU SU 35        [$        R&                  " S5         S nAGM  S nAff = fs  snf s  snf )NTr   .z.firestore.googz Testing connectivity latency to z"Failed to establish connection to z:    r   z.3fzN/Az
    Successful connections: z / z+
    Average connection setup latency (s): z
    Successful pings: z
    Ping time average (s): z'
    Ping time standard deviation (s): z
    )r
   VALUEScoreprojectGetr   GetDatabasedatabaseuid
locationIdprintrange_NUM_CONNECTSappendr   ConnectAndPing
_NUM_PINGSIOErrortimesleeplistfiltersumlen	itertoolschainfrom_iterable
statisticsstdevtextwrapdedent)selfargsr   dbhostnametiming_results_eresultconnect_timesconnection_time_avgping_time_lists
ping_timesping_time_avgping_time_stddevsummarys                   r   RunPing.Run6   sF   $$,,00$0?G			w	6B&&2==/9HN	,XJa
894%%&**8__E	
 ' tnGnFifQinGHM
  }M 223
7 
 0>H~Vyvay~OHtY__22?CDJ 7A3z?S_,S
1e  25Z11D:J'
,%  /0D4F4F3G H++>*? @:'s4??T=O=O+O*P Q)? +''7&8 9G 
(//'
"#=  28*BqcBC

1 H Is0   /H#
I#(	I#"
I(0	I(#
I -'II  N)__name__
__module____qualname____firstlineno____doc__r&   r)   staticmethodr   rG   __static_attributes__rI   r   r   r   r       s*    
 -*3 3*$r   r   )rN   
__future__r   r   r   r1   r4   r6   r+    googlecloudsdk.api_lib.firestorer   googlecloudsdk.callioper   $googlecloudsdk.command_lib.firestorer   r	   googlecloudsdk.corer
   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHABETAGACommandr   rI   r   r   <module>r]      s    3 &  '     6 ( @ 6 * T..33T5F5F5I5I<$4<< <$ <$r   