made tutorial outputs more presentable (#555)

Closes https://github.com/ooni/probe/issues/1831
This commit is contained in:
Srijan Srivastava 2021-10-22 19:47:57 +05:30 committed by GitHub
parent a9319142f3
commit 3f0da81bf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 59 additions and 57 deletions

View File

@ -190,9 +190,10 @@ Let us run the program with default arguments first. You can do
this operation by running:
```bash
go run -race ./internal/tutorial/measurex/chapter01
go run -race ./internal/tutorial/measurex/chapter01 | jq
```
Where `jq` is being used to make the output more presentable.
If you do that you obtain some logging messages, which are out of
the scope of this tutorial, and the following JSON:
@ -257,7 +258,7 @@ Let us now change the domain to resolve to be `antani.ooni.org` (a
nonexisting domain), which we can do by running this command:
```bash
go run -race ./internal/tutorial/measurex/chapter01 -domain antani.ooni.org
go run -race ./internal/tutorial/measurex/chapter01 -domain antani.ooni.org | jq
```
This is the output JSON:
@ -318,7 +319,7 @@ top of which `measurex` is written.)
Let us now try with an insanely low timeout:
```bash
go run -race ./internal/tutorial/measurex/chapter01 -timeout 250us
go run -race ./internal/tutorial/measurex/chapter01 -timeout 250us | jq
```
To get this JSON:

View File

@ -191,9 +191,10 @@ func main() {
// this operation by running:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter01
// go run -race ./internal/tutorial/measurex/chapter01 | jq
// ```
//
// Where `jq` is being used to make the output more presentable.
// If you do that you obtain some logging messages, which are out of
// the scope of this tutorial, and the following JSON:
//
@ -258,7 +259,7 @@ func main() {
// nonexisting domain), which we can do by running this command:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter01 -domain antani.ooni.org
// go run -race ./internal/tutorial/measurex/chapter01 -domain antani.ooni.org | jq
// ```
//
// This is the output JSON:
@ -319,7 +320,7 @@ func main() {
// Let us now try with an insanely low timeout:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter01 -timeout 250us
// go run -race ./internal/tutorial/measurex/chapter01 -timeout 250us | jq
// ```
//
// To get this JSON:

View File

@ -85,7 +85,7 @@ Let us run the program with default arguments first. You can do
this operation by running:
```bash
go run -race ./internal/tutorial/measurex/chapter02
go run -race ./internal/tutorial/measurex/chapter02 | jq
```
Here is the JSON we obtain in output:
@ -129,7 +129,7 @@ Let us now see if we can provoke some errors and timeouts.
Let us start with an IP address where there's no listening socket:
```bash
go run -race ./internal/tutorial/measurex/chapter02 -address 127.0.0.1:1
go run -race ./internal/tutorial/measurex/chapter02 -address 127.0.0.1:1 | jq
```
We get this JSON:
@ -161,7 +161,7 @@ the oddity that classifies the error.
Let us now try to obtain a timeout:
```bash
go run -race ./internal/tutorial/measurex/chapter02 -address 8.8.4.4:1
go run -race ./internal/tutorial/measurex/chapter02 -address 8.8.4.4:1 | jq
```
We get this JSON:
@ -192,7 +192,7 @@ precise than just the error alone.
Let us now use a very small timeout:
```bash
go run -race ./internal/tutorial/measurex/chapter02 -address 8.8.4.4:1 -timeout 100ms
go run -race ./internal/tutorial/measurex/chapter02 -address 8.8.4.4:1 -timeout 100ms | jq
```
To get this JSON:

View File

@ -86,7 +86,7 @@ func main() {
// this operation by running:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter02
// go run -race ./internal/tutorial/measurex/chapter02 | jq
// ```
//
// Here is the JSON we obtain in output:
@ -130,7 +130,7 @@ func main() {
// Let us start with an IP address where there's no listening socket:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter02 -address 127.0.0.1:1
// go run -race ./internal/tutorial/measurex/chapter02 -address 127.0.0.1:1 | jq
// ```
//
// We get this JSON:
@ -162,7 +162,7 @@ func main() {
// Let us now try to obtain a timeout:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter02 -address 8.8.4.4:1
// go run -race ./internal/tutorial/measurex/chapter02 -address 8.8.4.4:1 | jq
// ```
//
// We get this JSON:
@ -193,7 +193,7 @@ func main() {
// Let us now use a very small timeout:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter02 -address 8.8.4.4:1 -timeout 100ms
// go run -race ./internal/tutorial/measurex/chapter02 -address 8.8.4.4:1 -timeout 100ms | jq
// ```
//
// To get this JSON:

View File

@ -69,7 +69,7 @@ we print using the usual three-liner.
As before, let us start off with a vanilla run:
```bash
go run -race ./internal/tutorial/measurex/chapter03
go run -race ./internal/tutorial/measurex/chapter03 | jq
```
This time we get a much larger JSON, so I will pretend it is
@ -246,7 +246,7 @@ output JSON changes because of them.
Let us try to get a NXDOMAIN error.
```bash
go run -race ./internal/tutorial/measurex/chapter03 -query antani.ooni.org
go run -race ./internal/tutorial/measurex/chapter03 -query antani.ooni.org | jq
```
This produces the following JSON:
@ -443,7 +443,7 @@ Let us now try to get a REFUSED DNS Rcode, again from servers
that are, let's say, kind enough to easily help.
```bash
go run -race ./internal/tutorial/measurex/chapter03 -address 180.97.36.63:53
go run -race ./internal/tutorial/measurex/chapter03 -address 180.97.36.63:53 | jq
```
Here's the answer I get:

View File

@ -70,7 +70,7 @@ func main() {
// As before, let us start off with a vanilla run:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter03
// go run -race ./internal/tutorial/measurex/chapter03 | jq
// ```
//
// This time we get a much larger JSON, so I will pretend it is
@ -247,7 +247,7 @@ func main() {
// Let us try to get a NXDOMAIN error.
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter03 -query antani.ooni.org
// go run -race ./internal/tutorial/measurex/chapter03 -query antani.ooni.org | jq
// ```
//
// This produces the following JSON:
@ -444,7 +444,7 @@ func main() {
// that are, let's say, kind enough to easily help.
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter03 -address 180.97.36.63:53
// go run -race ./internal/tutorial/measurex/chapter03 -address 180.97.36.63:53 | jq
// ```
//
// Here's the answer I get:

View File

@ -80,7 +80,7 @@ the measurement itself, which we print below.
As before, let us start off with a vanilla run:
```bash
go run -race ./internal/tutorial/measurex/chapter04
go run -race ./internal/tutorial/measurex/chapter04 | jq
```
Let us comment the JSON in detail:
@ -209,13 +209,13 @@ changes in different error conditions.
Here are the commands I used for each proposed exercise:
1. go run -race ./internal/tutorial/measurex/chapter04 -address 8.8.4.4:1
1. go run -race ./internal/tutorial/measurex/chapter04 -address 8.8.4.4:1 | jq
2. go run -race ./internal/tutorial/measurex/chapter04 -sni example.org
2. go run -race ./internal/tutorial/measurex/chapter04 -sni example.org | jq
3. go run -race ./internal/tutorial/measurex/chapter04 -address 104.154.89.105:443 -sni self-signed.badssl.com
3. go run -race ./internal/tutorial/measurex/chapter04 -address 104.154.89.105:443 -sni self-signed.badssl.com | jq
4. go run -race ./internal/tutorial/measurex/chapter04 -address 104.154.89.105:443 -sni expire.badssl.com
4. go run -race ./internal/tutorial/measurex/chapter04 -address 104.154.89.105:443 -sni expire.badssl.com | jq
To emulate the last two scenarios, if you're on Linux, a
possibility is building Jafar with this command:

View File

@ -81,7 +81,7 @@ func main() {
// As before, let us start off with a vanilla run:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter04
// go run -race ./internal/tutorial/measurex/chapter04 | jq
// ```
//
// Let us comment the JSON in detail:
@ -210,13 +210,13 @@ func main() {
//
// Here are the commands I used for each proposed exercise:
//
// 1. go run -race ./internal/tutorial/measurex/chapter04 -address 8.8.4.4:1
// 1. go run -race ./internal/tutorial/measurex/chapter04 -address 8.8.4.4:1 | jq
//
// 2. go run -race ./internal/tutorial/measurex/chapter04 -sni example.org
// 2. go run -race ./internal/tutorial/measurex/chapter04 -sni example.org | jq
//
// 3. go run -race ./internal/tutorial/measurex/chapter04 -address 104.154.89.105:443 -sni self-signed.badssl.com
// 3. go run -race ./internal/tutorial/measurex/chapter04 -address 104.154.89.105:443 -sni self-signed.badssl.com | jq
//
// 4. go run -race ./internal/tutorial/measurex/chapter04 -address 104.154.89.105:443 -sni expire.badssl.com
// 4. go run -race ./internal/tutorial/measurex/chapter04 -address 104.154.89.105:443 -sni expire.badssl.com | jq
//
// To emulate the last two scenarios, if you're on Linux, a
// possibility is building Jafar with this command:

View File

@ -81,7 +81,7 @@ lines of code for printing the resulting measurement.
As before, let us start off with a vanilla run:
```bash
go run -race ./internal/tutorial/measurex/chapter05
go run -race ./internal/tutorial/measurex/chapter05 | jq
```
Produces this JSON:

View File

@ -82,7 +82,7 @@ func main() {
// As before, let us start off with a vanilla run:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter05
// go run -race ./internal/tutorial/measurex/chapter05 | jq
// ```
//
// Produces this JSON:

View File

@ -458,19 +458,19 @@ Here are some suggestions for follow up measurements:
1. provoke a connect error by using:
```
go run -race ./internal/tutorial/measurex/chapter06 -address 127.0.0.1:1
go run -race ./internal/tutorial/measurex/chapter06 -address 127.0.0.1:1 | jq
```
2. provoke a TLS handshake error by using:
```
go run -race ./internal/tutorial/measurex/chapter06 -sni example.com
go run -race ./internal/tutorial/measurex/chapter06 -sni example.com | jq
```
3. provoke an HTTP round trip error by using:
```
go run -race ./internal/tutorial/measurex/chapter06 -address 8.8.8.8:853
go run -race ./internal/tutorial/measurex/chapter06 -address 8.8.8.8:853 | jq
```
4. modify the code to fetch an HTTP endpoint instead (hint: you

View File

@ -459,19 +459,19 @@ func main() {
// 1. provoke a connect error by using:
//
// ```
// go run -race ./internal/tutorial/measurex/chapter06 -address 127.0.0.1:1
// go run -race ./internal/tutorial/measurex/chapter06 -address 127.0.0.1:1 | jq
// ```
//
// 2. provoke a TLS handshake error by using:
//
// ```
// go run -race ./internal/tutorial/measurex/chapter06 -sni example.com
// go run -race ./internal/tutorial/measurex/chapter06 -sni example.com | jq
// ```
//
// 3. provoke an HTTP round trip error by using:
//
// ```
// go run -race ./internal/tutorial/measurex/chapter06 -address 8.8.8.8:853
// go run -race ./internal/tutorial/measurex/chapter06 -address 8.8.8.8:853 | jq
// ```
//
// 4. modify the code to fetch an HTTP endpoint instead (hint: you

View File

@ -124,7 +124,7 @@ Finally, we print the results.
Let us perform a vanilla run first:
```bash
go run -race ./internal/tutorial/measurex/chapter07
go run -race ./internal/tutorial/measurex/chapter07 | jq
```
Please, check the JSON output. Do you recognize the fields

View File

@ -125,7 +125,7 @@ func main() {
// Let us perform a vanilla run first:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter07
// go run -race ./internal/tutorial/measurex/chapter07 | jq
// ```
//
// Please, check the JSON output. Do you recognize the fields

View File

@ -111,7 +111,7 @@ This is it. The rest of the program is exactly the same.
Let us perform a vanilla run first:
```bash
go run -race ./internal/tutorial/measurex/chapter08
go run -race ./internal/tutorial/measurex/chapter08 | jq
```
Please, check the JSON output. Do you recognize the fields

View File

@ -112,7 +112,7 @@ func main() {
// Let us perform a vanilla run first:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter08
// go run -race ./internal/tutorial/measurex/chapter08 | jq
// ```
//
// Please, check the JSON output. Do you recognize the fields

View File

@ -112,7 +112,7 @@ our `m` container and we print it.
Let us perform a vanilla run first:
```bash
go run -race ./internal/tutorial/measurex/chapter09
go run -race ./internal/tutorial/measurex/chapter09 | jq
```
Take a look at the JSON output. Can you spot that

View File

@ -113,7 +113,7 @@ func main() {
// Let us perform a vanilla run first:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter09
// go run -race ./internal/tutorial/measurex/chapter09 | jq
// ```
//
// Take a look at the JSON output. Can you spot that

View File

@ -115,7 +115,7 @@ The rest of the program is exactly like in chapter09.
Let us perform a vanilla run first:
```bash
go run -race ./internal/tutorial/measurex/chapter10
go run -race ./internal/tutorial/measurex/chapter10 | jq
```
Take a look at the JSON output. Can you spot that

View File

@ -116,7 +116,7 @@ func main() {
// Let us perform a vanilla run first:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter10
// go run -race ./internal/tutorial/measurex/chapter10 | jq
// ```
//
// Take a look at the JSON output. Can you spot that

View File

@ -95,13 +95,13 @@ here on `main` using the `PanicOnError` function.
Let us perform a vanilla run first:
```bash
go run -race ./internal/tutorial/measurex/chapter11
go run -race ./internal/tutorial/measurex/chapter11 | jq
```
Take a look at the JSON output and compare it with:
```bash
go run -race ./internal/tutorial/measurex/chapter10 -url https://www.google.com
go run -race ./internal/tutorial/measurex/chapter10 -url https://www.google.com | jq
```
(which is basically forcing chapter10 to run with the
@ -114,7 +114,7 @@ and compare it to the code written in chapter10?
Now run:
```bash
go run -race ./internal/tutorial/measurex/chapter11 -url https://google.com
go run -race ./internal/tutorial/measurex/chapter11 -url https://google.com | jq
```
Do you see the opportunity there for following redirections? :^).

View File

@ -96,13 +96,13 @@ func main() {
// Let us perform a vanilla run first:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter11
// go run -race ./internal/tutorial/measurex/chapter11 | jq
// ```
//
// Take a look at the JSON output and compare it with:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter10 -url https://www.google.com
// go run -race ./internal/tutorial/measurex/chapter10 -url https://www.google.com | jq
// ```
//
// (which is basically forcing chapter10 to run with the
@ -115,7 +115,7 @@ func main() {
// Now run:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter11 -url https://google.com
// go run -race ./internal/tutorial/measurex/chapter11 -url https://google.com | jq
// ```
//
// Do you see the opportunity there for following redirections? :^).

View File

@ -79,7 +79,7 @@ is closed when done by `MeasureURLAndFollowRedirections`, so we leave the loop.
Let us perform a vanilla run first:
```bash
go run -race ./internal/tutorial/measurex/chapter12
go run -race ./internal/tutorial/measurex/chapter12 | jq
```
Take a look at the JSON. You should see several redirects

View File

@ -80,7 +80,7 @@ func main() {
// Let us perform a vanilla run first:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter12
// go run -race ./internal/tutorial/measurex/chapter12 | jq
// ```
//
// Take a look at the JSON. You should see several redirects

View File

@ -250,7 +250,7 @@ func main() {
Let us perform a vanilla run first:
```bash
go run -race ./internal/tutorial/measurex/chapter14
go run -race ./internal/tutorial/measurex/chapter14 | jq
```
Take a look at the JSON.

View File

@ -251,7 +251,7 @@ func main() {
// Let us perform a vanilla run first:
//
// ```bash
// go run -race ./internal/tutorial/measurex/chapter14
// go run -race ./internal/tutorial/measurex/chapter14 | jq
// ```
//
// Take a look at the JSON.