func (s *Server) doStatusPage(w http.ResponseWriter, r *http.Request) (_ string, err error) {
	defer derrors.Wrap(&err, "doStatusPage")
	const pageSize = 20
	var (
		next, failures, recents []*internal.ModuleVersionState
		stats                   *postgres.VersionStats
		experiments             []*internal.Experiment
		excluded                []string
	)
	type annotation struct {
		error
		msg string
	}
	g, ctx := errgroup.WithContext(r.Context())
	g.Go(func() error {
		var err error
		next, err = s.db.GetNextModulesToFetch(ctx, pageSize)
		if err != nil {
			return annotation{err, "error fetching next versions"}
		}
		return nil
	})
	g.Go(func() error {
		var err error
		failures, err = s.db.GetRecentFailedVersions(ctx, pageSize)
		if err != nil {
			return annotation{err, "error fetching recent failures"}
		}
		return nil
	})
	g.Go(func() error {
		var err error
		recents, err = s.db.GetRecentVersions(ctx, pageSize)
		if err != nil {
			return annotation{err, "error fetching recent versions"}
		}
		return nil
	})
	g.Go(func() error {
		var err error
		stats, err = s.db.GetVersionStats(ctx)
		if err != nil {
			return annotation{err, "error fetching stats"}
		}
		return nil
	})
	g.Go(func() error {
		var err error
		experiments, err = s.db.GetExperiments(ctx)
		if err != nil {
			return annotation{err, "error fetching experiments"}
		}
		return nil
	})
	g.Go(func() error {
		var err error
		excluded, err = s.db.GetExcludedPrefixes(ctx)
		if err != nil {
			return annotation{err, "error fetching excluded"}
		}
		return nil
	})
	if err := g.Wait(); err != nil {
		var e annotation
		if errors.As(err, &e) {
			return e.msg, err
		}
		return "", err
	}

	type count struct {
		Code  int
		Desc  string
		Count int
	}
	var counts []*count
	for code, n := range stats.VersionCounts {
		c := &count{Code: code, Count: n}
		if e := derrors.FromHTTPStatus(code, ""); e != nil && e != derrors.Unknown {
			c.Desc = e.Error()
		}
		counts = append(counts, c)
	}
	sort.Slice(counts, func(i, j int) bool { return counts[i].Code < counts[j].Code })

	var env string
	switch s.cfg.ServiceID {
	case "":
		env = "Local"
	case "dev-etl":
		env = "Dev"
	case "staging-etl":
		env = "Staging"
	case "etl":
		env = "Prod"
	}
	page := struct {
		Config                       *config.Config
		Env                          string
		ResourcePrefix               string
		LatestTimestamp              *time.Time
		Counts                       []*count
		Next, Recent, RecentFailures []*internal.ModuleVersionState
		Experiments                  []*internal.Experiment
		Excluded                     []string
	}{
		Config:          s.cfg,
		Env:             env,
		ResourcePrefix:  strings.ToLower(env) + "-",
		LatestTimestamp: &stats.LatestTimestamp,
		Counts:          counts,
		Next:            next,
		Recent:          recents,
		RecentFailures:  failures,
		Experiments:     experiments,
		Excluded:        excluded,
	}
	var buf bytes.Buffer
	if err := s.indexTemplate.Execute(&buf, page); err != nil {
		return "error rendering template", err
	}
	if _, err := io.Copy(w, &buf); err != nil {
		log.Errorf(ctx, "Error copying buffer to ResponseWriter: %v", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
	}
	return "", nil
}
// doStatusPage writes the status page. On error it returns the error and a short
// string to be written back to the client.
doStatusPage writes the status page. On error it returns the error and a short
string to be written back to the client.
// doStatusPage writes the status page . On error it returns the error and a short // string to be written back to the client .
func (s *Server) doStatusPage(w http.ResponseWriter, r *http.Request) (_ string, err error) {
	defer derrors.Wrap(&err, "doStatusPage")
	const pageSize = 20
	var (
		next, failures, recents []*internal.ModuleVersionState
		stats                   *postgres.VersionStats
		experiments             []*internal.Experiment
		excluded                []string
	)
	type annotation struct {
		error
		msg string
	}
	g, ctx := errgroup.WithContext(r.Context())
	g.Go(func() error {
		var err error
		next, err = s.db.GetNextModulesToFetch(ctx, pageSize)
		if err != nil {
			return annotation{err, "error fetching next versions"}
		}
		return nil
	})
	g.Go(func() error {
		var err error
		failures, err = s.db.GetRecentFailedVersions(ctx, pageSize)
		if err != nil {
			return annotation{err, "error fetching recent failures"}
		}
		return nil
	})
	g.Go(func() error {
		var err error
		recents, err = s.db.GetRecentVersions(ctx, pageSize)
		if err != nil {
			return annotation{err, "error fetching recent versions"}
		}
		return nil
	})
	g.Go(func() error {
		var err error
		stats, err = s.db.GetVersionStats(ctx)
		if err != nil {
			return annotation{err, "error fetching stats"}
		}
		return nil
	})
	g.Go(func() error {
		var err error
		experiments, err = s.db.GetExperiments(ctx)
		if err != nil {
			return annotation{err, "error fetching experiments"}
		}
		return nil
	})
	g.Go(func() error {
		var err error
		excluded, err = s.db.GetExcludedPrefixes(ctx)
		if err != nil {
			return annotation{err, "error fetching excluded"}
		}
		return nil
	})
	if err := g.Wait(); err != nil {
		var e annotation
		if errors.As(err, &e) {
			return e.msg, err
		}
		return "", err
	}
	type count struct {
		Code  int
		Desc  string
		Count int
	}
	var counts []*count
	for code, n := range stats.VersionCounts {
		c := &count{Code: code, Count: n}
		if e := derrors.FromHTTPStatus(code, ""); e != nil && e != derrors.Unknown {
			c.Desc = e.Error()
		}
		counts = append(counts, c)
	}
	sort.Slice(counts, func(i, j int) bool { return counts[i].Code < counts[j].Code })
	var env string
	switch s.cfg.ServiceID {
	case "":
		env = "Local"
	case "dev-etl":
		env = "Dev"
	case "staging-etl":
		env = "Staging"
	case "etl":
		env = "Prod"
	}
	page := struct {
		Config                       *config.Config
		Env                          string
		ResourcePrefix               string
		LatestTimestamp              *time.Time
		Counts                       []*count
		Next, Recent, RecentFailures []*internal.ModuleVersionState
		Experiments                  []*internal.Experiment
		Excluded                     []string
	}{
		Config:          s.cfg,
		Env:             env,
		ResourcePrefix:  strings.ToLower(env) + "-",
		LatestTimestamp: &stats.LatestTimestamp,
		Counts:          counts,
		Next:            next,
		Recent:          recents,
		RecentFailures:  failures,
		Experiments:     experiments,
		Excluded:        excluded,
	}
	var buf bytes.Buffer
	if err := s.indexTemplate.Execute(&buf, page); err != nil {
		return "error rendering template", err
	}
	if _, err := io.Copy(w, &buf); err != nil {
		log.Errorf(ctx, "Error copying buffer to ResponseWriter: %v", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
	}
	return "", nil
}
func ( s * Server ) doStatusPage ( w http . ResponseWriter , r * http . Request ) ( _ string , err error ) { defer derrors . Wrap ( & err , " " ) const pageSize = 20 var ( next , failures , recents [ ] * internal . ModuleVersionState stats * postgres . VersionStats experiments [ ] * internal . Experiment excluded [ ] string ) type annotation struct { error msg string } g , ctx := errgroup . WithContext ( r . Context ( ) ) g . Go ( func ( ) error { var err error next , err = s . db . GetNextModulesToFetch ( ctx , pageSize ) if err != nil { return annotation { err , " " } } return nil } ) g . Go ( func ( ) error { var err error failures , err = s . db . GetRecentFailedVersions ( ctx , pageSize ) if err != nil { return annotation { err , " " } } return nil } ) g . Go ( func ( ) error { var err error recents , err = s . db . GetRecentVersions ( ctx , pageSize ) if err != nil { return annotation { err , " " } } return nil } ) g . Go ( func ( ) error { var err error stats , err = s . db . GetVersionStats ( ctx ) if err != nil { return annotation { err , " " } } return nil } ) g . Go ( func ( ) error { var err error experiments , err = s . db . GetExperiments ( ctx ) if err != nil { return annotation { err , " " } } return nil } ) g . Go ( func ( ) error { var err error excluded , err = s . db . GetExcludedPrefixes ( ctx ) if err != nil { return annotation { err , " " } } return nil } ) if err := g . Wait ( ) ; err != nil { var e annotation if errors . As ( err , & e ) { return e . msg , err } return " " , err } type count struct { Code int Desc string Count int } var counts [ ] * count for code , n := range stats . VersionCounts { c := & count { Code : code , Count : n } if e := derrors . FromHTTPStatus ( code , " " ) ; e != nil && e != derrors . Unknown { c . Desc = e . Error ( ) } counts = append ( counts , c ) } sort . Slice ( counts , func ( i , j int ) bool { return counts [ i ] . Code < counts [ j ] . Code } ) var env string switch s . cfg . ServiceID { case " " : env = " " case " " : env = " " case " " : env = " " case " " : env = " " } page := struct { Config * config . Config Env string ResourcePrefix string LatestTimestamp * time . Time Counts [ ] * count Next , Recent , RecentFailures [ ] * internal . ModuleVersionState Experiments [ ] * internal . Experiment Excluded [ ] string } { Config : s . cfg , Env : env , ResourcePrefix : strings . ToLower ( env ) + " " , LatestTimestamp : & stats . LatestTimestamp , Counts : counts , Next : next , Recent : recents , RecentFailures : failures , Experiments : experiments , Excluded : excluded , } var buf bytes . Buffer if err := s . indexTemplate . Execute ( & buf , page ) ; err != nil { return " " , err } if _ , err := io . Copy ( w , & buf ) ; err != nil { log . Errorf ( ctx , " " , err ) http . Error ( w , http . StatusText ( http . StatusInternalServerError ) , http . StatusInternalServerError ) } return " " , nil }
doStatusPage writes the status page.
doStatusPage writes the status page .