Skip to content

Commit

Permalink
add provider for fiber storage
Browse files Browse the repository at this point in the history
  • Loading branch information
negrel committed May 5, 2024
1 parent 5dc9c73 commit cdd715a
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/server/full/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func Initialize(logger wired.BootstrapLogger) wired.App {
uaparser.ProvideService,
wired.ProvideApp,
wired.ProvideClickhouseConfig,
wired.ProvideFiberStorage,
wired.ProvideGrafanaConfig,
wired.ProvideLogger,
wired.ProvideMinimalFiber,
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/full/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/server/ingestion/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func Initialize(logger wired.BootstrapLogger) wired.App {
uaparser.ProvideService,
wired.ProvideApp,
wired.ProvideClickhouseConfig,
wired.ProvideFiberStorage,
wired.ProvideLogger,
wired.ProvideMinimalFiber,
wired.ProvideMinimalFiberConfig,
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/ingestion/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
default = pkgs.buildGoModule {
pname = "prisme";
version = "0.15.0";
vendorHash = "sha256-cjt7l+6k+TLuzp5vwXBI5WvrtqRH5IZept/MV5Zv0L8=";
vendorHash = "sha256-90NC32QsMnF3rwUmtB2x9aEqpNiRn+hIRuFfaFfv6w4=";

src = ./.;
# Skip go test.
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ require (
github.com/ClickHouse/clickhouse-go/v2 v2.23.2
github.com/cespare/xxhash/v2 v2.3.0
github.com/gofiber/fiber/v2 v2.52.4
github.com/gofiber/storage v1.3.3
github.com/gofiber/storage/memory v1.3.4
github.com/golang-migrate/migrate/v4 v4.17.1
github.com/google/uuid v1.6.0
github.com/google/wire v0.6.0
github.com/negrel/ringo v0.5.0
github.com/oschwald/maxminddb-golang v1.12.0
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/client_model v0.5.0
github.com/rs/zerolog v1.32.0
github.com/stretchr/testify v1.9.0
github.com/tidwall/gjson v1.17.1
Expand All @@ -31,7 +34,6 @@ require (
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/gofiber/storage v1.3.3 h1:XvcaYqEVcoXllhnkvH8sTIbuB1IbidIe3UlxzMvzBrE=
github.com/gofiber/storage v1.3.3/go.mod h1:ZGviBmsCFkBSQInsD4C5e390gXwnH/MKcpKk//Fwv6o=
github.com/gofiber/storage/memory v1.3.4 h1:VxTq8Vrdvk73VsfvtTgc3LjXClbBrHXanzEo+w0cpgo=
github.com/gofiber/storage/memory v1.3.4/go.mod h1:pYsCUle/+4exGfsG7IlpmFYBVmNntP8OIDBvmABU8PE=
github.com/gofiber/utils v1.0.1 h1:knct4cXwBipWQqFrOy1Pv6UcgPM+EXo9jDgc66V1Qio=
github.com/gofiber/utils v1.0.1/go.mod h1:pacRFtghAE3UoknMOUiXh2Io/nLWSUHtQCi/3QASsOc=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-migrate/migrate/v4 v4.17.1 h1:4zQ6iqL6t6AiItphxJctQb3cFqWiSpMnX7wLTPnnYO4=
Expand Down
4 changes: 3 additions & 1 deletion pkg/middlewares/events_rate_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import (

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/limiter"
"github.com/gofiber/storage"
"github.com/prismelabs/analytics/pkg/config"
)

type EventsRateLimiter fiber.Handler

// ProvideEventsRateLimiter is a wire provider for events endpoints rate limiter.
func ProvideEventsRateLimiter(cfg config.Server) EventsRateLimiter {
func ProvideEventsRateLimiter(cfg config.Server, storage storage.Storage) EventsRateLimiter {
return limiter.New(limiter.Config{
Max: 60,
KeyGenerator: func(c *fiber.Ctx) string {
return c.IP()
},
Expiration: time.Minute,
Storage: storage,
})
}
15 changes: 15 additions & 0 deletions pkg/wired/fiber_storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package wired

import (
"time"

"github.com/gofiber/storage"
"github.com/gofiber/storage/memory"
)

// ProvideFiberStorage is a wire provider for fiber storage.
func ProvideFiberStorage() storage.Storage {
return memory.New(memory.Config{
GCInterval: 10 * time.Second,
})
}

0 comments on commit cdd715a

Please sign in to comment.