You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue documents a possible code cleanup identified by @ainghazal in ooni/probe-cli#1625. Basically, rather than exposing a function for fetching each "richer input" type from a "Session", like we do now:
typeExperimentTargetLoaderSessioninterface {
ExperimentProbeServicesClient(ctx context.Context) (ExperimentProbeServicesClient, error)
Logger() Logger
}
typeExperimentProbeServicesClientinterface {
// NewConfig returns a new [*httpclientx.Config] to communicate with the backend.NewConfig() *httpclientx.Config// NewProbeServicesEndpoints returns a copy of the list of known probe-services endpoints.NewProbeServicesEndpoints() []*httpclientx.Endpoint
}
The above code would not compile because of circular dependency, but this could be solved by moving the definition of *httpclientx.Config and *httpclientx.Endpoint to ./internal/model.
By doing that, communicating with the backend becomes an experiment-specific task and we can make lots of code experiment-private rather than having to implement fetches inside the ./internal/engine package.
Other solutions, would be possible, and we should discuss. The really important concept here is to move complexity from the ./internal/engine package to as close as possible to the experiments needing it.
The solution I presented above is just the first one that came to my mind.
The text was updated successfully, but these errors were encountered:
to me NewProbeServicesEndpoints semantics is confusing. Is this supposed to return a list of all known probe services domains?
If we assume that at the point of passing control to experiment we have already selected one, perhaps it's enough with having a method for BaseURL()? Or perhaps I'm missing something here.
package httpclientx // import "github.com/ooni/probe-cli/v3/internal/httpclientx"typeConfigstruct {
// Authorization contains the OPTIONAL Authorization header value to use.Authorizationstring// Client is the MANDATORY [model.HTTPClient] to use.Client model.HTTPClient// Logger is the MANDATORY [model.Logger] to use.Logger model.Logger// MaxResponseBodySize OPTIONALLY limits the maximum body size. If not set, we// use the [DefaultMaxResponseBodySize] value.MaxResponseBodySizeint64// UserAgent is the MANDATORY User-Agent header value to use.UserAgentstring
}
typeEndpointstruct {
// URL is the MANDATORY endpoint URL.URLstring// Host is the OPTIONAL host header to use for cloudfronting.Hoststring
}
typeOverlapped[Outputany] struct { /* ... */ }
// usage:// create a probe services clientpsc, err:=sess.NewProbeServicesClient(ctx)
iferr!=nil { /* ... */ }
// create configconfig:=psc.NewConfig()
// edit config...// get available endpointsepnts:=psc.NewEndpoints()
// create overlapped function callovr:=httpclientx.NewOverlappedPostJSON[*APIReq, *APIResp](apiReq, config)
// issue the overlapped function callresp, _, err:=ovr.Run(ctx, endpoints...)
iferr!=nil { /* ... */ }
From an initial back-and-forth with @ainghazal, it seems my proposal is, for now, quite unclear/obscure. I would circle back with @ainghazal, hammer down what is unclear and what could improved, then write a summary here below.
This issue documents a possible code cleanup identified by @ainghazal in ooni/probe-cli#1625. Basically, rather than exposing a function for fetching each "richer input" type from a "Session", like we do now:
We can instead have something like the following:
The above code would not compile because of circular dependency, but this could be solved by moving the definition of
*httpclientx.Config
and*httpclientx.Endpoint
to./internal/model
.By doing that, communicating with the backend becomes an experiment-specific task and we can make lots of code experiment-private rather than having to implement fetches inside the
./internal/engine
package.Other solutions, would be possible, and we should discuss. The really important concept here is to move complexity from the
./internal/engine
package to as close as possible to the experiments needing it.The solution I presented above is just the first one that came to my mind.
The text was updated successfully, but these errors were encountered: