You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/01/27 16:08:05 UTC

[GitHub] [skywalking-python] tom-pytel opened a new pull request #116: fix: grpc timeout segment data loss

tom-pytel opened a new pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116


   Please review this thoroughly because all I wanted to do was resend segments which failed to send due to a grpc timeout. But unexpectedly the behavior of grpc timeout changed, it doesn't time out anymore, the heartbeat seems to keep it alive now. I don't understand why this behavior changed so tha is why I am requesting a thorough looking at this.
   
   <!-- Uncomment the following checklist WHEN AND ONLY WHEN you're adding a new plugin -->
   <!--
   - [ ] Add a test case for the new plugin
   - [ ] Add a component id in [the main repo](https://github.com/apache/skywalking/blob/master/oap-server/server-bootstrap/src/main/resources/component-libraries.yml#L415)
   - [ ] Add a logo in [the UI repo](https://github.com/apache/skywalking-rocketbot-ui/tree/master/src/views/components/topology/assets)
   - [ ] Rebuild the `requirements.txt` by running `tools/env/build_requirements_(linux|windows).sh`
   -->
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] wu-sheng commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768416427


   I know we could dequeue, but still, highly recommend you to take a look at Satellite project. It provides a much bettet way to resolve this case by leveraging file system.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] kezhenxu94 commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768801454


   @tom-pytel I'm +1 to put the segments back to the queue when the it is not full and abandon the oldest segments if it's full.
   
   As for the timeout issue, I had a quick glance of the codes and guess (don't have too much time ATM to look thoroughly and test myself) the reason may be the changes from `self.traces_reporter.report(generator())` to `self.traces_reporter.report(iter([s]))`, the former `generator()` was blocking the `self.traces_reporter.report` and may cause timeout, while the latter one doesn't.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] muse-dev[bot] commented on a change in pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
muse-dev[bot] commented on a change in pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#discussion_r566248808



##########
File path: skywalking/agent/protocol/grpc.py
##########
@@ -68,10 +68,15 @@ def on_error(self):
         self.channel.subscribe(self._cb, try_to_connect=True)
 
     def report(self, queue: Queue, block: bool = True):
+        start = time()

Review comment:
       *Unbound name:*  Name `time` is used but not defined in the current scope.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel edited a comment on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel edited a comment on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768404151


   > From my understanding, the timeout should make the segments abandoned with keeping the agent memory as much as possible.
   > This is not specific for the agent, it is recommended, implemented, and kept in all agents. The users will never know how to determine which trace segments should be kept, and others are not in the runtime.
   > I am not checking the codes, but it should be in this way. @kezhenxu94
   
   Well there is already a mechanism to reject segments if the queue is full, in agent/\_\_init\_\_.py:archive() the queue is explicitly checked and segment is rejected if full. All I am trying to do is if queue is not full to not lose the segments that are there.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel edited a comment on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel edited a comment on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768410938


   > OK, this is another case, but also a tricky case in the product environment.
   > The queue could be full or closer to be full because of this mechanism, then new segments will be injected.
   > Which segments are more important to keep?
   
   If you want the new segments to take precedence then that `archive()` call could pop the oldest segment off the queue if it is full to make space for the new one, something like the following but with all the proper error checking:
   ```py
   def archive(segment: 'Segment'):
       if __queue.full():
           __queue.get()
           logger.warning('the queue is full, the oldest segment was abandoned')
   
       __queue.put(segment)
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] wu-sheng commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768666881


   > > I know we could dequeue, but still, highly recommend you to take a look at Satellite project. It provides a much bettet way to resolve this case by leveraging file system.
   > 
   > Well, we will probably eventually be looking at that but for now it is overkill for the small problem I am tasked with which is just not to drop sporadic segment data on silly timeouts. If you don't want this fix in your codebase its no problem I will just wind up doing it in our own fork then. So do you want me to add the dequeueing and keep this or just do on our own side?
   > 
   > Apart from that, like I said, I still don't understand why the grpc connection stopped timing out. The old code would time out constantly regardless of the heartbeat and this code works more like I expect was the intention which is that it does not actually time out as long as the server is up. Would be good to have an explanation for this since even if I don't add this fix to your codebase you could limit data losses just by fixing the constant timeout problem.
   
   I will leave the decision to @kezhenxu94 and you, once the memory cost is limited as much as the queue side, I am good for either re-push segment into the queue if there is available slot, or expire the oldest data in the queue.
   I agree that gRPC connection should be back to available if the OAP is back, also, please check the case that, there is a case, the connection may not restore based on gRPC reconnection mechanism, according to Java
   > If you set the backend address by a domain name, which should be resolved by a DNS server, rather than local HOST file, then rebooting OAP(or a new pod in k8s), actually IP changed, but same domain name. At this case, the client side is required to re-resolve the domain addresses.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768428683


   > I know we could dequeue, but still, highly recommend you to take a look at Satellite project. It provides a much bettet way to resolve this case by leveraging file system.
   
   Well, we will probably eventually be looking at that but for now it is overkill for the small problem I am tasked with which is just not to drop sporadic segment data on silly timeouts. If you don't want this fix in your codebase its no problem I will just wind up doing it in our own fork then. So do you want me to add the dequeueing and keep this or just do on our own side?
   
   Apart from that, like I said, I still don't understand why the grpc connection stopped timing out. The old code would time out constantly regardless of the heartbeat and this code works more like I expect was the intention which is that it does not actually time out as long as the server is up. Would be good to have an explanation for this since even if I don't add this fix to your codebase you could limit data losses just by fixing the constant timeout problem.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel edited a comment on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel edited a comment on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768410938


   > OK, this is another case, but also a tricky case in the product environment.
   > The queue could be full or closer to be full because of this mechanism, then new segments will be injected.
   > Which segments are more important to keep?
   
   If you want the new segments to take precedence then that `archive()` call could pop the oldest segment off the queue if it is full to make space for the new one, something like the following but with all the proper error checking:
   ```py
   def archive(segment: 'Segment'):
       if __queue.full():
           __queue.get()
           logger.warning('the queue is full, the oldest segment was abandoned')
   
       __queue.put(segment)
   ```
   The benefit here being that if you are not running the queue full then you will not lose segments at all.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768670352


   > I will leave the decision to @kezhenxu94 and you, once the memory cost is limited as much as the queue side, I am good for either re-push segment into the queue if there is available slot, or expire the oldest data in the queue.
   > I agree that gRPC connection should be back to available if the OAP is back, also, please check the case that, there is a case, the connection may not restore based on gRPC reconnection mechanism, according to Java
   > 
   > > If you set the backend address by a domain name, which should be resolved by a DNS server, rather than local HOST file, then rebooting OAP(or a new pod in k8s), actually IP changed, but same domain name. At this case, the client side is required to re-resolve the domain addresses.
   
   Ok, well I am also curious for @kezhenxu94's opinion. Specifically I haven't looked at how this grpc works under the hood so maybe he can tell me if this new code isn't doing something incredibly stupid like creating a new connection for each segment...


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] wu-sheng commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768417723


   https://github.com/apache/skywalking-satellite


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768410938


   > OK, this is another case, but also a tricky case in the product environment.
   > The queue could be full or closer to be full because of this mechanism, then new segments will be injected.
   > Which segments are more important to keep?
   
   If you want the new segments to take precedence then that `archive()` call could pop the oldest segment off the queue if it is full to make space for the new one.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768982383


   Now for some thoughts. I changed from a continuous send to send one segment at a time because with a continuous send I could not be guaranteed to know where the error happened and would not know which segment(s) to resend. For example does the grpc go one by one pulling then sending to stream or does it build up blocks of segments before trying to stream them? How efficient is it to send one segment at a time on a client stream function? What is the overhead of setting up a stream per-segment? Do you have a single unitary segment send function defined in your protocol which could do this more efficiently or is it only streams?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] wu-sheng commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768401528


   From my understanding, the timeout should make the segments abandoned with keeping the agent memory as much as possible.
   This is not specific for the agent, it is recommended, implemented, and kept in all agents. The users will never know how to determine which trace segments should be kept, and others are not in the runtime.
   I am not checking the codes, but it should be in this way. @kezhenxu94


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] wu-sheng commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768407507


   OK, this is another case, but also a tricky case in the product environment.
   The queue could be full or closer to be full because of this mechanism, then new segments will be injected. 
   Which segments are more important to keep?😃


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] kezhenxu94 commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768959233


   > As for the timeout issue, I had a quick glance of the codes and guess (don't have too much time ATM to look thoroughly and test myself) the reason may be the changes from `self.traces_reporter.report(generator())` to `self.traces_reporter.report(iter([s]))`, the former `generator()` was blocking the `self.traces_reporter.report` and may cause timeout, while the latter one doesn't.
   
   OK just did a quick experiment, seems to be the case, I just changed a shorter timeout intentionally and the codes before this PR throws timeout exception constantly, while those after this PR don't.
   
   ```diff
   diff --git a/skywalking/client/grpc.py b/skywalking/client/grpc.py
   index 734d3bb..81de589 100644
   --- a/skywalking/client/grpc.py
   +++ b/skywalking/client/grpc.py
   @@ -55,4 +55,4 @@ class GrpcTraceSegmentReportService(TraceSegmentReportService):
            self.report_stub = TraceSegmentReportServiceStub(channel)
    
        def report(self, generator):
   -        self.report_stub.collect(generator)
   +        self.report_stub.collect(generator, timeout=3)
   ```
   
   
   ```text
   skywalking [Thread-21] [DEBUG] grpc channel connectivity changed, [ChannelConnectivity.READY -> ChannelConnectivity.READY]
   Traceback (most recent call last):
     File "/Users/kezhenxu94/workspace/skywalking-python/venv/lib/python3.8/site-packages/apache_skywalking-0.5.0-py3.8.egg/skywalking/agent/protocol/grpc.py", line 122, in report
       self.traces_reporter.report(generator())
     File "/Users/kezhenxu94/workspace/skywalking-python/venv/lib/python3.8/site-packages/apache_skywalking-0.5.0-py3.8.egg/skywalking/client/grpc.py", line 58, in report
       self.report_stub.collect(generator, timeout=3)
     File "/Users/kezhenxu94/workspace/skywalking-python/venv/lib/python3.8/site-packages/grpc/_channel.py", line 1011, in __call__
       return _end_unary_response_blocking(state, call, False, None)
     File "/Users/kezhenxu94/workspace/skywalking-python/venv/lib/python3.8/site-packages/grpc/_channel.py", line 729, in _end_unary_response_blocking
       raise _InactiveRpcError(state)
   grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
   	status = StatusCode.DEADLINE_EXCEEDED
   	details = "Deadline Exceeded"
   	debug_error_string = "{"created":"@1611829792.286230000","description":"Error received from peer ipv4:127.0.0.1:11800","file":"src/core/lib/surface/call.cc","file_line":1062,"grpc_message":"Deadline Exceeded","grpc_status":4}"
   >
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel edited a comment on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel edited a comment on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768410938


   > OK, this is another case, but also a tricky case in the product environment.
   > The queue could be full or closer to be full because of this mechanism, then new segments will be injected.
   > Which segments are more important to keep?
   
   If you want the new segments to take precedence then that `archive()` call could pop the oldest segment off the queue if it is full to make space for the new one, something like the following but with all the proper error checking:
   ```js
   def archive(segment: 'Segment'):
       if __queue.full():
           __queue.get()
           logger.warning('the queue is full, the oldest segment was abandoned')
   
       __queue.put(segment)
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] kezhenxu94 commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768802156


   On the other hand, it's not that different to abandon the oldest segments or the latest segments  when the queue is full, maybe abandon the latest segments so that we don't need to `get` and `put` over and over again when there are too many traffics?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] kezhenxu94 commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768988580


   > I could not be guaranteed to know where the error happened and would not know which segment(s) to resend. 
   
   The streaming itself returns a generator of responses so that may be a clue (not sure).
   
   > Do you have a single unitary segment send function defined in your protocol which could do this more efficiently or is it only streams?
   
   I think we only provide stream for this case (segment).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] wu-sheng edited a comment on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
wu-sheng edited a comment on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768401528


   From my understanding, the timeout should make the segments abandoned with keeping the agent memory cost as less as possible.
   This is not specific for python agent, it is recommended, implemented, and kept in all agents. The users will never know how to determine which trace segments should be kept, and others are not in the runtime.
   I am not checking the codes, but it should be in this way. @kezhenxu94


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-769219850


   Ok, so I was uncomfortable with the idea of sending segments one by one using a streaming call so did a different way. There are now two mechanisms to prevent data loss here.
   * Added a `queue.get()` timeout so that `report()` will not block forever also setting a `collect()` timeout higher than this to make sure `report()` returns before a `collect()` timeout can possibly happen.
   * Even if a timeout does happen somehow, the last segment processed is pushed back onto the queue for another attempt when the connection is reestablished (I checked that it does seem to be processed one segment at a time and not in blocks).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] kezhenxu94 merged pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
kezhenxu94 merged pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] kezhenxu94 commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-769541217


   > Ok, so I was uncomfortable with the idea of sending segments one by one using a streaming call so did a different way. There are now two mechanisms to prevent data loss here.
   > 
   > * Added a `queue.get()` timeout so that `report()` will not block forever also setting a `collect()` timeout higher than this to make sure `report()` returns before a `collect()` timeout can possibly happen.
   > * Even if a timeout does happen somehow, the last segment processed is pushed back onto the queue for another attempt when the connection is reestablished (I checked that it does seem to be processed one segment at a time and not in blocks).
   
   This looks better than the previous method. Thanks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel edited a comment on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel edited a comment on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768404151


   > From my understanding, the timeout should make the segments abandoned with keeping the agent memory as much as possible.
   > This is not specific for the agent, it is recommended, implemented, and kept in all agents. The users will never know how to determine which trace segments should be kept, and others are not in the runtime.
   > I am not checking the codes, but it should be in this way. @kezhenxu94
   
   Well there is already a mechanism to reject segments if the queue is full, in agent/\_\_init\_\_.py:archive() the queue is explicitly checked and segment is rejected if full. All I am trying to do is if queue is not full to not lose the segments that have already made it into the queue.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768404151


   > From my understanding, the timeout should make the segments abandoned with keeping the agent memory as much as possible.
   > This is not specific for the agent, it is recommended, implemented, and kept in all agents. The users will never know how to determine which trace segments should be kept, and others are not in the runtime.
   > I am not checking the codes, but it should be in this way. @kezhenxu94
   
   Well there is already a mechanism to reject segments if the queue is full, in agent/__init__.py:archive() the queue is explicitly checked and segment is rejected if full. All I am trying to do is if queue is not full to not lose the segments that are there.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768979907


   > On the other hand, it's not that different to abandon the oldest segments or the latest segments when the queue is full, maybe abandon the latest segments so that we don't need to `get` and `put` over and over again when there are too many traffics?
   
   This can be changed very easily in code so you could leave it as it is and change if needed at some point. It could even be configurable at runtime if you want.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel commented on pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
tom-pytel commented on pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#issuecomment-768989656


   > > I could not be guaranteed to know where the error happened and would not know which segment(s) to resend.
   > 
   > The streaming itself returns a generator of responses so that may be a clue (not sure).
   
   Ok, well then don't merge until I dig a little deeper to see if it can be made more efficient.
   
   > > Do you have a single unitary segment send function defined in your protocol which could do this more efficiently or is it only streams?
   > 
   > I think we only provide stream for this case (segment).
   
   Any thoughts about introducing one in the future?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] muse-dev[bot] commented on a change in pull request #116: fix: grpc timeout segment data loss

Posted by GitBox <gi...@apache.org>.
muse-dev[bot] commented on a change in pull request #116:
URL: https://github.com/apache/skywalking-python/pull/116#discussion_r565436456



##########
File path: skywalking/agent/protocol/grpc.py
##########
@@ -67,58 +67,65 @@ def on_error(self):
         self.channel.unsubscribe(self._cb)
         self.channel.subscribe(self._cb, try_to_connect=True)
 
-    def report(self, queue: Queue, block: bool = True):
-        def generator():
-            while True:
-                try:
-                    segment = queue.get(block=block)  # type: Segment
-                except Empty:
-                    return
+    def report(self, queue: Queue, block: bool = True, fini: bool = False):
+        while True:
+            try:
+                segment = queue.get(block=block)  # type: Segment
+            except Empty:
+                return
+
+            queue.task_done()
+
+            logger.debug('reporting segment %s', segment)
+
+            s = SegmentObject(
+                traceId=str(segment.related_traces[0]),
+                traceSegmentId=str(segment.segment_id),
+                service=config.service_name,
+                serviceInstance=config.service_instance,
+                spans=[SpanObject(
+                    spanId=span.sid,
+                    parentSpanId=span.pid,
+                    startTime=span.start_time,
+                    endTime=span.end_time,
+                    operationName=span.op,
+                    peer=span.peer,
+                    spanType=span.kind.name,
+                    spanLayer=span.layer.name,
+                    componentId=span.component.value,
+                    isError=span.error_occurred,
+                    logs=[Log(
+                        time=int(log.timestamp * 1000),
+                        data=[KeyStringValuePair(key=item.key, value=item.val) for item in log.items],
+                    ) for log in span.logs],
+                    tags=[KeyStringValuePair(
+                        key=str(tag.key),
+                        value=str(tag.val),
+                    ) for tag in span.tags],
+                    refs=[SegmentReference(
+                        refType=0 if ref.ref_type == "CrossProcess" else 1,
+                        traceId=ref.trace_id,
+                        parentTraceSegmentId=ref.segment_id,
+                        parentSpanId=ref.span_id,
+                        parentService=ref.service,
+                        parentServiceInstance=ref.service_instance,
+                        parentEndpoint=ref.endpoint,
+                        networkAddressUsedAtPeer=ref.client_address,
+                    ) for ref in span.refs if ref.trace_id],
+                ) for span in segment.spans],
+            )
 
-                logger.debug('reporting segment %s', segment)
-
-                s = SegmentObject(
-                    traceId=str(segment.related_traces[0]),
-                    traceSegmentId=str(segment.segment_id),
-                    service=config.service_name,
-                    serviceInstance=config.service_instance,
-                    spans=[SpanObject(
-                        spanId=span.sid,
-                        parentSpanId=span.pid,
-                        startTime=span.start_time,
-                        endTime=span.end_time,
-                        operationName=span.op,
-                        peer=span.peer,
-                        spanType=span.kind.name,
-                        spanLayer=span.layer.name,
-                        componentId=span.component.value,
-                        isError=span.error_occurred,
-                        logs=[Log(
-                            time=int(log.timestamp * 1000),
-                            data=[KeyStringValuePair(key=item.key, value=item.val) for item in log.items],
-                        ) for log in span.logs],
-                        tags=[KeyStringValuePair(
-                            key=str(tag.key),
-                            value=str(tag.val),
-                        ) for tag in span.tags],
-                        refs=[SegmentReference(
-                            refType=0 if ref.ref_type == "CrossProcess" else 1,
-                            traceId=ref.trace_id,
-                            parentTraceSegmentId=ref.segment_id,
-                            parentSpanId=ref.span_id,
-                            parentService=ref.service,
-                            parentServiceInstance=ref.service_instance,
-                            parentEndpoint=ref.endpoint,
-                            networkAddressUsedAtPeer=ref.client_address,
-                        ) for ref in span.refs if ref.trace_id],
-                    ) for span in segment.spans],
-                )
-
-                yield s
-
-                queue.task_done()
+            try:
+                self.traces_reporter.report(iter([s]))
 
-        try:
-            self.traces_reporter.report(generator())
-        except grpc.RpcError:
-            self.on_error()
+            except grpc.RpcError:
+                self.on_error()
+                queue.put(segment)  # put back segment that failed to send for another attempt
+
+                # If not finalizing app then let grpc reconnect and leave this segment send for next update.
+                # Otherwise, if finalizing, then there will not be a next update so we have to wait for reconnect and
+                # finish send here. We retry up to 3 times then we give up.
+                if not fini or fini > 3:
+                    return
+
+                fini += 1  # yes, True += 1, its Python...

Review comment:
       *Incompatible variable type:*  fini is declared to have type `bool` but is used as type `int`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org