Skip to content

Commit

Permalink
Log type of nacserv request
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Dec 21, 2023
1 parent fcdf41f commit 60d7c1d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions imessage/direct/nacserv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func (c *Client) FetchVersions(ctx context.Context) (*ids.Versions, error) {
var resp *Response
var err error
if !c.IsRelay {
resp, err = c.FetchValidationData(ctx)
resp, err = c.fetch(ctx, c.URL, nil, "versions (direct)")
} else {
resp, err = c.fetch(ctx, fmt.Sprintf("%s/api/v1/bridge/get-version-info", c.URL), []byte("{}"))
resp, err = c.fetch(ctx, fmt.Sprintf("%s/api/v1/bridge/get-version-info", c.URL), []byte("{}"), "versions (relay)")
}
if err != nil {
return nil, err
Expand All @@ -65,12 +65,12 @@ func (c *Client) FetchVersions(ctx context.Context) (*ids.Versions, error) {

func (c *Client) FetchValidationData(ctx context.Context) (*Response, error) {
if !c.IsRelay {
return c.fetch(ctx, c.URL, nil)
return c.fetch(ctx, c.URL, nil, "validation data (direct)")
}
return c.fetch(ctx, fmt.Sprintf("%s/api/v1/bridge/get-validation-data", c.URL), []byte("{}"))
return c.fetch(ctx, fmt.Sprintf("%s/api/v1/bridge/get-validation-data", c.URL), []byte("{}"), "validation data (relay)")
}

func (c *Client) fetch(ctx context.Context, url string, body []byte) (*Response, error) {
func (c *Client) fetch(ctx context.Context, url string, body []byte, dataType string) (*Response, error) {
log := zerolog.Ctx(ctx)
method := http.MethodGet
if body != nil {
Expand All @@ -85,7 +85,7 @@ func (c *Client) fetch(ctx context.Context, url string, body []byte) (*Response,
req.Header.Set("X-Beeper-Access-Token", c.BeeperToken)
}

log.Info().Str("url", req.URL.String()).Msg("Fetching nacserv data")
log.Info().Str("url", req.URL.String()).Str("data_type", dataType).Msg("Fetching nacserv data")

resp, data, err := httputil.Do(httputil.Normal, req)
if err != nil {
Expand All @@ -104,8 +104,10 @@ func (c *Client) fetch(ctx context.Context, url string, body []byte) (*Response,

var logEvent = log.Info().
Str("name", respData.Name).
Str("data_type", dataType).
Time("valid_until", respData.ValidUntil).
Str("error", respData.Error)
Str("error", respData.Error).
Bool("has_data", respData.Data != nil)
if respData.Versions != nil {
logEvent = logEvent.Object("versions", respData.Versions)
}
Expand Down

0 comments on commit 60d7c1d

Please sign in to comment.