github.com/verrazzano/verrazzano@v1.7.1/tools/psr/backend/spi/worker.go (about) 1 // Copyright (c) 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package spi 5 6 import ( 7 "github.com/prometheus/client_golang/prometheus" 8 "github.com/verrazzano/verrazzano/pkg/log/vzlog" 9 "github.com/verrazzano/verrazzano/tools/psr/backend/config" 10 "github.com/verrazzano/verrazzano/tools/psr/backend/osenv" 11 ) 12 13 // WorkerDesc contains basic information about a worker 14 type WorkerDesc struct { 15 // WorkerType returns the worker type specified by the Env var 16 WorkerType string 17 18 // Description returns a description of the worker 19 Description string 20 21 // MetricsPrefix returns the worker prefix used for metrics 22 MetricsPrefix string 23 } 24 25 // Worker is an interface that must be implemented by all workers 26 type Worker interface { 27 28 // PreconditionsMet Checks for any worker preconditions to ensure they are met before DoWork() can be called; 29 // returns true if any preconditions are met, or an error if there is an unrecoverable issue 30 PreconditionsMet() (bool, error) 31 32 // GetWorkerDesc returns the WorkerDesc for the worker 33 GetWorkerDesc() WorkerDesc 34 35 // GetEnvDescList get the Environment variable descriptors used for worker configuration 36 GetEnvDescList() []osenv.EnvVarDesc 37 38 // DoWork implements the worker use case 39 DoWork(config.CommonConfig, vzlog.VerrazzanoLogger) error 40 41 // WantLoopInfoLogged returns true if the runner should log information for each loop 42 WantLoopInfoLogged() bool 43 44 // WorkerMetricsProvider is an interface to get prometheus metrics information for the worker 45 WorkerMetricsProvider 46 } 47 48 // WorkerMetricsProvider is an interface that provides Prometheus metrics information 49 type WorkerMetricsProvider interface { 50 // GetMetricDescList returns the prometheus metrics descriptors for the worker metrics. Must be thread safe 51 GetMetricDescList() []prometheus.Desc 52 53 // GetMetricList returns the realtime metrics for the worker. Must be thread safe 54 GetMetricList() []prometheus.Metric 55 }