feat(oohelperd): log messages at info level (#896)

We're using a request-specific logger where we also print the ID
of the request. This design helps to observe logs produced by
concurrent requests.

Part of https://github.com/ooni/probe/issues/2183

While there, fix https://github.com/ooni/probe/issues/2241
This commit is contained in:
Simone Basso 2022-08-28 22:26:58 +02:00 committed by GitHub
commit 4241ee4bc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 225 additions and 27 deletions

View file

@ -6,6 +6,7 @@ package main
import (
"context"
"fmt"
"net"
"net/url"
"sync"
@ -24,9 +25,16 @@ type (
// measure performs the measurement described by the request and
// returns the corresponding response or an error.
func measure(ctx context.Context, config *handler, creq *ctrlRequest) (*ctrlResponse, error) {
// create indexed logger
logger := &indexLogger{
indexstr: fmt.Sprintf("<#%d> ", config.Indexer.Add(1)),
logger: config.BaseLogger,
}
// parse input for correctness
URL, err := url.Parse(creq.HTTPRequest)
if err != nil {
logger.Warnf("cannot parse URL: %s", err.Error())
return nil, err
}
wg := &sync.WaitGroup{}
@ -37,6 +45,7 @@ func measure(ctx context.Context, config *handler, creq *ctrlRequest) (*ctrlResp
wg.Add(1)
go dnsDo(ctx, &dnsConfig{
Domain: URL.Hostname(),
Logger: logger,
NewResolver: config.NewResolver,
Out: dnsch,
Wg: wg,
@ -78,6 +87,7 @@ func measure(ctx context.Context, config *handler, creq *ctrlRequest) (*ctrlResp
Address: endpoint.Addr,
EnableTLS: endpoint.TLS,
Endpoint: endpoint.Epnt,
Logger: logger,
NewDialer: config.NewDialer,
NewTSLHandshaker: config.NewTLSHandshaker,
URLHostname: URL.Hostname(),
@ -91,6 +101,7 @@ func measure(ctx context.Context, config *handler, creq *ctrlRequest) (*ctrlResp
wg.Add(1)
go httpDo(ctx, &httpConfig{
Headers: creq.HTTPRequestHeaders,
Logger: logger,
MaxAcceptableBody: config.MaxAcceptableBody,
NewClient: config.NewClient,
Out: httpch,