3434
3535var childProcPathFmt = "/proc/%[1]v/task/%[1]v/children"
3636
37- //go :generate go run github.com/maxbrunsfeld/counterfeiter/v6 . nginxPlusClient
37+ //counterfeiter :generate . nginxPlusClient
3838
3939type nginxPlusClient interface {
4040 UpdateHTTPServers (
@@ -49,21 +49,19 @@ type nginxPlusClient interface {
4949 GetUpstreams () (* ngxclient.Upstreams , error )
5050}
5151
52- //go :generate go run github.com/maxbrunsfeld/counterfeiter/v6 . ProcessHandler
52+ //counterfeiter :generate . ProcessHandler
5353
5454type ProcessHandler interface {
5555 FindMainProcess (
5656 ctx context.Context ,
57- checkFile CheckFileFunc ,
58- readFile ReadFileFunc ,
5957 timeout time.Duration ,
6058 ) (int , error )
61- ReadFile (file string ) ([]byte , error )
59+ readFile (file string ) ([]byte , error )
6260 Kill (pid int ) error
6361 EnsureNginxRunning (ctx context.Context ) error
6462}
6563
66- //go :generate go run github.com/maxbrunsfeld/counterfeiter/v6 . Manager
64+ //counterfeiter :generate . Manager
6765
6866// Manager manages the runtime of NGINX.
6967type Manager interface {
@@ -79,9 +77,9 @@ type Manager interface {
7977 GetUpstreams () (ngxclient.Upstreams , error )
8078}
8179
82- //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . MetricsCollector
83-
8480// MetricsCollector is an interface for the metrics of the NGINX runtime manager.
81+ //
82+ //counterfeiter:generate . MetricsCollector
8583type MetricsCollector interface {
8684 IncReloadCount ()
8785 IncReloadErrors ()
@@ -122,13 +120,13 @@ func (m *ManagerImpl) IsPlus() bool {
122120func (m * ManagerImpl ) Reload (ctx context.Context , configVersion int ) error {
123121 start := time .Now ()
124122 // We find the main NGINX PID on every reload because it will change if the NGINX container is restarted.
125- pid , err := m .processHandler .FindMainProcess (ctx , os . Stat , os . ReadFile , pidFileTimeout )
123+ pid , err := m .processHandler .FindMainProcess (ctx , pidFileTimeout )
126124 if err != nil {
127125 return fmt .Errorf ("failed to find NGINX main process: %w" , err )
128126 }
129127
130128 childProcFile := fmt .Sprintf (childProcPathFmt , pid )
131- previousChildProcesses , err := m .processHandler .ReadFile (childProcFile )
129+ previousChildProcesses , err := m .processHandler .readFile (childProcFile )
132130 if err != nil {
133131 return err
134132 }
@@ -191,20 +189,18 @@ func (m *ManagerImpl) GetUpstreams() (ngxclient.Upstreams, error) {
191189 return * upstreams , nil
192190}
193191
194- type ProcessHandlerImpl struct {}
192+ type NewProcessHandlerImpl struct {}
195193
196194// EnsureNginxRunning ensures NGINX is running by locating the main process.
197- func (p * ProcessHandlerImpl ) EnsureNginxRunning (ctx context.Context ) error {
198- if _ , err := p .FindMainProcess (ctx , os . Stat , os . ReadFile , pidFileTimeout ); err != nil {
195+ func (p * NewProcessHandlerImpl ) EnsureNginxRunning (ctx context.Context ) error {
196+ if _ , err := p .FindMainProcess (ctx , pidFileTimeout ); err != nil {
199197 return fmt .Errorf ("failed to find NGINX main process: %w" , err )
200198 }
201199 return nil
202200}
203201
204- func (p * ProcessHandlerImpl ) FindMainProcess (
202+ func (p * NewProcessHandlerImpl ) FindMainProcess (
205203 ctx context.Context ,
206- checkFile CheckFileFunc ,
207- readFile ReadFileFunc ,
208204 timeout time.Duration ,
209205) (int , error ) {
210206 ctx , cancel := context .WithTimeout (ctx , timeout )
@@ -215,7 +211,7 @@ func (p *ProcessHandlerImpl) FindMainProcess(
215211 500 * time .Millisecond ,
216212 true , /* poll immediately */
217213 func (_ context.Context ) (bool , error ) {
218- _ , err := checkFile (PidFile )
214+ _ , err := p . checkFile (PidFile )
219215 if err == nil {
220216 return true , nil
221217 }
@@ -228,7 +224,7 @@ func (p *ProcessHandlerImpl) FindMainProcess(
228224 return 0 , err
229225 }
230226
231- content , err := readFile (PidFile )
227+ content , err := p . readFile (PidFile )
232228 if err != nil {
233229 return 0 , err
234230 }
@@ -241,10 +237,10 @@ func (p *ProcessHandlerImpl) FindMainProcess(
241237 return pid , nil
242238}
243239
244- func (p * ProcessHandlerImpl ) ReadFile (file string ) ([]byte , error ) {
245- return os . ReadFile (file )
240+ func (p * NewProcessHandlerImpl ) readFile (file string ) ([]byte , error ) {
241+ return p . readFile (file )
246242}
247243
248- func (p * ProcessHandlerImpl ) Kill (pid int ) error {
244+ func (p * NewProcessHandlerImpl ) Kill (pid int ) error {
249245 return syscall .Kill (pid , syscall .SIGHUP )
250246}
0 commit comments