skywalking icon indicating copy to clipboard operation
skywalking copied to clipboard

[Feature] provides sample option in python agent

Open tsonglew opened this issue 1 year ago • 10 comments
trafficstars

Search before asking

  • [X] I had searched in the issues and found no similar feature requirement.

Description

Support sample option like SW_AGENT_SAMPLE in java agent

Use case

Reduce the trace storage load

Related issues

#5997

Are you willing to submit a pull request to implement this on your own?

  • [X] Yes I am willing to submit a pull request on my own!

Code of Conduct

tsonglew avatar Apr 23 '24 14:04 tsonglew

fyi @Superskyyy

wu-sheng avatar Apr 23 '24 14:04 wu-sheng

Could you briefly describe your idea? Is it possible to dynamically update the value of sample based on the configuration file?

CodePrometheus avatar Apr 23 '24 15:04 CodePrometheus

@CodePrometheus I will achieve the function through following tasks:

  1. Add SW_AGENT_SAMPLE in skywalking/config.py
  2. Create a sampling_service with try_sampling, reset_sampling_factor and other methods. try_sampling will add one to a counter property of sampling_service. reset_sampling_factor will clear the counter.
  3. Modify skywalking/trace/context.py to check if sampling_service.try_sampling returns true every time before creating a new SpanContext. If sampling_service.try_sampling returns false, get_context should return NoopContext.
  4. A scheduler thread will be started when initializing a sampling service, it will reset the sampling factor every 3 seconds.

Dynamically updating the value based on the configuration file or environment variables will not be implemented.

tsonglew avatar May 02 '24 12:05 tsonglew

Could you briefly describe your idea? Is it possible to dynamically update the value of sample based on the configuration file?

@CodePrometheus Could you be more specific about this? What do you mean based on file?

The above logic seems to be as same as Java agent sampling.

wu-sheng avatar May 04 '24 01:05 wu-sheng

@CodePrometheus Could you be more specific about this? What do you mean based on file?

The above logic seems to be as same as Java agent sampling.

Yes, the above logic is similar to the existing sample_n_per_3_secs in Java agent. I want to refer to dynamic configuration, ref https://github.com/apache/skywalking/issues/6114

CodePrometheus avatar May 04 '24 02:05 CodePrometheus

I am not sure whether python agent supports dynamic configuration in the kernel already? @Superskyyy

wu-sheng avatar May 04 '24 02:05 wu-sheng

I am not sure whether python agent supports dynamic configuration in the kernel already? @Superskyyy

Currently, this capability is not implemented in python-agent.

CodePrometheus avatar May 07 '24 17:05 CodePrometheus

@tsonglew Are you going to add this too?

wu-sheng avatar May 08 '24 00:05 wu-sheng

@tsonglew Are you going to add this too?

Yes, I will create another mr for config change events

tsonglew avatar May 10 '24 11:05 tsonglew