Skip to content

v0.4.0 + v0.4.1

Compare
Choose a tag to compare
@pacejackson pacejackson released this 22 Jun 18:33
· 358 commits to master since this release
v0.4.1

v0.4.1

Non-breaking changes

metricsbp

  • Add Statsd.RuntimeGauge, this is the gauges we used in RunSysStats. Make it a public API so other
    code can take advantage of it, too. If you are using metricsbp.M.Gauge, it might make sense to move to using metricsbp.M.RuntimeGauge(...) but note that it will add rutime. to the prefix and add instance+pid tags.
  • The Thrift client pool reported gauges are runtime gauges now, the old gauge will be removed in a future version so users should start to update their dashboards/alerts now.

thriftbp

  • Add support for suppressing errors on Thrift clients. (#241)
diff --git a/client.go b/client.go
index 53d6183..348ee0f 100644
--- a/client.go
+++ b/client.go
@@ -1,10 +1,12 @@
 package auth
 
 import (
+       "errors"
        "time"
 
        "github.com/reddit/baseplate.go/errorsbp"
        "github.com/reddit/baseplate.go/thriftbp"

+       "github.com/reddit/my-service/thrift/my_service"
 )
 
 const (
@@ -107,5 +109,10 @@ func (cfg Config) Compile() thriftbp.ClientPoolConfig {
                SocketTimeout:      cfg.SocketTimeout,
                ReportPoolStats:    cfg.PoolStats.Report,
                PoolGaugeInterval:  cfg.PoolStats.GaugeInterval,
+               ErrorSpanSuppressor: func(err error) bool {
+                       var myErr *my_service.MyError
+                       return errors.As(err, &myErr)
+               },
        }
 }

v0.4.0

This is a big release with bug fixes, enhancements, and several breaking changes.

Bug fixes

httpbp

  • httpbp.InjectEdgeRequestContext middleware was not base64 decoding the edge context header before parsing it, resulting in parsing failures. This has been fixed and should not require any changes to service code. (#236)

Breaking changes

thriftbp

  • The signatures of NewBaseplateServer, NewServer, and BaseplateDefaultProcessorMiddlewares have changed. NewBaseplateServer and NewServer both use ServerConfig as an arg now, and some of the new configuration options are added into ServerConfig struct. Specifically, ErrorSpanSuppressor has been added to allow you to suppress IDL defined errors from being reported as errors when stopping the server span. (#239)
diff --git a/main.go b/main.go
index dca49ac..37a9b9c 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,7 @@ package main
 
 import (
        "context"
+       "errors"
        "flag"
 
        "github.com/go-redis/redis/v7"
@@ -37,7 +38,13 @@ func main() {
                        redis.NewClusterClient(cfg.Redis.Options()),
                ),
        })
-       server, err := thriftbp.NewBaseplateServer(bp, processor)
+       server, err := thriftbp.NewBaseplateServer(bp, thriftbp.ServerConfig{
+               Processor: processor,
+               ErrorSpanSuppressor: func(err error) bool {
+                       var myErr *my_service.MyError
+                       return errors.As(err, &myErr)
+               },
+       })
        if err != nil {
                log.Fatal(err)
        }
diff --git a/server/service_test.go b/server/service_test.go
index a4789f0..664503f 100644
--- a/server/service_test.go
+++ b/server/service_test.go
@@ -44,7 +44,10 @@ func TestMain(m *testing.M) {
                ),
        })
 
-       srv, err = thrifttest.NewBaseplateServer(secrets, processor, thrifttest.ServerConfig{})
+       srv, err = thrifttest.NewBaseplateServer(thrifttest.ServerConfig{
+               Processor:   processor,
+               SecretStore: secrets,
+       })
        if err != nil {
                panic(err)
        }
  • When creating client pool we now have separated ConnectTimeout and SocketTimeout on ClientPoolConfig. (#232)
diff --git a/foo.go b/foo.go
index dc894be..53d6183 100644
--- a/foo.go
+++ b/foo.go
@@ -96,6 +103,7 @@ func (cfg Config) Compile() thriftbp.ClientPoolConfig {
                Addr:               "9090",
                InitialConnections: 1,
                MaxConnections:     100,
+               ConnectTimeout:     25*time.Millisecond,
                SocketTimeout:      500*time.Millisecond,
                ReportPoolStats:    true,

httpbp

  • When creating the Endpoint map for an HTTP server, you are now required to provide the list of allowed HTTP methods for each endpoint. (#227 , #229)
diff --git a/server/service.go b/server/service.go
index bb13e1f..7eb50a7 100644
--- a/server/service.go
+++ b/server/service.go
@@ -54,18 +54,22 @@ func (s MyService) Endpoints() map[httpbp.Pattern]httpbp.Endpoint {
        return map[httpbp.Pattern]httpbp.Endpoint{
                "/health": {
                        Name:   "is_healthy",
+                       Methods: []string{http.MethodGet},
                        Handle: s.IsHealthy,
                },
                "/foo": {
                        Name:   "foo",
+                       Methods: []string{http.MethodPost},
                        Handle: s.Foo,
                },
                "/foo/bar": {
                        Name:   "foo-bar",
+                       Methods: []string{http.MethodPost},
                        Handle: s.FooBar,
                },
                "/fizz": {
                        Name:   "fizz",
+                       Methods: []string{http.MethodGet},
                        Handle: s.Fizz,
                },
        }

metricsbp

  • Renamed all the terminology of “labels” into “tags”, this includes all of the types and functions to align with the terminology used in baseplate.py as well as the terminology used by Spans. (#224)
diff --git a/foo.go b/foo.go
index 1970b06..88875d3 100644
--- a/foo.go
+++ b/foo.go
@@ -22,13 +22,13 @@ func MonitorTraffic(name string, next httpbp.HandlerFunc) httpbp.HandlerFunc {
-               tags := metricsbp.Labels{"foo": foo}
+               tags := metricsbp.Tags{"foo": foo}
 
                if bar := r.Header.Get("bar"); bar != "" {
                        tags["bar"] = strings.ToLower(bar)
                }
 
-               metricsbp.M.Counter("traffic").With(tags.AsStatsdLabels()...).Add(1)
+               metricsbp.M.Counter("traffic").With(tags.AsStatsdTags()...).Add(1)
                return next(ctx, w, r)
        }
 }
  • The sys stats (reported via RunSysStats function) no longer takes customizable tags as the arg. The tags associated with those gauges are now fixed to comply with Baseplate spec. The metrics will also be prefixed with “runtime.”, and “runtime.active_requests” is added. (#224 , #238)
    • This is not a breaking change in code but you will have to adjust any dashboards/alerts that report these metrics.

batcherror -> errorsbp

  • The package batcherror no longer exists. batcherror.BatchError is now renamed into errorsbp.Batch. (#239)
diff --git a/foo.go b/foo.go
index c2705a4..dc894be 100644
--- a/foo.go
+++ b/foo.go
@@ -3,7 +3,7 @@ package foo
 import (
-       "github.com/reddit/baseplate.go/batcherror"
+       "github.com/reddit/baseplate.go/errorsbp"
 )
 
@@ -46,9 +46,9 @@ func DefaultConfig() Config {
 
 func (cfg Config) Validate() error {
-       var err batcherror.BatchError
+       var err errorsbp.Batch
        if cfg.Addr == "" {
                err.Add(ErrorInvalidConfigValue{
                        Name:  "Addr",

Non-breaking changes

errorsbp

  • Added a new type, errorsbp.Suppressor, in order to support some of the changes mentioned in thriftbp package. (#239)

metricsbp

  • For the counters that come automatically with Spans, the “fail” counter is called “failure” now to comply with Baseplate spec. (#224)
    • Currently we report both for an easier transition, but the “fail” counter will be removed in a future version.

thriftbp:

  • DefaultClientMiddlewareArgs added new configuration option to suppress certain errors to report in spans. (#239)
  • Support the standard Baseplate Error struct. (#226)