skywalking icon indicating copy to clipboard operation
skywalking copied to clipboard

Improve Zipkin<->SkyWalking integration

Open wu-sheng opened this issue 7 years ago • 25 comments

Today's analysis process, in the easy scenario, really could transfer spans to SkyWalking trace. We used to demo it. Such as

  • https://twitter.com/adrianfcole/status/1007625470886567936

I am welcome to have a deeper discussion on improving this feature. But please notice, as an APM, we have less flexible in span tags and the spans of each trace. Meaning, if you want to have the SkyWalking topology, metrics, and alarm, you need to have logically the same raw data.

Right now, the major issues of Zipkin receiver, not production ready are

  1. Cluster mode is not supported. Because Zipkin sends trace through span by span. But the whole analysis needs the whole trace to build SkyWalking segments. One segment means all spans of one trace in one process(or thread). But in ZipkinSkyWalkingTransfer#doTransfer, it uses CacheFactory.INSTANCE, which use CaffeineSpanCache to cache the span with timeout mechanism. The CaffeineSpanCache use memory cache. In production and cluster mode, this cache should be a distributed cache env, and each trace timeout should be controlled by one OAP instance. Such as always let the OAP instance, who received the root span, to process the timeout and analysis the whole trace.
  2. CaffeineSpanCache#onRemoval is the entrance based on timeout to assume the whole trace has been received, which could begin to analysis in Zipkin2SkyWalkingTransfer. The transfer process in SegmentBuilder#build including the complex steps, which I am not sure ready and suitable for everyone.

I think you have read https://github.com/SkyAPM/zipkin-skywalking , actually, that document is wrote by me and @adriancole back to the back we were building this feature as step one.

So, you need to fix the above two issues.

Also, when we came into SkyWalking 6.x, we have a better solution than analysis of the whole trace.

The following suggestion should have better performance in trace analysis, but you need to understand SkyWalking more. When needAnalysis=false today, the trace/span have been saved in storage already, and query has been supported. So, the things we left are topology and metrics, these two actually are the same thing. Build scopes. You could read MultiScopesSpanListener#parseEntry, MultiScopesSpanListener#parseExit and MultiScopesSpanListener#build. Especially the #build method. If you have read SkyWalking OAL document, you should know, SkyWalking analysis core receives the scopes. In Zipkin receiver, we could only process span having remoteEndpoint, matching the client span <-> server span, instead of building the whole trace. Build the service, service instance, endpoint and relationship scopes. This could significantly reduce the memory cost of distributed cache in issue(1). But you still need that the cache.

wu-sheng avatar May 12 '19 00:05 wu-sheng

I found some inconsistency regarding Zipkin spans. I am testing with a setting needAnalysis=true. I see that tracing is not visible. It turned out skywalking queries index zipkin_span which is empty.

On the other hand, when needAnalysis=false, org.apache.skywalking.oap.server.receiver.zipkin.trace.SpanForward#send is called and spans are being saved to zipkin_span.

Should zipkin_span be populated with spans or we should rather query some other index when browsing tracing?

I see that in org.apache.skywalking.oap.server.core.query.TraceQueryService a decision is made which DAO to load. Of course in my case Zipkin storage is on so org.apache.skywalking.oap.server.storage.plugin.zipkin.elasticsearch.ZipkinTraceQueryEsDAO is loaded.

   private ITraceQueryDAO getTraceQueryDAO() {
        if (traceQueryDAO == null) {
            this.traceQueryDAO = moduleManager.find(StorageModule.NAME).provider().getService(ITraceQueryDAO.class);
        }
        return traceQueryDAO;
    }

tommic81 avatar May 14 '19 09:05 tommic81

I think this is a wrong description in document, when I submit span storage implementation. If analysis is true, there is no need to switch to zipkin elasticsearch, keep as elasticsearch.

wu-sheng avatar May 14 '19 10:05 wu-sheng

I think this is a wrong description in document, when I submit span storage implementation. If analysis is true, there is no need to change storage.

wu-sheng avatar May 14 '19 10:05 wu-sheng

I could understand this description easily. nice

On Sun, May 12, 2019, 8:20 AM 吴晟 Wu Sheng [email protected] wrote:

Today's analysis process, in the easy scenario, really could transfer spans to SkyWalking trace. We used to demo it. Such as

  • https://twitter.com/adrianfcole/status/1007625470886567936

I am welcome to have a deeper discussion on improving this feature. But please notice, as an APM, we have less flexible in span tags and the spans of each trace. Meaning, if you want to have the SkyWalking topology, metrics, and alarm, you need to have logically the same raw data.

Right now, the major issues of Zipkin receiver, not production ready are

  1. Cluster mode is not supported. Because Zipkin sends trace through span by span. But the whole analysis needs the whole trace to build SkyWalking segments. One segment means all spans of one trace in one process(or thread). But in ZipkinSkyWalkingTransfer#doTransfer, it uses CacheFactory.INSTANCE, which use CaffeineSpanCache to cache the span with timeout mechanism. The CaffeineSpanCache use memory cache. In production and cluster mode, this cache should be a distributed cache env, and each trace timeout should be controlled by one OAP instance. Such as always let the OAP instance, who received the root span, to process the timeout and analysis the whole trace.
  2. CaffeineSpanCache#onRemoval is the entrance based on timeout to assume the whole trace has been received, which could begin to analysis in Zipkin2SkyWalkingTransfer. The transfer process in SegmentBuilder#build including the complex steps, which I am not sure ready and suitable for everyone.

I think you have read https://github.com/SkyAPM/zipkin-skywalking , actually, that document is wrote by me and @adriancole https://github.com/adriancole back to the back we were building this feature as step one.

So, you need to fix the above two issues.

Also, when we came into SkyWalking 6.x, we have a better solution than analysis of the whole trace.

The following suggestion should have better performance in trace analysis, but you need to understand SkyWalking more. When needAnalysis=false today, the trace/span have been saved in storage already, and query has been supported. So, the things we left are topology and metrics, these two actually are the same thing. Build scopes. You could read MultiScopesSpanListener#parseEntry, MultiScopesSpanListener#parseExit and MultiScopesSpanListener#build. Especially the #build method. If you have read SkyWalking OAL document, you should know, SkyWalking analysis core receives the scopes. In Zipkin receiver, we could only process span having remoteEndpoint, matching the client span <-> server span, instead of building the whole trace. Build the service, service instance, endpoint and relationship scopes. This could significantly reduce the memory cost of distributed cache in issue(1). But you still need that the cache.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/apache/skywalking/issues/2653, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAPVV76POPBWAEBP4OTQ73PU5PEHANCNFSM4HMJHS6A .

codefromthecrypt avatar May 14 '19 11:05 codefromthecrypt

Hi, We have a problem with relations between particular spans. I my scenario a tracing consists of 3 spans: 2 CLIENT kind, 1 SERVER kind.

Calls tree looks like that: 1 client span (id=74a5bdd765145dd2) --> 2 client span (id=76b8e4cf36177665, parent=74a5bdd765145dd2) --> 3 server span (id=d6762f661eb4de16, parent=76b8e4cf36177665).

In Zipking server, spans are presented correctly whilst in Skywalking, CLIENT spans are not connected to each other. root --> 1 client span (id=74a5bdd765145dd2) root --> 2 client span (id=76b8e4cf36177665, parent=74a5bdd765145dd2) --> 3 server span (id=d6762f661eb4de16, parent=76b8e4cf36177665)

I believe I found a suspicious piece of code. In org.apache.skywalking.oap.server.receiver.zipkin.analysis.transform.SegmentBuilder#initSpan there is a switch which assumes that there might be built a reference only when SERVER span arrives:

 switch (kind) {
            case CLIENT:
                spanBuilder.setSpanType(SpanType.Exit);
                String peer = getPeer(parentSpan, span);
                if (peer != null) {
                    spanBuilder.setPeer(peer);
                }
                clientSideSpan = new ClientSideSpan(span, spanBuilder);
                clientPartSpan.put(span.id(), clientSideSpan);
                break;
            case SERVER:
                spanBuilder.setSpanType(SpanType.Entry);
                this.buildRef(spanBuilder, span, parentSegmentSpan, parentSpan);
                break;
            case CONSUMER:
                spanBuilder.setSpanType(SpanType.Entry);
                this.buildRef(spanBuilder, span, parentSegmentSpan, parentSpan);
                break;
            case PRODUCER:
                spanBuilder.setSpanType(SpanType.Exit);
                peer = getPeer(parentSpan, span);
                if (peer != null) {
                    spanBuilder.setPeer(peer);
                }
                clientSideSpan = new ClientSideSpan(span, spanBuilder);
                clientPartSpan.put(span.id(), clientSideSpan);
                break;
            default:
                spanBuilder.setSpanType(SpanType.Local);
        }

sample-tracing-1.txt

skywalking-ui-1 zipkin-server-ui-1

tommic81 avatar May 15 '19 08:05 tommic81

One client span is a parent of another client span? I definitely was expecting this happens. SkyWalking segments expect, exit span(client) always matches entry span(server), and for an RPC, only one exit and one entry.

wu-sheng avatar May 15 '19 09:05 wu-sheng

But how to handle a case when within application A we may have a couple of steps and each step (component) generate its own span and finally one of them will generate a http request to application B?

component A (app A) -> component B (app A) -> component C (app A) -> http GET -> component A (app B)

Is it possible possible to generate the correct relations and present a tree on Tracing tab (Gui)?

tommic81 avatar May 16 '19 12:05 tommic81

In the current analysis codes, I will say it is hard. Transfer zipkin span to SkyWalking segment has too many limits. That is why I submit the no-analysis mode.

In my mind, I prefer to build new analysis codes based on no-analysis mode, meaning, still saving span directly, and build the trace only in query stage. Becaust at that moment, no need to worry about client/server side spans, just build trace segment and segment ref. And only require client/server matching to do analysis, in your case, only try to identify these two spans(component C (app A) -> http GET -> component A (app B)), then metrics are generated by these two.

By the way, in SkyWalking native format and agent, we don't need to process this, we will merge component A->C(if they are all RPC client library instrumentations) automatically. We call it StackBasedSpan.

If you want to quick deep dive talk, Join #skywalking channel at Apache Slack

wu-sheng avatar May 16 '19 13:05 wu-sheng

Hi,

So basically you are suggesting, to switch off analyzing (needAnalysis=true) and of course to set up storage to zipkin-elasticsearch and to rely on results of org.apache.skywalking.oap.server.storage.plugin.zipkin.elasticsearch.ZipkinTraceQueryEsDAO?

This will work but in the same we are losing other extra features like Topology. Am I right?

tommic81 avatar May 17 '19 13:05 tommic81

This will work but in the same we are losing other extra features like Topology. Am I right?

Yes. That is the part we should build, to replace the current one. Are you interested in deep dive in this about how to generate topology and metrics based on Zipkin spans? I have basic ideas, but there are coding and testing stuff need to be done.

wu-sheng avatar May 17 '19 13:05 wu-sheng

Hi, I am interesting with this enhancement because i am working on the AMP service for our application, and it build up with internal framework which had zipkin reporter native code. Tell me if there are something i can help, and which is helping myself.

Duncan-tree-zhou avatar Jun 18 '19 01:06 Duncan-tree-zhou

@Duncan-tree-zhou I have list them in this issue. We could discuss more details if you have some questions.

wu-sheng avatar Jun 18 '19 01:06 wu-sheng

@wu-sheng here are my questions:

  1. how many ways we can solve this problem.
  • for my understanding, to compose and transform zipkin traces into skywalking segments is the way with least modification.
  • are there any other way to implement the enhancement?
  1. if we chose a way, how many functionalities we should implement to complete the integration.
  • let's say to transform the zipkin format to segments. We should implement a transformer. Is it enough to make work?
  1. what is the prolems and primary concerns ( in different dimension and details) to implement the functionalities?
  • let's say to implement the transformer. how may attrs zipkin format has and how may attrs sykwalking format has. how to map the attrs. Maybe we can draw a table to the maping and find out like which attrs are required but zipkin format not provided etc.

Duncan-tree-zhou avatar Jun 18 '19 02:06 Duncan-tree-zhou

for my understanding, to compose and transform zipkin traces into skywalking segments is the way with least modification.

We could save Zipkin trace by using span based, rather than segment of SkyWalking. I have implemented it, which is much friendly to Zipkin. Read this, https://github.com/apache/skywalking/blob/master/docs/en/setup/backend/backend-storage.md#elasticsearch-6-with-zipkin-trace-extension

The reason I proposed this, is Zipkin trace can't transfer to SkyWalking segments perfectly. That is why we put in the document, analysis is not production ready.

are there any other way to implement the enhancement?

The most important enhancement are analysis metrics from zipkin span. This means, match zipkin client-server span and generated SkyWalking scopes(Service, ServiceRelation, etc.), like SourceBuilder used by MultiScopesSpanListener.

let's say to transform the zipkin format to segments. We should implement a transformer. Is it enough to make work?

This may be not necessary.

what is the prolems and primary concerns ( in different dimension and details) to implement the functionalities?

I think mostly is in OAP cluster mode. Zipkin spans of a trace could be sent to the different instances in an uncertain time, so, we need to make client/server match perfectly. Such as using Redis Cluster to be central cache?(Maybe only)

wu-sheng avatar Jun 18 '19 02:06 wu-sheng

The most important enhancement are analysis metrics from zipkin span. This means, match zipkin client-server span and generated SkyWalking scopes(Service, ServiceRelation, etc.), like SourceBuilder used by MultiScopesSpanListener.

for my understanding, zipkin reporter did not collect metrics information(since zipkin did not support to collect metrics data). if you have no hand you can't make a fist. so i think maybe you can recomend users to use a metrics agent to collection the metrics data?

I think mostly is in OAP cluster mode. Zipkin spans of a trace could be sent to the different instances in an uncertain time, so, we need to make client/server match perfectly. Such as using Redis Cluster to be central cache?(Maybe only)

I am not understanding that if SW had save the zipkin spans in db(like es). why a central cache is needed? why the storage can't be the data central?

Duncan-tree-zhou avatar Jun 18 '19 14:06 Duncan-tree-zhou

And I am trying to implement the SW agents for components of our framework . They remake many wheels like the Driver/rpc/webdispatcher etc. It looks like that to implement agents is the easier way to work out. The Skywalking agent SDK is really very good.

Duncan-tree-zhou avatar Jun 18 '19 14:06 Duncan-tree-zhou

for my understanding, zipkin reporter did not collect metrics information(since zipkin did not support to collect metrics data). if you have no hand you can't make a fist. so i think maybe you can recomend users to use a metrics agent to collection the metrics data?

I mean analysis metrics from traces, like we did from SkyWalking traces. We just don't have JVM.

I am not understanding that if SW had save the zipkin spans in db(like es). why a central cache is needed? why the storage can't be the data central?

Same as above, I was talking about analysis metrics from Zipkin trace.

And I am trying to implement the SW agents for components of our framework . They remake many wheels like the Driver/rpc/webdispatcher etc. It looks like that to implement agents is the easier way to work out. The Skywalking agent SDK is really very good.

In most cases, I think agent plugin should be much better, and have better performance.

wu-sheng avatar Jun 18 '19 14:06 wu-sheng

I mean analysis metrics from traces, like we did from SkyWalking traces. We just don't have JVM.

Are there any articles or docs to discrip how Skywalking analysis the metrics of traces in cluster mode?

Duncan-tree-zhou avatar Jun 18 '19 15:06 Duncan-tree-zhou

Are there any articles or docs to discrip how Skywalking analysis the metrics of traces in cluster mode?

No, I am afraid. But in the short version, SkyWalking has special header and segment formats, very different with Zipkin span based. It is designed particularly for APM, rather than tracing. I think you can't learn from those about how to analysis Zipkin span. MultiScopesSpanListener to SourceBuilder is still the best refer. You need to analysis spans, and get all Scopes of SkyWalking, and send them OAL engine. This feature requires clear understanding of what is SkyWalking OAP and OAL scripts.

wu-sheng avatar Jun 18 '19 15:06 wu-sheng

Hi, I just came across this interesting issue, because we are hitting this problem when we are evaluating Skywalking for our production environment for the zipkin client.

I think the core problem is that, in the distributed OLA envirnoment, one single OLA needs to collect all the span information in order to calculate the segment informatoin. I have a draft work-around idea, and would like to discuss here.

Lets say, we put a Kafka broker in the middle of zipkin and skywalking OLA, and all span informaiton with the same traceid is routed to the same partitoin of the Kafka topic, and all the messages of one particular partition will be delivered to the same OLA node. Will this solution solve the problem in certain degree? Dear @wu-sheng, looking forward for your response. Thanks.

yangyshdan avatar Sep 23 '19 14:09 yangyshdan