improve access to controller info
This commit is contained in:
parent
6a032bfaa2
commit
6cd18ff1fd
3 changed files with 17 additions and 25 deletions
|
|
@ -115,10 +115,7 @@ func (a *APIController) handleWorkflowJobEvent(w http.ResponseWriter, r *http.Re
|
|||
signature := r.Header.Get("X-Hub-Signature-256")
|
||||
hookType := r.Header.Get("X-Github-Hook-Installation-Target-Type")
|
||||
|
||||
controllerInfo, err := a.r.GetControllerInfo(r.Context())
|
||||
if err != nil {
|
||||
log.Printf("failed to get controller info for metics labels: %q", err)
|
||||
}
|
||||
controllerInfo := a.r.GetControllerInfo(r.Context())
|
||||
|
||||
if err := a.r.DispatchWorkflowJob(hookType, signature, body); err != nil {
|
||||
if errors.Is(err, gErrors.ErrNotFound) {
|
||||
|
|
|
|||
|
|
@ -37,11 +37,7 @@ func (c *GarmCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
}
|
||||
|
||||
func (c *GarmCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
controllerInfo, err := c.runner.GetControllerInfo(auth.GetAdminContext())
|
||||
if err != nil {
|
||||
log.Printf("error on fetching controllerInfo: %s", err)
|
||||
// continue anyway
|
||||
}
|
||||
controllerInfo := c.runner.GetControllerInfo(auth.GetAdminContext())
|
||||
|
||||
c.CollectInstanceMetric(ch, controllerInfo.Hostname, controllerInfo.ControllerID.String())
|
||||
c.CollectHealthMetric(ch, controllerInfo.Hostname, controllerInfo.ControllerID.String())
|
||||
|
|
|
|||
|
|
@ -66,6 +66,10 @@ func NewRunner(ctx context.Context, cfg config.Config) (*Runner, error) {
|
|||
creds[ghcreds.Name] = ghcreds
|
||||
}
|
||||
|
||||
controllerInfo := params.ControllerInfo{
|
||||
ControllerID: ctrlId.ControllerID,
|
||||
}
|
||||
|
||||
poolManagerCtrl := &poolManagerCtrl{
|
||||
controllerID: ctrlId.ControllerID.String(),
|
||||
config: cfg,
|
||||
|
|
@ -81,6 +85,7 @@ func NewRunner(ctx context.Context, cfg config.Config) (*Runner, error) {
|
|||
poolManagerCtrl: poolManagerCtrl,
|
||||
providers: providers,
|
||||
credentials: creds,
|
||||
controllerInfo: controllerInfo,
|
||||
}
|
||||
|
||||
if err := runner.loadReposOrgsAndEnterprises(); err != nil {
|
||||
|
|
@ -268,23 +273,17 @@ type Runner struct {
|
|||
controllerInfo params.ControllerInfo
|
||||
}
|
||||
|
||||
func (r *Runner) GetControllerInfo(ctx context.Context) (params.ControllerInfo, error) {
|
||||
if r.controllerInfo == (params.ControllerInfo{}) {
|
||||
var err error
|
||||
r.controllerInfo, err = r.store.ControllerInfo()
|
||||
if err != nil {
|
||||
return params.ControllerInfo{}, errors.Wrap(err, "fetching controller info")
|
||||
}
|
||||
// GetControllerInfo returns the controller id and the hostname.
|
||||
// This data might be used in metrics and logging.
|
||||
func (r *Runner) GetControllerInfo(ctx context.Context) params.ControllerInfo {
|
||||
// hostname could change
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
log.Printf("error getting hostname: %v", err)
|
||||
//not much choice but to continue
|
||||
}
|
||||
if r.controllerInfo.Hostname == "" {
|
||||
var err error
|
||||
r.controllerInfo.Hostname, err = os.Hostname()
|
||||
if err != nil {
|
||||
// this returns a partial controller info, but it's better than nothing
|
||||
return r.controllerInfo, errors.Wrap(err, "fetching hostname")
|
||||
}
|
||||
}
|
||||
return r.controllerInfo, nil
|
||||
r.controllerInfo.Hostname = hostname
|
||||
return r.controllerInfo
|
||||
}
|
||||
|
||||
func (r *Runner) ListCredentials(ctx context.Context) ([]params.GithubCredentials, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue