Skip to content

Commit

Permalink
feat(gossip.proto): add JoinRequest, JoinResponse, LeaveRequest, Leav…
Browse files Browse the repository at this point in the history
…eResponse

message types

chore(gossip.pb.go): update generated Go code for Gossip service
feat(gossip.pb.go): add new message types for JoinRequest, JoinResponse, LeaveRequest, LeaveResponse, and LeaveResponse
feat(gossip.pb.go): add support for self field in JoinRequest, LeaveRequest, and LeaveRequest
feat(gossip.pb.go): add support for LeaveRequest message type
feat(gossip.pb.go): add support for LeaveResponse message type
feat(gossip.pb.go): add support for LeaveResponse message type
feat(gossip.pb.go): add support for LeaveResponse message type
feat(gossip.pb.go): add support for LeaveResponse message type
feat(gossip.pb.go): add support for GossipService Ping method
feat(gossip.pb.go): add support for PingRequest and PingResponse message types
feat(gossip.pb.go): add support for Join method
feat(gossip.pb.go): add support for JoinRequest and JoinResponse message types

chore(gossip.pb.go): update number of message types to 14 in gossip.proto
feat(gossip.pb.go): add JoinRequest, JoinResponse, LeaveRequest, and LeaveResponse
message types to gossip.proto

chore(gossip): add Join and Leave procedures to GossipService
feat(cache): change ReportCacheHealth to Record in memory cache
feat(cache): change ReportCacheHit to Record in metrics middleware
refactor(ratelimit): remove logging of latency in ratelimit functions
refactor(service): update comments in Listen method regarding timeouts

feat(gossip): implement cluster package for managing gossip communication

feat(gossip): add cluster struct with methods for managing cluster members and
communication

feat(gossip): implement Config struct with default values for gossip
configuration

feat(gossip): add New function to create a new cluster instance with provided
config

feat(gossip): implement run method to start the cluster's gossip loop and
background tasks

feat(gossip): add methods for joining, shutting down, and subscribing to
cluster events

feat(gossip): implement randomPeers method to select random peers for gossip
communication

feat(gossip): add methods to add and remove members from the cluster state

feat(gossip): implement gossip method for exchanging membership information
with peers

feat(gossip): add clusterServer struct to handle gossip service
feat(gossip): implement CreateHandler method in clusterServer
feat(gossip): implement Serve method in clusterServer
feat(gossip): implement Join method in clusterServer
feat(gossip): implement Leave method in clusterServer
feat(gossip): implement Ping method in clusterServer
feat(gossip): implement IndirectPing method in clusterServer
feat(gossip): implement SyncMembers method in clusterServer
feat(gossip): add Member struct with Hash method
feat(gossip): add Cluster interface with SubscribeJoinEvents and SubscribeLeaveEvents
feat(gossip): add tests for cluster membership and event emission

feat(gossip): add rpc.go file with functions for handling join, leave, ping,
indirectPing, and syncMembers in the gossip package

feat(gossip): add test for membership changes propagation to hash ring
feat(gossip): add test utility function to simulate failure in cluster
fix(load): change variable name from SystemLoadReport to SystemLoad
fix(metrics): refactor axiom methods to use Record instead of specific reports
feat(metrics): add Metric interface for all metrics to implement
feat(proto): add Join and Leave RPC methods to GossipService
feat(scripts): add deploy script for scaling regions in fly platform

refactor(ratelimit): remove unused time tracking code in service methods
refactor(ratelimit): update ratelimit fields to use integer type instead of number
feat(api): update key schema fields to use integer type instead of number
feat(api): update ratelimit fields to use integer type instead of number

fix(routes): specify that limit and duration fields should be integers
  • Loading branch information
chronark committed Jul 19, 2024
1 parent 560608d commit 567207b
Show file tree
Hide file tree
Showing 34 changed files with 1,724 additions and 476 deletions.
337 changes: 297 additions & 40 deletions apps/agent/gen/proto/gossip/v1/gossip.pb.go

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions apps/agent/gen/proto/gossip/v1/gossipv1connect/gossip.connect.go

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

2 changes: 1 addition & 1 deletion apps/agent/pkg/cache/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (c *memory[T]) report() {
size := len(c.data)
utilization := float64(size) / math.Max(1, float64(c.maxSize))

c.metrics.ReportCacheHealth(metrics.CacheHealthReport{
c.metrics.Record(metrics.CacheHealth{
CacheSize: size,
CacheMaxSize: c.maxSize,
LruSize: c.lru.Len(),
Expand Down
2 changes: 1 addition & 1 deletion apps/agent/pkg/cache/middleware/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func WithMetrics[T any](c cache.Cache[T], m metrics.Metrics, resource string, ti
func (mw *metricsMiddleware[T]) Get(ctx context.Context, key string) (T, cache.CacheHit) {
start := time.Now()
value, hit := mw.next.Get(ctx, key)
mw.metrics.ReportCacheHit(metrics.CacheHitReport{
mw.metrics.Record(metrics.CacheHit{
Key: key,
Hit: hit != cache.Miss,
Resource: mw.resource,
Expand Down
20 changes: 1 addition & 19 deletions apps/agent/pkg/connect/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"time"

"connectrpc.com/connect"
"connectrpc.com/otelconnect"
Expand Down Expand Up @@ -47,12 +46,6 @@ func (s *ratelimitServer) Ratelimit(
ctx context.Context,
req *connect.Request[ratelimitv1.RatelimitRequest],
) (*connect.Response[ratelimitv1.RatelimitResponse], error) {
start := time.Now()
defer func() {
s.logger.Info().
Int64("latency", time.Since(start).Milliseconds()).
Msg("connect.Ratelimit")
}()

ctx, span := tracing.Start(ctx, tracing.NewSpanName("connect.ratelimit", "Ratelimit"))
defer span.End()
Expand All @@ -74,12 +67,6 @@ func (s *ratelimitServer) MultiRatelimit(
ctx context.Context,
req *connect.Request[ratelimitv1.RatelimitMultiRequest],
) (*connect.Response[ratelimitv1.RatelimitMultiResponse], error) {
start := time.Now()
defer func() {
s.logger.Info().
Int64("latency", time.Since(start).Milliseconds()).
Msg("connect.MultiRatelimit")
}()

ctx, span := tracing.Start(ctx, tracing.NewSpanName("connect.ratelimit", "MultiRatelimit"))
defer span.End()
Expand Down Expand Up @@ -112,12 +99,7 @@ func (s *ratelimitServer) PushPull(
ctx context.Context,
req *connect.Request[ratelimitv1.PushPullRequest],
) (*connect.Response[ratelimitv1.PushPullResponse], error) {
start := time.Now()
defer func() {
s.logger.Info().
Int64("latency", time.Since(start).Milliseconds()).
Msg("connect.PushPull")
}()

ctx, span := tracing.Start(ctx, tracing.NewSpanName("connect.ratelimit", "PushPull"))
defer span.End()
err := auth.Authorize(ctx, s.authToken, req.Header().Get("Authorization"))
Expand Down
8 changes: 4 additions & 4 deletions apps/agent/pkg/connect/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ func (s *Server) Listen(addr string) error {
srv := &http.Server{Addr: addr, Handler: h2c.NewHandler(s.mux, &http2.Server{})}

// See https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/
//
//
// > # http.ListenAndServe is doing it wrong
// > Incidentally, this means that the package-level convenience functions that bypass http.Server
// > like http.ListenAndServe, http.ListenAndServeTLS and http.Serve are unfit for public Internet
// > servers.
// >
// > hose functions leave the Timeouts to their default off value, with no way of enabling them,
// > so if you use them you'll soon be leaking connections and run out of file descriptors. I've
// > hose functions leave the Timeouts to their default off value, with no way of enabling them,
// > so if you use them you'll soon be leaking connections and run out of file descriptors. I've
// > made this mistake at least half a dozen times.
// >
// > Instead, create a http.Server instance with ReadTimeout and WriteTimeout and use its
// > Instead, create a http.Server instance with ReadTimeout and WriteTimeout and use its
// > corresponding methods, like in the example a few paragraphs above.
srv.ReadTimeout = 5 * time.Second
srv.WriteTimeout = 10 * time.Second
Expand Down
Loading

1 comment on commit 567207b

@vercel
Copy link

@vercel vercel bot commented on 567207b Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

planetfall – ./apps/planetfall

planetfall-git-main-unkey.vercel.app
planetfall-unkey.vercel.app
planetfall-two.vercel.app
planetfall.unkey.dev

Please sign in to comment.