* feat: added build meta data to monitor * feat: added versioning to prime-monitor * feat: added logger package for prime-monitor * feat: implemented logging in cmd * feat: implemented moduled monorepo architecture * feat: added cron package for healthcheck * feat: added constants and modules for healthcheck * feat: added environment service getter method * feat: added environment service parser for parsing the recieved keys * feat: added environment service provider method * feat: added retry based executer for the test methods * feat: added http health check method and placeholders for redis & pg * feat: added tests for healthcheck methods * feat: added PerformHealthCheck Controller Method for execution of healthcheck controller * feat: added healthcheck test file for testing the healthcheck * feat: added healthcheck to work file * feat: added readme for healthcheck package * feat: created healthcheck register for prime scheduler * feat: added cron command for running cron subpart of monitor * feat: added prime schedule handler for cron * feat: added start command for starting up prime scheduler * feat: added build utility files for monitor * fix: goreleaser builds * feat: removed Redis method from healthcheck methods * feat: added docker file for building prime-monitor * feat: added flag for adding healthcheck duration for cron start * chore: removed redis as a healthcheck method * chore: modified actions to build monitor on branch build and docker images * feat: added monitor service in docker compose caddy * feat: added description for HealthCheckJob * fix: status code issue for reachable and non reachable * feat: added api package for connecting with prime api * feat: modified cmd package to report healthcheck status to prime * feat: added api types inside prime-monitor * feat: added message field for meta while status reporting * fix: modified constants for environment variables * feat: added monitor readme * fix: build-branch monitor content shift to build-branch-ee * chore: added build args on release * feat: remove version meta data from cli * fix: docker file changed to fix the build to default * fix: removed build flags from github branch build * fix: moved cron start to root level start cmd * fix: passed the recieved machine signature to api headers * feat: optimised docker build for monitor
3.5 KiB
Prime Healthcheck
Prime Healthcheck is a service that take care of checking for all the running services in the user's system. Internally the Prime Healthcheck makes network calls to each of the services that are provided in the environment variables.
Usage
PerformHealthCheck
PerformHealthCheck is the primary method that is responsible for perfoming the
health check over the services provided. Essentially PerformHealthCheck looks up
for environment variables provided with prefix SERVICE_, the format is along
the lines of SERVICE_TESTMETHOD_NAME where name is the name of the service,
the corresponding value to this would contain, the exact url to be called for
that service, without the protocol. The function returns two channel, which can
be used to recieve updates for healthchecks.
Function Signature
func (h *HealthCheckHandler) PerformHealthCheck(ctx context.Context, options HealthCheckOptions) (chan *HealthCheckStatus, chan *error)
package main
func main() {
// If you have to pass custom test methods
handler := HealthCheckHandler{
TestIdMethodMap: T_TestIdMethodMap,
TestIdStringMap: T_TestIdStringMap,
}
// If you want to use default test methods
handler := NewHealthCheckHandler()
t.Setenv(tt.ServiceName, tt.ServiceValue)
options := HealthCheckOptions{
ConfirmTries: 3,
MaxRetries: 1,
TimeoutDuration: 5 * time.Second,
RetryDuration: 1 * time.Second,
}
statusChannel, errorChannel := handler.PerformHealthCheck(ctx, options)
statuses := make([]HealthCheckStatus, 0)
errors := make([]error, 0)
for {
select {
case status, ok := <-statusChannel:
if !ok {
statusChannel = nil
} else {
statuses = append(statuses, *status)
}
case err, ok := <-errorChannel:
if !ok {
errorChannel = nil
} else {
errors = append(errors, *err)
cancel()
}
}
if statusChannel == nil && errorChannel == nil {
break
}
}
}
ExecuteHealthCheckWithRetries
ExecuteHealthCheckWithRetries is a method that performs the health check with retries.
It uses the provided test method and options to repeatedly check the health of a service
until it either succeeds or exhausts the retry attempts.
Function Signature
func (h *HealthCheckHandler) ExecuteHealthCheckWithRetries(ctx context.Context, testMethod HealthCheckMethod, options HealthCheckMethodOptions, wg *sync.WaitGroup, statusChannel chan *HealthCheckStatus, errorChannel chan *error)
GetServiceFromEnvironment
GetServiceFromEnvironment retrieves a map of services from the environment variables.
It filters the environment variables to only include those with the prefix SERVICE_ and
parses them into a map of service names to ServiceData.
Function Signature
func (h *HealthCheckHandler) GetServiceFromEnvironment() (map[string]*ServiceData, error)
ParseKeyValue
ParseKeyValue parses a key-value pair from the environment variables into a service
name and ServiceData. It splits the key and value into their respective components
and validates them.
Function Signature
func (h *HealthCheckHandler) ParseKeyValue(key string, value string) (string, *ServiceData, error)
GetEnvironmentVarMap
GetEnvironmentVarMap retrieves all environment variables and returns them as a map
of key-value pairs. It filters out any empty or commented-out variables.
Function Signature
func GetEnvironmentVarMap() map[string]string
... For understanding more, please read healthcheck.go and healthcheck_method.go