-
Notifications
You must be signed in to change notification settings - Fork 2
Send correct logs to Saturn logger #40
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,9 +56,10 @@ func main1() int { | |
LoggingClient: http.DefaultClient, | ||
LoggingInterval: 5 * time.Second, | ||
|
||
DoValidation: true, | ||
PoolRefresh: 5 * time.Minute, | ||
SaturnClient: &saturnClient, | ||
DoValidation: true, | ||
PoolRefresh: 5 * time.Minute, | ||
SaturnClient: &saturnClient, | ||
SaturnLoggerJWT: "test", | ||
}) | ||
if err != nil { | ||
return err | ||
|
@@ -84,5 +85,6 @@ func main1() int { | |
log.Println(err) | ||
return 1 | ||
} | ||
time.Sleep(5 * time.Second) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was for some debugging to ensure that we do eventually see the response of the logging endpoint before shutting down. Lemme remove this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aarshkshah1992 but.. did you push the removal? 🙃 I still see it :D |
||
return 0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package caboose | |
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
"time" | ||
|
@@ -19,6 +20,7 @@ type logger struct { | |
client *http.Client | ||
endpoint url.URL | ||
done chan struct{} | ||
jwt string | ||
} | ||
|
||
func newLogger(c *Config) *logger { | ||
|
@@ -28,6 +30,7 @@ func newLogger(c *Config) *logger { | |
client: c.LoggingClient, | ||
endpoint: c.LoggingEndpoint, | ||
done: make(chan struct{}), | ||
jwt: c.SaturnLoggerJWT, | ||
} | ||
go l.background() | ||
return &l | ||
|
@@ -59,7 +62,24 @@ func (l *logger) submit(logs []log) { | |
finalLogs := bytes.NewBuffer(nil) | ||
enc := json.NewEncoder(finalLogs) | ||
enc.Encode(logBatch{logs}) | ||
l.client.Post(l.endpoint.String(), "application/json", finalLogs) | ||
|
||
req, err := http.NewRequest(http.MethodPost, l.endpoint.String(), finalLogs) | ||
if err != nil { | ||
goLogger.Errorw("failed to create http request to submit saturn logs", "err", err) | ||
return | ||
} | ||
|
||
req.Header.Set("Content-Type", "application/json") | ||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", l.jwt)) | ||
|
||
resp, err := l.client.Do(req) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather than having this a specific so e.g. we set the specific client/url at https://github.com/ipfs/bifrost-gateway/blob/main/blockstore.go#L111 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have removed this token from the config. |
||
if err != nil { | ||
goLogger.Errorw("failed to submit saturn logs", "err", err) | ||
return | ||
} | ||
if resp.StatusCode != http.StatusOK { | ||
goLogger.Errorw("saturn logging endpoint did not return 200", "status", resp.StatusCode) | ||
} | ||
} | ||
|
||
func (l *logger) Close() { | ||
|
@@ -71,17 +91,19 @@ type logBatch struct { | |
} | ||
|
||
type log struct { | ||
CacheHit bool `json:"cacheHit"` | ||
URL string `json:"url"` | ||
LocalTime time.Time `json:"localTime"` | ||
NumBytesSent int `json:"numBytesSent"` | ||
RequestDuration float64 `json:"requestDuration"` // in seconds | ||
RequestID string `json:"requestId"` | ||
HTTPStatusCode int `json:"httpStatusCode"` | ||
HTTPProtocol string `json:"httpProtocol"` | ||
TTFBMS int `json:"ttfbMs"` | ||
ClientAddress string `json:"clientAddress"` | ||
Range string `json:"range"` | ||
Referrer string `json:"referrer"` | ||
UserAgent string `json:"userAgent"` | ||
CacheHit bool `json:"cacheHit"` | ||
URL string `json:"url"` | ||
StartTime time.Time `json:"startTime"` | ||
NumBytesSent int `json:"numBytesSent"` | ||
RequestDurationSec float64 `json:"requestDurationSec"` // in seconds | ||
RequestID string `json:"requestId"` | ||
HTTPStatusCode int `json:"httpStatusCode"` | ||
HTTPProtocol string `json:"httpProtocol"` | ||
TTFBMS int `json:"ttfbMs"` | ||
Range string `json:"range"` | ||
Referrer string `json:"referrer"` | ||
UserAgent string `json:"userAgent"` | ||
NodeId string `json:"nodeId"` | ||
IfNetworkError string `json:"ifNetworkError"` | ||
NodeIpAddress string `json:"nodeIpAddress"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iiurc last time we talked about this @guanzo noted it is ok to simply disable sending logs to logger when JWT token is not set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.