// Get latest convergence state and send notifications func monitorConverged(lastConverged bool, lastEventAt time.Time) (bool, ecs.ServiceEvent) { log := logger.New("ns=services_monitor") services, err := models.ClusterServices() if err != nil { log.Log("fn=monitorConverged err=%q", err) return lastConverged, ecs.ServiceEvent{ CreatedAt: aws.Time(lastEventAt), } } converged := services.IsConverged() events := services.EventsSince(lastEventAt) log.Log("fn=monitorConverged converged=%t events=%d lastEventAt=%q", converged, len(events), lastEventAt) if events.HasCapacityWarning() { models.NotifyError("rack:capacity", fmt.Errorf(events.CapacityWarning()), map[string]string{ "rack": os.Getenv("RACK"), }) } if converged != lastConverged { models.NotifySuccess("rack:converge", map[string]string{ "rack": os.Getenv("RACK"), "converged": fmt.Sprintf("%t", converged), }) } return converged, services.LastEvent() }
func getClusterServices() (models.ECSServices, error) { os.Setenv("RACK", "convox-test") os.Setenv("CLUSTER", "convox-test") stubAws := test.StubAws( test.HttpdListServicesCycle(), test.HttpdDescribeServicesCycle(), ) defer stubAws.Close() return models.ClusterServices() }
// Get initial convergence state func checkConverged() (bool, ecs.ServiceEvent) { log := logger.New("ns=services_monitor") services, err := models.ClusterServices() if err != nil { log.Log("fn=checkConverged err=%q", err) return true, ecs.ServiceEvent{ CreatedAt: aws.Time(time.Now()), } } converged := services.IsConverged() lastEvent := services.LastEvent() log.Log("fn=checkConverged converged=%t lastEventAt=%q", converged, lastEvent.CreatedAt) return converged, lastEvent }