Created
May 24, 2024 15:15
-
-
Save Nashluffy/097e7df7d0a90b0cdefd2b87fb3129c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (s *SidecarAPI) Shutdown(r *http.Request) (interface{}, []error, *api.ApiError, func()) { | |
err := s.client.Quit(r.Context(), s.promURL) | |
if err != nil { | |
return internalError(fmt.Errorf("failed to quit prometheus: %w", err)) | |
} | |
db, err := tsdb.OpenDBReadOnly(s.dataDir, s.logger) | |
if err != nil { | |
return internalError(fmt.Errorf("failed to start read-only tsdb: %w", err)) | |
} | |
err = db.FlushWAL(s.dataDir) | |
if err != nil { | |
return internalError(fmt.Errorf("failed to flush WAL to disk: %w", err)) | |
} | |
uploaded, err := s.shipper.Sync(r.Context()) | |
if err != nil { | |
return internalError(fmt.Errorf("failed to upload block: %w", err)) | |
} | |
// as everything in WAL has been persisted to a block, clear it to avoid overlapping blocks | |
// if the prometheus instance starts again | |
walDir := s.dataDir + "/wal" | |
if err := os.RemoveAll(walDir); err != nil { | |
s.logger.Log("failed to remove wal directory", err.Error()) | |
} | |
return &flushResponse{BlocksUploaded: uploaded}, nil, nil, func() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment