
    {                         S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	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rSrSrS rS	 r " S
 S\5      rS r " S S\5      rg)zA library for logs tailing.    N)apis)
gapic_util)log   zMhttps://cloud.google.com/logging/docs/reference/tools/gcloud-logging#tailing.c           
         [         R                  R                  S[         R                  R                  S[         R                  R                  S[         R                  R
                  S[         R                  R                  S0nU R                  5       [         R                  R                  :X  a  gU" U 5        U" SR                  UR                  U R                  5       S5      U R                  5       5      5        g)	z(Handles _MultiThreadedRendezvous errors.zInvalid argument.z&There are too many tail sessions open.zInternal error.z-Access is denied or has changed for resource.zTThe maximum duration for tail has been met. The command may be repeated to continue.Nz{} ({})zUnknown error encountered.)grpc
StatusCodeINVALID_ARGUMENTRESOURCE_EXHAUSTEDINTERNALPERMISSION_DENIEDOUT_OF_RANGEcode	CANCELLEDformatgetdetails)
rendezvousoutput_debugoutput_warningerror_messages_by_codes       -lib/googlecloudsdk/api_lib/logging/tailing.py_HandleGrpcRendezvousr   .   s     oo&&

oo((
2
oo

oo''
9
oo""6 __$//333
z!!  !2!=?     c                 R   [         R                  " SS5      nUR                  R                  R                  nUR
                  R                  SUR
                  R                  S0nU R                  5        H.  u  pVUR                  USR                  U5      5      nU" Xv5        M0     g)zHandles supression counts.loggingv2zLogging API backend rate limitz,client not consuming messages quickly enoughzUNKNOWN REASON: {}N)r   GetGapicClientClasstypesTailLogEntriesResponseSuppressionInfoReason
RATE_LIMITNOT_CONSUMEDitemsr   r   )counts_by_reasonhandlerclient_classsuppression_infosuppression_reason_stringsreasoncountreason_strings           r   _HandleSuppressionCountsr.   I   s    )))T:,"((??OO ((
***
8	  (--/mf.22$++F35MM! 0r   c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)_SuppressionInfoAccumulatorZ   zKAccumulates and outputs information about suppression for the tail session.c                     Xl         X l        X0l        [        R                  " 5       U l        [        R                  " 5       U l        U" 5       U l        g N)_get_now_warning_errorcollectionsCounter_count_by_reason_delta_count_by_reason_cumulative_last_flush)selfget_nowr   output_errors       r   __init__$_SuppressionInfoAccumulator.__init__]   s=    M"MK"-"5"5"7D'2':':'<D$yDr   c                 L    U R                  SR                  [        5      5        g )Nz$Find guidance for suppression at {}.)r5   r   _HELP_PAGE_LINKr<   s    r   _OutputSuppressionHelpMessage9_SuppressionInfoAccumulator._OutputSuppressionHelpMessagee   s    MM.55oFHr   c                 f    U R                  5       U R                  -
  R                  5       [        :  $ r3   )r4   r;   total_seconds&_SUPPRESSION_INFO_FLUSH_PERIOD_SECONDSrC   s    r   _ShouldFlush(_SuppressionInfoAccumulator._ShouldFlushi   s,    MMOd...]_EF Fr   c                 D    U R                  SR                  X!5      5        g )Nz Suppressed {} entries due to {}.)r6   r   r<   r-   r,   s      r   _OutputSuppressionDeltaMessage:_SuppressionInfoAccumulator._OutputSuppressionDeltaMessagem   s    KK299%OPr   c                 D    U R                  SR                  X!5      5        g )Nz+In total, suppressed {} messages due to {}.)r5   r   rL   s      r   #_OutputSuppressionCumulativeMessage?_SuppressionInfoAccumulator._OutputSuppressionCumulativeMessagep   s    MM?FF r   c                     U R                  5       U l        [        U R                  U R                  5        U =R
                  U R                  -  sl        U R                  R                  5         g r3   )r4   r;   r.   r9   rM   r:   clearrC   s    r   _Flush"_SuppressionInfoAccumulator._Flusht   sS    }}DT88!@@B$$(C(CC$%%'r   c                     U R                  5         [        U R                  U R                  5        U R                  (       a  U R	                  5         g g r3   )rT   r.   r:   rP   rD   rC   s    r   Finish"_SuppressionInfoAccumulator.Finish{   s?    KKMT==!EEG''
((* (r   c           	          U =R                   [        R                  " U Vs0 s H  o"R                  UR                  _M     sn5      -  sl         U R                  5       (       a  U R                  5         g g s  snf r3   )r9   r7   r8   r+   suppressed_countrI   rT   )r<   r)   infos      r   Add_SuppressionInfoAccumulator.Add   sf    ;#6#68HI8Hd++	+8HI$K K
kkm  	Js    A6)r:   r9   r6   r4   r;   r5   N)__name__
__module____qualname____firstlineno____doc__r?   rD   rI   rM   rP   rT   rW   r\   __static_attributes__ r   r   r0   r0   Z   s0    S!HFQ(+r   r0   c              #     #    UR                  5         [        XU5      nSnUR                  (       aV   UR                  5       nUR                  UR                  5        UR                   H  n	U	v   M	     UR                  (       a  MV  U(       a  [        XcU5        UR                  5         UR                  5         g! [        R
                   a  nUn SnAMP  SnAff = f7f)a  Streams entries back from the Logging API.

Args:
  get_now: A callable that returns the current time.
  output_warning: A callable that outputs the argument as a warning.
  output_error: A callable that outputs the argument as an error.
  output_debug: A callable that outputs the argument as debug info.
  tail_stub: The `BidiRpc` stub to use.

Yields:
  Entries included in the tail session.
N)openr0   	is_activerecvr   RpcErrorr\   r)   entriesr   rW   close)
r=   r   r>   r   	tail_stubsuppression_info_accumulatorerrorresponseeentrys
             r   _StreamEntriesrr      s      ..!<|"-
%!h !$$X%>%>?!!k " 	  %~>%%'// == es5   0C B< AC 4C <CCC CC c                       \ rS rSrSrS rS rS\R                  R                  \R                  \R                  \R                  R                  4S jrS rSrg)		LogTailer   zStreams logs using gRPC.c                     [         R                  " SS5      U l        [        R                  " 5       U l        U R
                  R                  U R                  5        S U l        g )Nr   r   )r   GetGapicClientInstanceclient
contextlib	ExitStack_exit_stackenter_contextrl   rC   s    r   r?   LogTailer.__init__   sF    --i>DK!++-D""4;;/DNr   c                 X    U R                  5         U R                  R                  5         g r3   )Stopr{   rk   rC   s    r   rk   LogTailer.close   s    IIKr   Nc              #     #    U R                   R                  R                  5       nUR                  R	                  U5        X(l        [        R                  " U R                   U R                   R                  R                  R                  US9U l        U(       a  [        R                  " US9Ul        [        XtUX`R                  5       H  n	U	v   M	     g7f)a  Tails log entries from the Cloud Logging API.

Args:
  resource_names: The resource names to tail.
  logs_filter: The Cloud Logging filter identifying entries to include in
    the session.
  buffer_window_seconds: The amount of time that Cloud Logging should buffer
    entries to get correct ordering, or None if the backend should use its
    default.
  output_warning: A callable that outputs the argument as a warning.
  output_error: A callable that outputs the argument as an error.
  output_debug: A callable that outputs the argument as debug.
  get_now: A callable that returns the current time.

Yields:
  Entries for the tail session.
)initial_request)secondsN)rx   r   TailLogEntriesRequestresource_namesextendfilterr   MakeBidiRpcr   	transporttail_log_entriesrl   datetime	timedeltabuffer_windowrr   )
r<   r   logs_filterbuffer_window_secondsr   r>   r   r=   requestrq   s
             r   TailLogsLogTailer.TailLogs   s     2 kk557G!!.1 N++T[[((22CC!DN &009NOg ,nn>k>s   CCc                 \    U R                   (       a  U R                   R                  5         g g r3   )rl   rk   rC   s    r   r   LogTailer.Stop   s    ~~
nn r   )r{   rx   rl   )r^   r_   r`   ra   rb   r?   rk   r   errPrintrn   debugr   nowr   r   rc   rd   r   r   rt   rt      sG      &*!ggmmIIII((,,$Lr   rt   )rb   r7   ry   r   +google.appengine.logging.v1.request_log_pb2google"google.appengine.v1.audit_data_pb2&google.appengine.v1beta.audit_data_pb23google.cloud.appengine_v1alpha.proto.audit_data_pb2 google.cloud.audit.audit_log_pb2/google.cloud.bigquery.logging.v1.audit_data_pb2"google.iam.admin.v1.audit_data_pb2$google.iam.v1.logging.audit_data_pb2google.type.money_pb2googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r   r   rH   rB   r   r.   objectr0   rr   rt   rd   r   r   <module>r      sv    "    3 ) - : ' 6 ) +  - * #  *+ &a6"",& ,^"J6 6r   