mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-03 20:17:59 +00:00 
			
		
		
		
	backport of commit 00855a9e7a (#20622)
				
					
				
			Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com>
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							e08ca7dbf6
						
					
				
				
					commit
					99f55c11be
				
			
							
								
								
									
										4
									
								
								changelog/20609.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								changelog/20609.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					```release-note:improvement
 | 
				
			||||||
 | 
					command/server: Add support for dumping pprof files to the filesystem via SIGUSR2 when 
 | 
				
			||||||
 | 
					`VAULT_PPROF_WRITE_TO_FILE=true` is set on the server.
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
@@ -1681,6 +1681,44 @@ func (c *ServerCommand) Run(args []string) int {
 | 
				
			|||||||
				c.logger.Info(fmt.Sprintf("Wrote stacktrace to: %s", f.Name()))
 | 
									c.logger.Info(fmt.Sprintf("Wrote stacktrace to: %s", f.Name()))
 | 
				
			||||||
				f.Close()
 | 
									f.Close()
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// We can only get pprof outputs via the API but sometimes Vault can get
 | 
				
			||||||
 | 
								// into a state where it cannot process requests so we can get pprof outputs
 | 
				
			||||||
 | 
								// via SIGUSR2.
 | 
				
			||||||
 | 
								if os.Getenv("VAULT_PPROF_WRITE_TO_FILE") != "" {
 | 
				
			||||||
 | 
									dir := ""
 | 
				
			||||||
 | 
									path := os.Getenv("VAULT_PPROF_FILE_PATH")
 | 
				
			||||||
 | 
									if path != "" {
 | 
				
			||||||
 | 
										if _, err := os.Stat(path); err != nil {
 | 
				
			||||||
 | 
											c.logger.Error("Checking pprof path failed", "error", err)
 | 
				
			||||||
 | 
											continue
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										dir = path
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										dir, err = os.MkdirTemp("", "vault-pprof")
 | 
				
			||||||
 | 
										if err != nil {
 | 
				
			||||||
 | 
											c.logger.Error("Could not create temporary directory for pprof", "error", err)
 | 
				
			||||||
 | 
											continue
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									dumps := []string{"goroutine", "heap", "allocs", "threadcreate"}
 | 
				
			||||||
 | 
									for _, dump := range dumps {
 | 
				
			||||||
 | 
										pFile, err := os.Create(filepath.Join(dir, dump))
 | 
				
			||||||
 | 
										if err != nil {
 | 
				
			||||||
 | 
											c.logger.Error("error creating pprof file", "name", dump, "error", err)
 | 
				
			||||||
 | 
											break
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										err = pprof.Lookup(dump).WriteTo(pFile, 0)
 | 
				
			||||||
 | 
										if err != nil {
 | 
				
			||||||
 | 
											c.logger.Error("error generating pprof data", "name", dump, "error", err)
 | 
				
			||||||
 | 
											break
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									c.logger.Info(fmt.Sprintf("Wrote pprof files to: %s", dir))
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Notify systemd that the server is shutting down
 | 
						// Notify systemd that the server is shutting down
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user