Skip to content

Commit

Permalink
test for batcher availability
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth More authored and Siddharth More committed Apr 3, 2024
1 parent 04b5c82 commit 619cb67
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 61 deletions.
2 changes: 1 addition & 1 deletion disperser/dataapi/grpc_service_availability_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *server) getServiceAvailability(ctx context.Context, services []string)
var availabilityStatus *ServiceAvailability
s.logger.Info("checking service health", "service", serviceName)

response, err := s.EigenDAGRPCServiceChecker.CheckHealth(ctx, serviceName)
response, err := s.eigenDAGRPCServiceChecker.CheckHealth(ctx, serviceName)
if err != nil {

if err.Error() == "disperser connection is nil" {
Expand Down
51 changes: 24 additions & 27 deletions disperser/dataapi/http_service_availability_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dataapi

import (
"context"
"fmt"
"net/http"
)

Expand All @@ -12,42 +11,40 @@ type HttpServiceAvailabilityCheck struct {
URL string
}

type HttpServiceAvailability struct{}

func (s *server) getServiceHealth(ctx context.Context, services []HttpServiceAvailabilityCheck) ([]*ServiceAvailability, error) {

availabilityStatuses := make([]*ServiceAvailability, len(services))
for i, service := range services {
var availabilityStatus *ServiceAvailability
s.logger.Info("checking service health", "service", service.ServiceName)
resp, err := http.Get(service.URL)

resp, err := s.eigenDAHttpServiceChecker.CheckHealth(service.URL)
if err != nil {
s.logger.Error("Error querying service health:", "err", err)
availabilityStatus := &ServiceAvailability{
ServiceName: service.ServiceName,
ServiceStatus: "UNKNOWN",
}
availabilityStatuses[i] = availabilityStatus
continue
}
defer resp.Body.Close()

// Check if the HTTP status code is 200 OK, which typically indicates healthiness.
// Adjust the logic if the service uses different conventions.
if resp.StatusCode == http.StatusOK {
availabilityStatus = &ServiceAvailability{
ServiceName: service.ServiceName,
ServiceStatus: "SERVING",
}
s.logger.Info("Service healthy", "service", service.ServiceName)
availabilityStatuses[i] = availabilityStatus
} else {
fmt.Printf("Service may not be healthy. Received status code: %d\n", resp.StatusCode)
availabilityStatus = &ServiceAvailability{
ServiceName: service.ServiceName,
ServiceStatus: "NOT_SERVING",
}
s.logger.Info("Service unhealthy", "service", service.ServiceName)
availabilityStatuses[i] = availabilityStatus

availabilityStatus = &ServiceAvailability{
ServiceName: service.ServiceName,
ServiceStatus: resp,
}
availabilityStatuses[i] = availabilityStatus
}
return availabilityStatuses, nil
}

// ServiceAvailability represents the status of a service.
func (sa *HttpServiceAvailability) CheckHealth(endpt string) (string, error) {
resp, err := http.Get(endpt)
if err != nil {
return "UNKNOWN", err
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusOK {
return "SERVING", nil
}

return "NOT_SERVING", nil
}
25 changes: 18 additions & 7 deletions disperser/dataapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type EigenDAGRPCServiceChecker interface {
CloseConnections() error
}

type EigenDAHttpServiceChecker interface {
CheckHealth(serviceName string) (string, error)
}

type (
BlobMetadataResponse struct {
BlobKey string `json:"blob_key"`
Expand Down Expand Up @@ -135,7 +139,8 @@ type (
disperserHostName string
churnerHostName string
batcherHealthUrl string
EigenDAGRPCServiceChecker EigenDAGRPCServiceChecker
eigenDAGRPCServiceChecker EigenDAGRPCServiceChecker
eigenDAHttpServiceChecker EigenDAHttpServiceChecker
}
)

Expand All @@ -149,17 +154,22 @@ func NewServer(
logger logging.Logger,
metrics *Metrics,
grpcConn GRPCConn,
EigenDAGRPCServiceChecker EigenDAGRPCServiceChecker,
eigenDAGRPCServiceChecker EigenDAGRPCServiceChecker,
eigenDAHttpServiceChecker EigenDAHttpServiceChecker,

) *server {
// Initialize the health checker service for EigenDA services
if grpcConn == nil {
grpcConn = &GRPCDialerSkipTLS{}
}

if EigenDAGRPCServiceChecker == nil {
if eigenDAGRPCServiceChecker == nil {

eigenDAGRPCServiceChecker = NewEigenDAServiceHealthCheck(grpcConn, config.DisperserHostname, config.ChurnerHostname)
}

EigenDAGRPCServiceChecker = NewEigenDAServiceHealthCheck(grpcConn, config.DisperserHostname, config.ChurnerHostname)
if eigenDAHttpServiceChecker == nil {
eigenDAHttpServiceChecker = &HttpServiceAvailability{}
}

return &server{
Expand All @@ -176,7 +186,8 @@ func NewServer(
disperserHostName: config.DisperserHostname,
churnerHostName: config.ChurnerHostname,
batcherHealthUrl: config.BatcherHealthUrl,
EigenDAGRPCServiceChecker: EigenDAGRPCServiceChecker,
eigenDAGRPCServiceChecker: eigenDAGRPCServiceChecker,
eigenDAHttpServiceChecker: eigenDAHttpServiceChecker,
}
}

Expand Down Expand Up @@ -255,8 +266,8 @@ func (s *server) Start() error {

func (s *server) Shutdown() error {

if s.EigenDAGRPCServiceChecker != nil {
err := s.EigenDAGRPCServiceChecker.CloseConnections()
if s.eigenDAGRPCServiceChecker != nil {
err := s.eigenDAGRPCServiceChecker.CloseConnections()

if err != nil {
s.logger.Error("Failed to close connections", "error", err)
Expand Down
Loading

0 comments on commit 619cb67

Please sign in to comment.