MCPcopy
hub / github.com/dgraph-io/dgraph / containerHealthCheck

Method containerHealthCheck

dgraphtest/local_cluster.go:784–836  ·  view source on GitHub ↗
(url func(c *LocalCluster) (string, error))

Source from the content-addressed store, hash-verified

782}
783
784func (c *LocalCluster) containerHealthCheck(url func(c *LocalCluster) (string, error)) error {
785 endpoint, err := url(c)
786 if err != nil {
787 return errors.Wrapf(err, "error getting health URL %v", endpoint)
788 }
789
790 for attempt := range 120 {
791 time.Sleep(waitDurBeforeRetry)
792
793 endpoint, err = url(c)
794 if err != nil {
795 return errors.Wrap(err, "error getting health URL")
796 }
797
798 req, err := http.NewRequest(http.MethodGet, endpoint, nil)
799 if err != nil {
800 if attempt > 50 {
801 log.Printf("[WARNING] problem building req for endpoint [%v], err: [%v]", endpoint, err)
802 }
803 continue
804 }
805 body, err := dgraphapi.DoReq(req)
806 if err != nil {
807 if attempt > 50 {
808 log.Printf("[WARNING] problem hitting health endpoint [%v], err: [%v]", endpoint, err)
809 }
810 continue
811 }
812 resp := string(body)
813
814 // zero returns OK in the health check
815 if resp == "OK" {
816 return nil
817 }
818
819 // For Alpha, we always run alpha with EE features enabled
820 if !strings.Contains(resp, `"ee_features"`) {
821 continue
822 }
823 if c.conf.acl && !strings.Contains(resp, `"acl"`) {
824 continue
825 }
826 if err := c.waitUntilLogin(); err != nil {
827 return err
828 }
829 if err := c.waitUntilGraphqlHealthCheck(); err != nil {
830 return err
831 }
832 return nil
833 }
834
835 return fmt.Errorf("health failed, cluster took too long to come up [%v]", endpoint)
836}
837
838func (c *LocalCluster) waitUntilLogin() error {
839 if !c.conf.acl {

Callers 1

HealthCheckMethod · 0.95

Calls 4

waitUntilLoginMethod · 0.95
DoReqFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected