MSP-8974 up deps
This commit is contained in:
1 parent
0abaaf740f
commit
a0aafd93b9
602 files changed
+47724
-13295
No files matched your search
+36
@@ -48,6 +48,12 @@ func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWr
|
||||
if fl && hj && rf {
|
||||
return &httpFancyWriter{bw}
|
||||
}
|
||||
if fl && hj {
|
||||
return &flushHijackWriter{bw}
|
||||
}
|
||||
if hj {
|
||||
return &hijackWriter{bw}
|
||||
}
|
||||
}
|
||||
if fl {
|
||||
return &flushWriter{bw}
|
||||
@@ -143,6 +149,36 @@ func (f *flushWriter) Flush() {
|
||||
|
||||
var _ http.Flusher = &flushWriter{}
|
||||
|
||||
// flushHijackWriter is a HTTP writer that additionally satisfies http.Flusher
|
||||
// and http.Hijacker, for writers that do not implement io.ReaderFrom.
|
||||
type flushHijackWriter struct {
|
||||
basicWriter
|
||||
}
|
||||
|
||||
func (f *flushHijackWriter) Flush() {
|
||||
f.wroteHeader = true
|
||||
f.ResponseWriter.(http.Flusher).Flush()
|
||||
}
|
||||
|
||||
func (f *flushHijackWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
return f.ResponseWriter.(http.Hijacker).Hijack()
|
||||
}
|
||||
|
||||
var _ http.Flusher = &flushHijackWriter{}
|
||||
var _ http.Hijacker = &flushHijackWriter{}
|
||||
|
||||
// hijackWriter is a HTTP writer that additionally satisfies http.Hijacker, for
|
||||
// writers that implement neither http.Flusher nor io.ReaderFrom.
|
||||
type hijackWriter struct {
|
||||
basicWriter
|
||||
}
|
||||
|
||||
func (f *hijackWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
return f.ResponseWriter.(http.Hijacker).Hijack()
|
||||
}
|
||||
|
||||
var _ http.Hijacker = &hijackWriter{}
|
||||
|
||||
// httpFancyWriter is a HTTP writer that additionally satisfies
|
||||
// http.Flusher, http.Hijacker, and io.ReaderFrom. It exists for the common case
|
||||
// of wrapping the http.ResponseWriter that package http gives you, in order to
|
||||
|
||||
+12
-8
@@ -3,6 +3,7 @@ package protocol
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -210,17 +211,20 @@ func (dsn *Dsn) SetOrgID(orgID uint64) {
|
||||
// GetAPIURL returns the URL of the envelope endpoint of the project
|
||||
// associated with the DSN.
|
||||
func (dsn Dsn) GetAPIURL() *url.URL {
|
||||
var rawURL string
|
||||
rawURL += fmt.Sprintf("%s://%s", dsn.scheme, dsn.host)
|
||||
host := dsn.host
|
||||
port := ""
|
||||
if dsn.port != dsn.scheme.defaultPort() {
|
||||
rawURL += fmt.Sprintf(":%d", dsn.port)
|
||||
port = strconv.Itoa(dsn.port)
|
||||
}
|
||||
if dsn.path != "" {
|
||||
rawURL += dsn.path
|
||||
// JoinHostPort correctly adds brackets for IPv6 hosts. However with an
|
||||
// empty port it leaves a trailing ":", which we trim to omit the default port.
|
||||
host = net.JoinHostPort(host, port)
|
||||
host = strings.TrimSuffix(host, ":")
|
||||
return &url.URL{
|
||||
Scheme: string(dsn.scheme),
|
||||
Host: host,
|
||||
Path: dsn.path + "/api/" + dsn.projectID + "/envelope/",
|
||||
}
|
||||
rawURL += fmt.Sprintf("/api/%s/%s/", dsn.projectID, "envelope")
|
||||
parsedURL, _ := url.Parse(rawURL)
|
||||
return parsedURL
|
||||
}
|
||||
|
||||
// RequestHeaders returns all the necessary headers that have to be used in the transport when sending events
|
||||
|
||||
+26
-2
@@ -26,6 +26,9 @@ type Scheduler struct {
|
||||
cancel context.CancelFunc
|
||||
processingWg sync.WaitGroup
|
||||
|
||||
// processing serializes buffer-to-transport handoffs and allows cancelable waits.
|
||||
processing chan struct{}
|
||||
|
||||
mu sync.Mutex
|
||||
cond *sync.Cond
|
||||
startOnce sync.Once
|
||||
@@ -79,6 +82,7 @@ func NewScheduler(
|
||||
currentCycle: currentCycle,
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
processing: make(chan struct{}, 1),
|
||||
}
|
||||
s.cond = sync.NewCond(&s.mu)
|
||||
|
||||
@@ -145,7 +149,9 @@ func (s *Scheduler) Flush(timeout time.Duration) bool {
|
||||
}
|
||||
|
||||
func (s *Scheduler) FlushWithContext(ctx context.Context) bool {
|
||||
s.flushBuffers()
|
||||
if !s.flushBuffers(ctx) {
|
||||
return false
|
||||
}
|
||||
return s.transport.FlushWithContext(ctx)
|
||||
}
|
||||
|
||||
@@ -193,6 +199,13 @@ func (s *Scheduler) hasWork() bool {
|
||||
}
|
||||
|
||||
func (s *Scheduler) processNextBatch() {
|
||||
select {
|
||||
case s.processing <- struct{}{}:
|
||||
defer func() { <-s.processing }()
|
||||
case <-s.ctx.Done():
|
||||
return
|
||||
}
|
||||
|
||||
if len(s.currentCycle) == 0 {
|
||||
return
|
||||
}
|
||||
@@ -290,12 +303,23 @@ func (s *Scheduler) sendItem(item protocol.EnvelopeConvertible) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Scheduler) flushBuffers() {
|
||||
func (s *Scheduler) flushBuffers(ctx context.Context) bool {
|
||||
select {
|
||||
case s.processing <- struct{}{}:
|
||||
defer func() { <-s.processing }()
|
||||
case <-ctx.Done():
|
||||
return false
|
||||
}
|
||||
|
||||
for category, buffer := range s.buffers {
|
||||
if ctx.Err() != nil {
|
||||
return false
|
||||
}
|
||||
if !buffer.IsEmpty() {
|
||||
s.processItems(buffer, category, true)
|
||||
}
|
||||
}
|
||||
return ctx.Err() == nil
|
||||
}
|
||||
|
||||
func (s *Scheduler) isRateLimited(category ratelimit.Category) bool {
|
||||
|
||||
Reference in new issue
Block a user