Skip to content

Commit

Permalink
Release/v0.8.3 (#116)
Browse files Browse the repository at this point in the history
* Bump up APIFW version to v0.8.3

* Bump up Go version to 1.22.8

* Add additional conf params in proxy and API modes

* Add version package. Update Makefile and Dockerfile
  • Loading branch information
afr1ka authored Oct 22, 2024
1 parent d3a6a01 commit 3a10ff7
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 118 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
needs:
- draft-release
env:
X_GO_DISTRIBUTION: "https://go.dev/dl/go1.22.7.linux-amd64.tar.gz"
X_GO_DISTRIBUTION: "https://go.dev/dl/go1.22.8.linux-amd64.tar.gz"
strategy:
matrix:
include:
Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:
needs:
- draft-release
env:
X_GO_VERSION: "1.22.7"
X_GO_VERSION: "1.22.8"
strategy:
matrix:
include:
Expand Down Expand Up @@ -267,19 +267,19 @@ jobs:
include:
- arch: armv6
distro: bullseye
go_distribution: https://go.dev/dl/go1.22.7.linux-armv6l.tar.gz
go_distribution: https://go.dev/dl/go1.22.8.linux-armv6l.tar.gz
artifact: armv6-libc
- arch: aarch64
distro: bullseye
go_distribution: https://go.dev/dl/go1.22.7.linux-arm64.tar.gz
go_distribution: https://go.dev/dl/go1.22.8.linux-arm64.tar.gz
artifact: arm64-libc
- arch: armv6
distro: alpine_latest
go_distribution: https://go.dev/dl/go1.22.7.linux-armv6l.tar.gz
go_distribution: https://go.dev/dl/go1.22.8.linux-armv6l.tar.gz
artifact: armv6-musl
- arch: aarch64
distro: alpine_latest
go_distribution: https://go.dev/dl/go1.22.7.linux-arm64.tar.gz
go_distribution: https://go.dev/dl/go1.22.8.linux-arm64.tar.gz
artifact: arm64-musl
steps:
- uses: actions/[email protected]
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM golang:1.22-alpine3.20 AS build

ARG APIFIREWALL_NAMESPACE
ARG APIFIREWALL_VERSION
ENV APIFIREWALL_NAMESPACE=${APIFIREWALL_NAMESPACE}
ENV APIFIREWALL_VERSION=${APIFIREWALL_VERSION}

RUN apk add --no-cache \
Expand All @@ -15,7 +16,7 @@ COPY . .

RUN go mod download -x && \
go build \
-ldflags="-X ${APIFIREWALL_NAMESPACE}/main.version=${APIFIREWALL_VERSION} -X main.build=${APIFIREWALL_VERSION} -s -w" \
-ldflags="-X ${APIFIREWALL_NAMESPACE}/internal/version.Version=${APIFIREWALL_VERSION} -s -w" \
-buildvcs=false \
-o ./api-firewall \
./cmd/api-firewall
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 0.8.2
VERSION := 0.8.3
NAMESPACE := github.com/wallarm/api-firewall

.DEFAULT_GOAL := build
Expand Down
4 changes: 2 additions & 2 deletions cmd/api-firewall/internal/handlers/api/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"github.com/valyala/fasthttp"
"github.com/wallarm/api-firewall/internal/platform/storage"
"github.com/wallarm/api-firewall/internal/platform/web"
"github.com/wallarm/api-firewall/internal/version"
)

type Health struct {
Build string
Logger *logrus.Logger
OpenAPIDB storage.DBOpenAPILoader
}
Expand Down Expand Up @@ -55,7 +55,7 @@ func (h *Health) Liveness(ctx *fasthttp.RequestCtx) error {
Namespace string `json:"namespace,omitempty"`
}{
Status: "up",
Build: h.Build,
Build: version.Version,
Host: host,
Pod: os.Getenv("KUBERNETES_PODNAME"),
PodIP: os.Getenv("KUBERNETES_NAMESPACE_POD_IP"),
Expand Down
8 changes: 4 additions & 4 deletions cmd/api-firewall/internal/handlers/proxy/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"github.com/valyala/fasthttp"
"github.com/wallarm/api-firewall/internal/platform/proxy"
"github.com/wallarm/api-firewall/internal/platform/web"
"github.com/wallarm/api-firewall/internal/version"
)

type Health struct {
Build string
Logger *logrus.Logger
Pool proxy.Pool
}

// Readiness checks if the Fasthttp connection pool is ready to handle new requests.
func (h Health) Readiness(ctx *fasthttp.RequestCtx) error {
func (h *Health) Readiness(ctx *fasthttp.RequestCtx) error {

status := "ok"
statusCode := fasthttp.StatusOK
Expand Down Expand Up @@ -47,7 +47,7 @@ func (h Health) Readiness(ctx *fasthttp.RequestCtx) error {
// app is deployed to a Kubernetes cluster, it will also return pod, node, and
// namespace details via the Downward API. The Kubernetes environment variables
// need to be set within your Pod/Deployment manifest.
func (h Health) Liveness(ctx *fasthttp.RequestCtx) error {
func (h *Health) Liveness(ctx *fasthttp.RequestCtx) error {
host, err := os.Hostname()
if err != nil {
host = "unavailable"
Expand All @@ -63,7 +63,7 @@ func (h Health) Liveness(ctx *fasthttp.RequestCtx) error {
Namespace string `json:"namespace,omitempty"`
}{
Status: "up",
Build: h.Build,
Build: version.Version,
Host: host,
Pod: os.Getenv("KUBERNETES_PODNAME"),
PodIP: os.Getenv("KUBERNETES_NAMESPACE_POD_IP"),
Expand Down
95 changes: 65 additions & 30 deletions cmd/api-firewall/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"expvar" // Register the expvar handlers
"fmt"
"mime"
"net"
Expand All @@ -17,6 +16,7 @@ import (
"github.com/ardanlabs/conf"
"github.com/go-playground/validator"
"github.com/pkg/errors"
"github.com/savsgio/gotils/strconv"
"github.com/sirupsen/logrus"
"github.com/valyala/fasthttp"
"github.com/wundergraph/graphql-go-tools/pkg/graphql"
Expand All @@ -30,10 +30,9 @@ import (
"github.com/wallarm/api-firewall/internal/platform/proxy"
"github.com/wallarm/api-firewall/internal/platform/storage"
"github.com/wallarm/api-firewall/internal/platform/web"
"github.com/wallarm/api-firewall/internal/version"
)

var build = "develop"

const (
namespace = "apifw"
logPrefix = "main"
Expand Down Expand Up @@ -95,7 +94,7 @@ func runAPIMode(logger *logrus.Logger) error {
// Configuration

var cfg config.APIMode
cfg.Version.SVN = build
cfg.Version.SVN = version.Version
cfg.Version.Desc = projectName

if err := conf.Parse(os.Args[1:], namespace, &cfg); err != nil {
Expand Down Expand Up @@ -140,10 +139,7 @@ func runAPIMode(logger *logrus.Logger) error {
return errors.New("invalid log level")
}

// print the build version for our logs. Also expose it under /debug/vars
expvar.NewString("build").Set(build)

logger.Infof("%s : Started : Application initializing : version %q", logPrefix, build)
logger.Infof("%s : Started : Application initializing : version %q", logPrefix, version.Version)
defer logger.Infof("%s: Completed", logPrefix)

out, err := conf.String(&cfg)
Expand Down Expand Up @@ -211,7 +207,6 @@ func runAPIMode(logger *logrus.Logger) error {
// Start Health API Service

healthData := handlersAPI.Health{
Build: build,
Logger: logger,
OpenAPIDB: specStorage,
}
Expand Down Expand Up @@ -266,9 +261,25 @@ func runAPIMode(logger *logrus.Logger) error {
}

api := fasthttp.Server{
Handler: requestHandlers,
ReadTimeout: cfg.ReadTimeout,
WriteTimeout: cfg.WriteTimeout,
Handler: requestHandlers,
ReadTimeout: cfg.ReadTimeout,
WriteTimeout: cfg.WriteTimeout,
ReadBufferSize: cfg.ReadBufferSize,
WriteBufferSize: cfg.WriteBufferSize,
MaxRequestBodySize: cfg.MaxRequestBodySize,
DisableKeepalive: cfg.DisableKeepalive,
MaxConnsPerIP: cfg.MaxConnsPerIP,
MaxRequestsPerConn: cfg.MaxRequestsPerConn,
ErrorHandler: func(ctx *fasthttp.RequestCtx, err error) {
logger.WithFields(logrus.Fields{
"error": err,
"host": strconv.B2S(ctx.Request.Header.Host()),
"path": strconv.B2S(ctx.Path()),
"method": strconv.B2S(ctx.Request.Header.Method()),
}).Error("request processing error")

ctx.Error("", fasthttp.StatusInternalServerError)
},
Logger: logger,
NoDefaultServerHeader: true,
}
Expand Down Expand Up @@ -337,7 +348,7 @@ func runGraphQLMode(logger *logrus.Logger) error {
// Configuration

var cfg config.GraphQLMode
cfg.Version.SVN = build
cfg.Version.SVN = version.Version
cfg.Version.Desc = projectName

if err := conf.Parse(os.Args[1:], namespace, &cfg); err != nil {
Expand Down Expand Up @@ -382,10 +393,7 @@ func runGraphQLMode(logger *logrus.Logger) error {
return errors.New("invalid log level")
}

// Print the build version for our logs. Also expose it under /debug/vars.
expvar.NewString("build").Set(build)

logger.Infof("%s : Started : Application initializing : version %q", logPrefix, build)
logger.Infof("%s : Started : Application initializing : version %q", logPrefix, version.Version)
defer logger.Infof("%s: Completed", logPrefix)

out, err := conf.String(&cfg)
Expand Down Expand Up @@ -467,6 +475,9 @@ func runGraphQLMode(logger *logrus.Logger) error {
MaxConnsPerHost: cfg.Server.MaxConnsPerHost,
ReadTimeout: cfg.Server.ReadTimeout,
WriteTimeout: cfg.Server.WriteTimeout,
ReadBufferSize: cfg.Server.ReadBufferSize,
WriteBufferSize: cfg.Server.WriteBufferSize,
MaxResponseBodySize: cfg.Server.MaxResponseBodySize,
DialTimeout: cfg.Server.DialTimeout,
}
pool, err := proxy.NewChanPool(host, &options, nil)
Expand Down Expand Up @@ -538,7 +549,6 @@ func runGraphQLMode(logger *logrus.Logger) error {
// Start Health API Service

healthData := handlersProxy.Health{
Build: build,
Logger: logger,
Pool: pool,
}
Expand Down Expand Up @@ -593,9 +603,22 @@ func runGraphQLMode(logger *logrus.Logger) error {
}

api := fasthttp.Server{
Handler: requestHandlers,
ReadTimeout: cfg.ReadTimeout,
WriteTimeout: cfg.WriteTimeout,
Handler: requestHandlers,
ReadTimeout: cfg.ReadTimeout,
WriteTimeout: cfg.WriteTimeout,
ReadBufferSize: cfg.ReadBufferSize,
WriteBufferSize: cfg.WriteBufferSize,
MaxRequestBodySize: cfg.MaxRequestBodySize,
DisableKeepalive: cfg.DisableKeepalive,
MaxConnsPerIP: cfg.MaxConnsPerIP,
MaxRequestsPerConn: cfg.MaxRequestsPerConn,
ErrorHandler: func(ctx *fasthttp.RequestCtx, err error) {
logger.WithFields(logrus.Fields{
"error": err,
}).Error("request processing error")

ctx.Error("", fasthttp.StatusForbidden)
},
Logger: logger,
NoDefaultServerHeader: true,
}
Expand Down Expand Up @@ -643,7 +666,7 @@ func runProxyMode(logger *logrus.Logger) error {
// Configuration

var cfg config.ProxyMode
cfg.Version.SVN = build
cfg.Version.SVN = version.Version
cfg.Version.Desc = projectName

if err := conf.Parse(os.Args[1:], namespace, &cfg); err != nil {
Expand Down Expand Up @@ -721,10 +744,7 @@ func runProxyMode(logger *logrus.Logger) error {
// =========================================================================
// App Starting

// print the build version for our logs. Also expose it under /debug/vars
expvar.NewString("build").Set(build)

logger.Infof("%s : Started : Application initializing : version %q", logPrefix, build)
logger.Infof("%s : Started : Application initializing : version %q", logPrefix, version.Version)
defer logger.Infof("%s: Completed", logPrefix)

out, err := conf.String(&cfg)
Expand Down Expand Up @@ -820,6 +840,9 @@ func runProxyMode(logger *logrus.Logger) error {
MaxConnsPerHost: cfg.Server.MaxConnsPerHost,
ReadTimeout: cfg.Server.ReadTimeout,
WriteTimeout: cfg.Server.WriteTimeout,
ReadBufferSize: cfg.Server.ReadBufferSize,
WriteBufferSize: cfg.Server.WriteBufferSize,
MaxResponseBodySize: cfg.Server.MaxResponseBodySize,
DialTimeout: cfg.Server.DialTimeout,
DNSConfig: cfg.DNS,
}
Expand Down Expand Up @@ -884,7 +907,6 @@ func runProxyMode(logger *logrus.Logger) error {
// Start Health API Service

healthData := handlersProxy.Health{
Build: build,
Logger: logger,
Pool: pool,
}
Expand Down Expand Up @@ -939,9 +961,22 @@ func runProxyMode(logger *logrus.Logger) error {
}

api := fasthttp.Server{
Handler: requestHandlers,
ReadTimeout: cfg.ReadTimeout,
WriteTimeout: cfg.WriteTimeout,
Handler: requestHandlers,
ReadTimeout: cfg.ReadTimeout,
WriteTimeout: cfg.WriteTimeout,
ReadBufferSize: cfg.ReadBufferSize,
WriteBufferSize: cfg.WriteBufferSize,
MaxRequestBodySize: cfg.MaxRequestBodySize,
DisableKeepalive: cfg.DisableKeepalive,
MaxConnsPerIP: cfg.MaxConnsPerIP,
MaxRequestsPerConn: cfg.MaxRequestsPerConn,
ErrorHandler: func(ctx *fasthttp.RequestCtx, err error) {
logger.WithFields(logrus.Fields{
"error": err,
}).Error("request processing error")

ctx.Error("", cfg.CustomBlockStatusCode)
},
Logger: logger,
NoDefaultServerHeader: true,
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/api-firewall/tests/main_graphql_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ func BenchmarkGraphQL(b *testing.B) {
}
var cfg = config.GraphQLMode{
Graphql: gqlCfg,
Server: config.Backend{
Server: config.ProtectedAPI{
URL: benchBackendURL,
},
APIHost: benchHandlerURL,
APIFWServer: config.APIFWServer{
APIHost: benchHandlerURL,
},
}

handler := graphqlHandler.Handlers(&cfg, schema, serverURL, shutdown, logger, pool, wsPool, nil, nil)
Expand Down
Loading

0 comments on commit 3a10ff7

Please sign in to comment.