Skip to content

Commit

Permalink
[DataApi] Add Batcher availability (Layr-Labs#436)
Browse files Browse the repository at this point in the history
Co-authored-by: Siddharth More <Siddhi More>
  • Loading branch information
siddimore authored Apr 4, 2024
1 parent 20051ff commit 812aefa
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 63 deletions.
10 changes: 6 additions & 4 deletions disperser/cmd/dataapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type Config struct {
BLSOperatorStateRetrieverAddr string
EigenDAServiceManagerAddr string

DisperserHostname string
ChurnerHostname string
DisperserHostname string
ChurnerHostname string
BatcherHealthEndpt string
}

func NewConfig(ctx *cli.Context) (Config, error) {
Expand Down Expand Up @@ -63,8 +64,9 @@ func NewConfig(ctx *cli.Context) (Config, error) {
HTTPPort: ctx.GlobalString(flags.MetricsHTTPPort.Name),
EnableMetrics: ctx.GlobalBool(flags.EnableMetricsFlag.Name),
},
DisperserHostname: ctx.GlobalString(flags.DisperserHostnameFlag.Name),
ChurnerHostname: ctx.GlobalString(flags.ChurnerHostnameFlag.Name),
DisperserHostname: ctx.GlobalString(flags.DisperserHostnameFlag.Name),
ChurnerHostname: ctx.GlobalString(flags.ChurnerHostnameFlag.Name),
BatcherHealthEndpt: ctx.GlobalString(flags.BatcherHealthEndptFlag.Name),
}
return config, nil
}
7 changes: 7 additions & 0 deletions disperser/cmd/dataapi/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ var (
Required: true,
EnvVar: common.PrefixEnvVar(envVarPrefix, "EIGENDA_CHURNER_HOSTNAME"),
}
BatcherHealthEndptFlag = cli.StringFlag{
Name: common.PrefixFlag(FlagPrefix, "eigenda-batcher-health-endpoint"),
Usage: "Endpt of EigenDA Batcher Health Sidecar",
Required: true,
EnvVar: common.PrefixEnvVar(envVarPrefix, "EIGENDA_BATCHER_HEALTH_ENDPOINT"),
}
/* Optional Flags*/
MetricsHTTPPort = cli.StringFlag{
Name: common.PrefixFlag(FlagPrefix, "metrics-http-port"),
Expand All @@ -143,6 +149,7 @@ var requiredFlags = []cli.Flag{
EnableMetricsFlag,
DisperserHostnameFlag,
ChurnerHostnameFlag,
BatcherHealthEndptFlag,
}

var optionalFlags = []cli.Flag{
Expand Down
12 changes: 7 additions & 5 deletions disperser/cmd/dataapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ func RunDataApi(ctx *cli.Context) error {
metrics = dataapi.NewMetrics(blobMetadataStore, config.MetricsConfig.HTTPPort, logger)
server = dataapi.NewServer(
dataapi.Config{
ServerMode: config.ServerMode,
SocketAddr: config.SocketAddr,
AllowOrigins: config.AllowOrigins,
DisperserHostname: config.DisperserHostname,
ChurnerHostname: config.ChurnerHostname,
ServerMode: config.ServerMode,
SocketAddr: config.SocketAddr,
AllowOrigins: config.AllowOrigins,
DisperserHostname: config.DisperserHostname,
ChurnerHostname: config.ChurnerHostname,
BatcherHealthEndpt: config.BatcherHealthEndpt,
},
sharedStorage,
promClient,
Expand All @@ -111,6 +112,7 @@ func RunDataApi(ctx *cli.Context) error {
metrics,
nil,
nil,
nil,
)
)

Expand Down
11 changes: 6 additions & 5 deletions disperser/dataapi/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package dataapi

type Config struct {
SocketAddr string
ServerMode string
AllowOrigins []string
DisperserHostname string
ChurnerHostname string
SocketAddr string
ServerMode string
AllowOrigins []string
DisperserHostname string
ChurnerHostname string
BatcherHealthEndpt string
}
37 changes: 37 additions & 0 deletions disperser/dataapi/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,43 @@ const docTemplate = `{
}
}
},
"/metrics/batcher-service-availability": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Batcher Availability"
],
"summary": "Get status of EigenDA batcher.",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dataapi.ServiceAvailabilityResponse"
}
},
"400": {
"description": "error: Bad request",
"schema": {
"$ref": "#/definitions/dataapi.ErrorResponse"
}
},
"404": {
"description": "error: Not found",
"schema": {
"$ref": "#/definitions/dataapi.ErrorResponse"
}
},
"500": {
"description": "error: Server error",
"schema": {
"$ref": "#/definitions/dataapi.ErrorResponse"
}
}
}
}
},
"/metrics/churner-service-availability": {
"get": {
"produces": [
Expand Down
37 changes: 37 additions & 0 deletions disperser/dataapi/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,43 @@
}
}
},
"/metrics/batcher-service-availability": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Batcher Availability"
],
"summary": "Get status of EigenDA batcher.",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dataapi.ServiceAvailabilityResponse"
}
},
"400": {
"description": "error: Bad request",
"schema": {
"$ref": "#/definitions/dataapi.ErrorResponse"
}
},
"404": {
"description": "error: Not found",
"schema": {
"$ref": "#/definitions/dataapi.ErrorResponse"
}
},
"500": {
"description": "error: Server error",
"schema": {
"$ref": "#/definitions/dataapi.ErrorResponse"
}
}
}
}
},
"/metrics/churner-service-availability": {
"get": {
"produces": [
Expand Down
24 changes: 24 additions & 0 deletions disperser/dataapi/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,30 @@ paths:
summary: Fetch metrics
tags:
- Metrics
/metrics/batcher-service-availability:
get:
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/dataapi.ServiceAvailabilityResponse'
"400":
description: 'error: Bad request'
schema:
$ref: '#/definitions/dataapi.ErrorResponse'
"404":
description: 'error: Not found'
schema:
$ref: '#/definitions/dataapi.ErrorResponse'
"500":
description: 'error: Server error'
schema:
$ref: '#/definitions/dataapi.ErrorResponse'
summary: Get status of EigenDA batcher.
tags:
- Batcher Availability
/metrics/churner-service-availability:
get:
produces:
Expand Down
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.eigenDAServiceChecker.CheckHealth(ctx, serviceName)
response, err := s.eigenDAGRPCServiceChecker.CheckHealth(ctx, serviceName)
if err != nil {

if err.Error() == "disperser connection is nil" {
Expand Down Expand Up @@ -74,7 +74,7 @@ func (s *server) getServiceAvailability(ctx context.Context, services []string)
return availabilityStatuses, nil
}

func NewEigenDAServiceHealthCheck(grpcConnection GRPCConn, disperserHostName, churnerHostName string) EigenDAServiceChecker {
func NewEigenDAServiceHealthCheck(grpcConnection GRPCConn, disperserHostName, churnerHostName string) EigenDAGRPCServiceChecker {

// Create Pre-configured connections to the services
// Saves from having to create new connection on each request
Expand Down
50 changes: 50 additions & 0 deletions disperser/dataapi/http_service_availability_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package dataapi

import (
"context"
"net/http"
)

// Simple struct with a Service Name and its HealthEndPt.
type HttpServiceAvailabilityCheck struct {
ServiceName string
HealthEndPt 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 := s.eigenDAHttpServiceChecker.CheckHealth(service.HealthEndPt)
if err != nil {
s.logger.Error("Error querying service health:", "err", err)
}

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
}
Loading

0 comments on commit 812aefa

Please sign in to comment.