Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the ability to import traces from JSON into zipkin-ui #1884

Closed
wants to merge 2 commits into from
Closed

Adding the ability to import traces from JSON into zipkin-ui #1884

wants to merge 2 commits into from

Conversation

Logic-32
Copy link
Contributor

I got tired of having no way to view previous traces in Zipkin. Since it provides a way to download the trace JSON I figured there should be a way to add it back. This adds a new link with the ability to select a JSON file for upload (as opposed to copy/paste due to the potential size of traces, ref: #1460) and view it just like any other trace.

Relates to: #1747.

@codefromthecrypt
Copy link
Member

interesting! for a impl summary, is the trace in browser local storage or is it sortof a one-shot deal? Can you attach screen shots? Is there anything sharable between traceViewer.mustache and anything else?

@Logic-32
Copy link
Contributor Author

Logic-32 commented Jan 16, 2018

  1. It's a one shot deal. You refresh the page and you have to browse for the file again.
  2. Attaching.
  3. traceViewer.mustache is trace.mustache with just a couple of small changes. I did a horrible job committing it (it should've been a copy). If you have a good reference for how I can share more between the two, accounting for the small changes, I'd be happy to refactor a bit.

traceimport-browse
traceimport-view

Edit: updated images to reflect new link name.

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Jan 16, 2018 via email

@Logic-32
Copy link
Contributor Author

You da boss! Say the words and I will make the change :)

@codefromthecrypt
Copy link
Member

some dangling concerns are that the UI doesn't natively speak v2 yet, so however worded, this implies the data is in v1 format.

The v2 format is in zipkin-js.. I wonder if there's a way we can leverage that to allow pasting of v2. If we have this feature, it should work with new data.

PS still need others feedback cc @openzipkin/core

@Logic-32 Logic-32 closed this Jan 17, 2018
@Logic-32
Copy link
Contributor Author

Logic-32 commented Jan 17, 2018

So, I just realized I messed up the commit a bit (new to and hating git, sorry). So bear with me for a bit while I try to correct things.

Edit: Corrected but in 2 commits this time :\

Also, I do agree this should work with v2 data. But at the moment I'm not sure where zipkin-js is or how to update it to work with v2 data. I'd be happy to help with what I can given the right direction but for now I'll wait for the feedback from others.

@Logic-32 Logic-32 reopened this Jan 17, 2018
reader.onload = evt => {
let model;
try {
const trace = JSON.parse(evt.target.result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here, we should assume zipkin v2 format unless we know heuristically it is not. Worst case we can copy/paste a modified version of https://github.com/openzipkin/zipkin-js/blob/master/packages/zipkin/src/jsonEncoder.js#L25 to map v2 json to v1 format. Ex here are the tests for that: https://github.com/openzipkin/zipkin-js/blob/master/packages/zipkin/test/jsonEncoder.JSON_V1.test.js

Reason is that it is only time resource which is why the UI isn't internally rewritten to v2 yet. I don't want to encourage people to keep using v1. The best heuristic to detect if incoming json is v2 or not is presence of the "localEndpoint" field, which is only absent on instrumentation error.

Copy link
Contributor Author

@Logic-32 Logic-32 Jan 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting that we iterate through the spans in trace, see if they have a 'localEndpoint', and if they do, then call jsonEncoder.encodeV1() (effectively) on each span so that the UI can display both v1 and v2 traces?

I'm midly afraid that v2 traces with 10k spans will suffer a bit from that. But that concern aside, is there an easy way to extract jsonEncoder without having to copy/paste it into zipkin-ui? Of course, I'm talking about extracting/sharing the conversion more so than the call to JSON.stringify() at the end.

I think here, we should assume zipkin v2 format unless we know heuristically it is not.

Given that the UI will only show you traces in v1 format I think it is safer to assume v1 until zipkin-ui is updated to support v2. But that doesn't mean we can't still support v2 pending the above discussion.

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Jan 19, 2018 via email

@eirslett
Copy link
Contributor

Looping through 10k elements in JS is still quicker than touching the DOM, I don't think it will be a problem. (But don't take my word for it, might be a good idea to profile it.) I would be concerned if it took more than 30ms.

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Jan 19, 2018 via email

@Logic-32
Copy link
Contributor Author

Haha if you have a trace with 9k spans you will have other problems.

Lol. Perhaps. But it is an unfortunate fact of life in the system I work on. It's not really all that common but I deal with the worst-of-the-worst so I have the unfortunate pleasure of seeing it daily :'(

Looping through 10k elements in JS is still quicker than touching the DOM, I don't think it will be a problem. (But don't take my word for it, might be a good idea to profile it.) I would be concerned if it took more than 30ms.

Touche! My head must be in the clouds right now :)

Could copy/paste with a comment or add a dependency on zipkin-js and use
the functions directly.

Will start with copy/paste and update the pull request when I can. No promise on ETA given work priorities and such :\

@Logic-32
Copy link
Contributor Author

Logic-32 commented Jan 31, 2018

Back to working on this.

Is there anything sharable between traceViewer.mustache and anything else?

Just found out that with partials I can.
Ref:

Also, I renamed "Import A Trace" to "View Saved Trace". I added some missing i18n properties as well. No translations, just the properties and default values. Hopefully that doesn't mess with the foreign languages too much :\

Reference pictures in prior post updated to reflect these changes.

(commit to follow...)

nav.search = Go to trace
nav.viewSaved = View Saved Trace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrGlaucus @gianarb @drolando can you contribute chinese and italian text for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will work on the translation as the merge is done.

@drolando
Copy link
Contributor

drolando commented Feb 3, 2018

Isn't the JSON returned by the UI valid V2 format? Couldn't you simply POST it back to /api/v2/spans and use the UI as usual?

@codefromthecrypt
Copy link
Member

@drolando right now the UI doesn't mount any write endpoints, and search etc is limited by original timestamp. to change to mount write endpoints might interfere with some folks assumptions about the security of their UI (right now, if you cut at /zipkin/* there's no way to poison or otherwise trace data). There is a different change that wasn't universally popular about writing to a separate storage service #1747.

On the technical bits, the v2 conversion etc code will end up replacing the v1 code in the project, so some of this is temporary technical debt.

hope this background is useful

@Logic-32
Copy link
Contributor Author

Logic-32 commented Feb 6, 2018

@drolando, in addition to what Adrian said, where I work we have a habit of attaching trace JSON to bug cases as output via the JSON button in the UI. Without this feature, or some other tool to import the JSON, the trace JSON is pretty useless. We have no desire to actually re-persist the JSON since our ES cluster is already pretty full of Zipkin data. So this makes for a nice on-the-fly viewing of data with no storage overhead.

@adriancole, any updates on feedback from the core team?

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Feb 7, 2018 via email

@@ -21,6 +22,7 @@ loadConfig().then(config => {

crossroads.addRoute(contextRoot, () => initializeDefault(config));
crossroads.addRoute(`${contextRoot}traces/{id}`, traceId => initializeTrace(traceId, config));
crossroads.addRoute('zipkin/traceViewer', () => initializeTraceViewer(config));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be using the contextRoot variable? (if not, those proxy-mounting zipkin will be broken I think.. look at the README for more)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops! My bad. Will fix.

@codefromthecrypt
Copy link
Member

@Logic-32 can you look at the test dir and see if you can make a similar test for anything that's new here (possibly for the conversion part, copy some test code from zipkin-js). This is a lot of new code and having at least some coverage will help if there's a bug we need to sort out later

@codefromthecrypt
Copy link
Member

PS the UI still says "view a saved trace" which is confusing as data in zipkin is saved.

I wonder if the upload functionality should be a widget next to "go to trace" Ex instead of going to a trace by ID, we are going to an offline trace (by choosing the file). Regardless, I feel a bit off about the json viewer being mixed in with server side stuff like dependencies, as it is offline..

One way is to change "go to trace" to "enter trace ID" and put another widget directly under that says "choose trace json"

I tried the functionality and notice I can't collapse any of the spans (even clicking expand-all collapse-all). Might want to check that.

@Logic-32
Copy link
Contributor Author

Logic-32 commented Feb 8, 2018

the UI still says "view a saved trace" which is confusing as data in zipkin is saved.

That's because I changed it from "Import a Trace" ;)

I wonder if the upload functionality should be a widget next to "go to trace"

Maybe? It could certainly clear up the verbiage issue we're having. I attached a rough mockup below of what it would look like (in IE). Having it below the "go to trace" box isn't really practical as I don't think Bootstrap navs support multi-row very well (at least, I've never seen one). Either way, I can't say it looks very clean. It's not immediately obvious which textbox should be used for what purpose without some descriptive text around the file input. Additionally, there are some workflow complications with doing it that way. After selecting the file we'd have to change the URL to remove any reference to current state. Otherwise somebody may try to copy/paste it and expect the same results. Which won't happen. We can use JS to fix the URL but we have to be careful with history management so the back/forward buttons work as expected.

So the short version is that I believe a dedicated page for viewing the traces is the simplest way to do it. But I'm not sure how to disambiguate the online from offline stuff like you're concerned about. We can consider a multi-level nav but that means extra clicks to get to a page. With as simple as the UI is at the moment I don't think that's appropriate either.

mock-ie

I tried the functionality and notice I can't collapse any of the spans (even clicking expand-all collapse-all). Might want to check that.

Works on my box in Zipkin 2.4.6 with this change applied. Tried IE, FF, and Chrome. Behaves identically to normal/stored traces. Did those work for you? Which version/branch were you using?

p.s. Will try to find a test to add when I can.

@Logic-32
Copy link
Contributor Author

Just got tests added for the span conversion stuff. Unfortunately there is a somewhat higher level bug that may make them moot.

Currently, the /zipkin/v1/trace/{traceIdHex} has an optional query parameter to dump raw traces. From what I can tell, getting that dump avoids some timestamp adjustments and sorting that a non-raw dump would do. Unfortunately, it seems like /zipkin/v2/trace/{traceIdHex} defaults to the same /v1 raw behavior. Now, it's unfortunate because the UI doesn't like it when the initial/root span isn't the first in the list of spans. It actually fails quite miserably when that's the case. Additionally, the lack of timestamp adjustments can cause spans to render in odd places on the timeline. Is this something that would hold up this feature? If so, I have no idea how I'd handle the situation at the moment.

For reference:

  • We just deployed Zipkin 2.4.2 to our production servers so I was using it as my test case
  • I dumped a normal v1 trace, a raw one, and a v2 trace for comparison
  • The normal v1 trace rendered properly, neither of the latter did
  • The raw v1 trace and v2 trace rendered identically after moving the root span up to be the first span

p.s. How does "View Local Trace" sound?

@codefromthecrypt
Copy link
Member

Thanks for the update and all the hard work @Logic-32.

yes, we decided that in v2 it would be best to move the adjustment logic to javascript in the UI (which makes a fake root span etc), just this hasn't been done. I forgot about this.

The key part is this logic (around sorting the trace by the root span) https://github.com/openzipkin/zipkin/blob/master/zipkin/src/main/java/zipkin/internal/ApplyTimestampAndDuration.java

There is also clock skew logic, which would might be something we can punt slightly.
https://github.com/openzipkin/zipkin/blob/master/zipkin/src/main/java/zipkin/internal/CorrectForClockSkew.java

@Logic-32
Copy link
Contributor Author

Happy to help @adriancole :) However, I'm not sure I'm up for porting those changes over. I know Java/JS well enough but it's a lot of testing/etc... and some other priorities have come up for me. Is it a requirement to have those working before the change can be merged? If so, what other options do we have?

At a minimum, I could probably implement a sort routine to at least make sure the root span is first in the list. That's about all I'd have time for. And if I did that, would you want me to do it for raw v1 traces as well?

@codefromthecrypt
Copy link
Member

@Logic-32 thanks for being transparent about what you can budget attention for. It has been a great help so far. I think that the sort-based thing should happen after any potential conversion to v1 and before the existing logic is invoked. What I mean is that I'd solve order for v1 raw (which should transitively solve for v2). Limit to sorting and then we'll open an issue to progress further. Sound good?

@Logic-32
Copy link
Contributor Author

Sounds good to me! Will update when I can.

@codefromthecrypt
Copy link
Member

another release will be on the way soon. any chance this might be ready?

@Logic-32
Copy link
Contributor Author

Logic-32 commented Mar 12, 2018

Was able to look at sorting a little bit last week. Going to try and polish/commit today :)

Edit: done.

… navbar to accomodate new link.

Adding configuration to forward requests to traceViewer

Updated traceViewer to support v2 traces by recoding in v1 format.  Add error handling in case JSON parsing fails.  Renamed feature to 'View Saved Trace'.  Added il8n properties.

Extracted span conversion into it's own file so it could be tested more easily.  Fixed missing 'contextPath' issue.
@codefromthecrypt
Copy link
Member

testing now

@codefromthecrypt
Copy link
Member

I will test this with normal span. then merge and add code for messaging span. Good stuff!

@codefromthecrypt
Copy link
Member

there's some interesting offset rendering I'm looking into..

@codefromthecrypt
Copy link
Member

for example, the UI is misaligned unless you stretch the screen carefully

screen shot 2018-03-15 at 12 13 36 pm

screen shot 2018-03-15 at 12 13 45 pm

@codefromthecrypt
Copy link
Member

screen shot 2018-03-15 at 4 47 00 pm

Looks like the left positioning is present on trace viewer but not the normal trace screen

@codefromthecrypt
Copy link
Member

getting somewhere now..

@codefromthecrypt
Copy link
Member

ok it is because when we switch to v1 format we aren't merging by ID like the v1 api does.

screen shot 2018-03-15 at 5 08 06 pm

@codefromthecrypt
Copy link
Member

ok since this is on your master branch, I'm not going to push a commit to it. I'll make a commit to fix the merging thing and squash yours into it on the way in. will finish up tonight. Thanks for the help!

@Logic-32
Copy link
Contributor Author

To make sure I understand correctly:

  1. You're trace is in v2 format and there is an issue converting to v1.
  2. You're going to essentially merge this request while simultaneously fixing the bug?
  3. Sorry for this being on my master branch. Still new to git and didn't think about that. I'm honestly going to delete the repo once it gets merged though so feel free to do whatever :)
    • Deleting the repo so I can start fresh/branch properly if I make more changes.
  4. You're welcome, and thank you!

codefromthecrypt pushed a commit that referenced this pull request Mar 16, 2018
This is an alternative to saving on the backend or via a proxy

Closes #1747
@codefromthecrypt
Copy link
Member

Thanks @Logic-32 I squashed yours and added 355a96f for the merge thing (as without it the UI was weird). will make follow-up now for messaging spans

@Logic-32
Copy link
Contributor Author

Awesome! Thank you for fixing up that merging issue for me :)

abesto pushed a commit to abesto/zipkin that referenced this pull request Sep 10, 2019
This is an alternative to saving on the backend or via a proxy

Closes openzipkin#1747
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants