This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix telemetry span not entering properly attempt 3 #8043
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
5c2f3dc
Fix tracing tests (#8022)
bkchr 094fee8
Fix tracing spans are not being forwarded to spawned task (#8009)
bkchr a443b5c
Proper test for telemetry and prefix span
cecton 5448b94
WIP
cecton f52d1ea
Fix test (need to create & enter the span at the same time)
cecton 09ef926
WIP
cecton 6f42906
Remove telemtry_span from sc_service config
cecton 1b8d945
CLEANUP
cecton c2e1e37
Merge commit 30ec0bedf7b902b10188e9da8650c688aad23e1f (no conflict)
cecton 4f7f326
Merge commit 017a9a06b44c191d98ab76ccd4e021aea2d16e79 (conflicts)
cecton 60c02ef
Update comment
cecton d1381de
Incorrect indent
cecton fd5cfbb
Merge commit 169b16f67509366e8a0ceaf8022ec791e4b2eea7 (no conflict)
cecton 95e4742
More meaningful name
cecton 3d7adba
Dedent
cecton 34008ec
Naming XD
cecton c94bdc6
Attempt to make a more complete test
cecton 4d023d5
Merge commit 6105169c51344d3c1344532e2b5831804a4c7abd (no conflict)
cecton 17b2010
Merge commit a675f9a1551770d45bab35bc20cfe5a2663721a0 (conflicts)
cecton e7dae73
Merge commit 22441aa4bc40200cbd98503e6f44769dd39f7031 (no conflict)
cecton 35fa4c3
lint
cecton e4544c3
Missing licenses
cecton 4315639
Remove user data
cecton 86870f0
CLEANUP
cecton b7538be
Apply suggestions from code review
cecton 6d4b06b
CLEANUP
cecton 5705955
Apply suggestion
cecton 51738dd
Update bin/node/cli/tests/telemetry.rs
cecton d57c361
Wrapping lines
cecton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) 2021 Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
|
||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| use assert_cmd::cargo::cargo_bin; | ||
| use nix::sys::signal::{kill, Signal::SIGINT}; | ||
| use nix::unistd::Pid; | ||
| use std::convert::TryInto; | ||
| use std::process; | ||
|
|
||
| pub mod common; | ||
| pub mod websocket_server; | ||
|
|
||
| #[async_std::test] | ||
| async fn telemetry_works() { | ||
| let config = websocket_server::Config { | ||
| capacity: 1, | ||
| max_frame_size: 1048 * 1024, | ||
| send_buffer_len: 32, | ||
| bind_address: "127.0.0.1:0".parse().unwrap(), | ||
| }; | ||
| let mut server = websocket_server::WsServer::new(config).await.unwrap(); | ||
|
|
||
| let addr = server.local_addr().unwrap(); | ||
|
|
||
| let server_task = async_std::task::spawn(async move { | ||
| loop { | ||
| use websocket_server::Event; | ||
| match server.next_event().await { | ||
| // New connection on the listener. | ||
| Event::ConnectionOpen { address } => { | ||
| println!("New connection from {:?}", address); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this useful or should it be removed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be useful when debugging. I personally used it for that purpose. But again it doesn't show up unless the test fails and it's an indicator. |
||
| server.accept(); | ||
| } | ||
|
|
||
| // Received a message from a connection. | ||
| Event::BinaryFrame { message, .. } => { | ||
| let json: serde_json::Value = serde_json::from_slice(&message).unwrap(); | ||
| let object = json | ||
| .as_object() | ||
| .unwrap() | ||
| .get("payload") | ||
| .unwrap() | ||
| .as_object() | ||
| .unwrap(); | ||
| if matches!(object.get("best"), Some(serde_json::Value::String(_))) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| Event::TextFrame { .. } => panic!("Got a TextFrame over the socket, this is a bug"), | ||
|
|
||
| // Connection has been closed. | ||
| Event::ConnectionError { .. } => {} | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| let mut substrate = process::Command::new(cargo_bin("substrate")); | ||
|
|
||
| let mut substrate = substrate | ||
| .args(&["--dev", "--tmp", "--telemetry-url"]) | ||
| .arg(format!("ws://{} 10", addr)) | ||
| .stdout(process::Stdio::piped()) | ||
| .stderr(process::Stdio::piped()) | ||
| .stdin(process::Stdio::null()) | ||
| .spawn() | ||
| .unwrap(); | ||
|
|
||
| server_task.await; | ||
|
|
||
| assert!( | ||
| substrate.try_wait().unwrap().is_none(), | ||
| "the process should still be running" | ||
| ); | ||
|
|
||
| // Stop the process | ||
| kill(Pid::from_raw(substrate.id().try_into().unwrap()), SIGINT).unwrap(); | ||
| assert!(common::wait_for(&mut substrate, 40) | ||
| .map(|x| x.success()) | ||
| .unwrap_or_default()); | ||
|
|
||
| let output = substrate.wait_with_output().unwrap(); | ||
|
|
||
| println!("{}", String::from_utf8(output.stdout).unwrap()); | ||
| eprintln!("{}", String::from_utf8(output.stderr).unwrap()); | ||
cecton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert!(output.status.success()); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you have written a macro for creating async tests in the Substrate context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in general I don't understand why we use
async-stdhere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check that tomorrow 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit complicated with all the
compatstuff. I couldn't change it easily and it adds more dependency (tokio-util):I think that's good enough for now if that's okay for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you educate me on what the tokio situation is in substrate atm? Is the following correct:
libp2pis executor agnostic (but uses tokio 1.0 in examples/tests), other async subsystems use … tokio 0.2, andjsonrpcis stuck on tokio 0.1. And now we addasync-stdhere (or is it already used in other tests too)?If the above is correct we clearly have some tech debt to pay off here. :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have:
I don't personally mind having multiple different executors in different crates if it is for tests. It's just a dev dependency, it doesn't impact the user. Compiling both isn't a big issue either. 🤷♀️