ooni / probe-engine

Semi-automatic export of https://github.com/ooni/probe-cli internals
https://ooni.org
GNU General Public License v3.0
45 stars 16 forks source link

Uniform bytes measurements and accounting #125

Closed bassosimone closed 4 years ago

bassosimone commented 4 years ago

In #118 we're measuring the bytes consumed by Telegram, but we're not measuring the bytes consumed by contacting OONI services. We should actually do that, because the original MK implementation was doing that, thus we need to have feature parity.

bassosimone commented 4 years ago

Before we can do this now, we need to finish converting the code to netx. Moving to Sprint 7.

bassosimone commented 4 years ago

Done in https://github.com/ooni/probe-engine/pull/418

bassosimone commented 4 years ago

We also need to do some work in probe-cli, reopening

bassosimone commented 4 years ago

I realized, in particular, that we're not correctly measuring the bytes in probe-cli. We're missing in particular the bytes used for submitting the report. As discussed with @hellais in chat, we don't want to include in this number of bytes interactions that don't pertain the experiment itself (e.g. downloading the assets). We're going to open an issue to track whether we want to report to the user the total amount of bytes consumed by using OONI (including downloading assets).

bassosimone commented 4 years ago

Here's the issue for tracking counting all the bytes consumed: https://github.com/ooni/probe/issues/1069

bassosimone commented 4 years ago

This issue ended up being much more complicated than intended. It turns out the design of netx was (1) already rather complicated and (2) did not allow easily to independently count bytes for the experiment and for the session. Because I recognized the importance of reducing the complexity of netx due to both (1) and (2), I spent time designing how to simplify netx rather than working on this issue in this sprint. As part of that, it seems I was able to improve the design significantly (https://github.com/ooni/probe-engine/issues/359) and also to solve the problem at hand (https://github.com/ooni/probe-engine/pull/421/commits/5dbf679ba0b0798148d06c7a9c52837042a7c3dc).

bassosimone commented 4 years ago

The detailed plan for implementing this feature in Sprint 10 is the following:

Note that, when all the above is done, measuring all bytes consumed by a probe (i.e. https://github.com/ooni/probe/issues/1069) is also mostly done. A probe that is using Go code will then have a way to obtain all the bytes consumed within a session. To enable a mobile probe to get this information we need this final step:

However, even after we have done that, we're still left with one more problem. We now have two conflicting ways of counting bytes, namely this context based way and experiment callbacks. Hence, to really get to the bottom of this issue we should further do the following:

I am thus going to close https://github.com/ooni/probe-engine/issues/416 and https://github.com/ooni/probe-engine/issues/417, and I am thus going to update the title of this issue accordingly.

Finally:

bassosimone commented 4 years ago

So, I hit another blocker: the connection to ps.ooni.io is persistent and is created by the session, therefore we cannot observe the bytes that it has exchanged when we're submitting a report using the context of the session. This means that the current solution with the byte counter does not work when there are persistent connections. I need to think about a different approach. 😞

bassosimone commented 4 years ago

So, while thinking about this, I'll work on https://github.com/ooni/probe-engine/issues/359. It seems I am hitting some of the problems caused by the complexity described in https://github.com/ooni/probe-engine/issues/359 anyway. 🤷‍♀

bassosimone commented 4 years ago

Okay, we've now reached again the point where we need to implement changes in probe-cli and in oonimkall to consider this issue complete! 🍀

bassosimone commented 4 years ago

So, probe-cli is very easy, this diff does the trick:

diff --git a/nettests/nettests.go b/nettests/nettests.go
index ea06ade..2231546 100644
--- a/nettests/nettests.go
+++ b/nettests/nettests.go
@@ -76,6 +76,10 @@ func (c *Controller) Run(builder *engine.ExperimentBuilder, inputs []string) err
        builder.SetCallbacks(model.ExperimentCallbacks(c))
        c.numInputs = len(inputs)
        exp := builder.NewExperiment()
+       defer func() {
+               c.res.DataUsageDown += exp.KibiBytesReceived()
+               c.res.DataUsageUp += exp.KibiBytesSent()
+       }()

        c.msmts = make(map[int64]*database.Measurement)

@@ -202,6 +206,9 @@ func (c *Controller) OnProgress(perc float64, msg string) {

 // OnDataUsage should be called when we have a data usage update.
 func (c *Controller) OnDataUsage(dloadKiB, uploadKiB float64) {
-       c.res.DataUsageDown += dloadKiB
-       c.res.DataUsageUp += uploadKiB
+       // Unused as 2020-04-05: we're now using directly the accessors
+       // provided by the experiment. This callback is going to be removed
+       // from probe-engine in May or June.
+       //
+       // TODO(bassosimone): create an issue for this?
 }

We're nearly done

bassosimone commented 4 years ago

This is now hopefully done!