forked from Layr-Labs/eigenda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DataApi] Add Batcher availability (Layr-Labs#436)
Co-authored-by: Siddharth More <Siddhi More>
- Loading branch information
Showing
11 changed files
with
370 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.