Skip to content

Commit

Permalink
PMM-13409 Fix update status failure after upgrade (#3234)
Browse files Browse the repository at this point in the history
* PMM-13409 Fix update:getStatus failure after upgrade

* PMM-13409 remove the token after upgrade

* PMM-13409 fix the system attribute

* Update managed/services/server/updater.go

Co-authored-by: Michael Okoko <[email protected]>

* PMM-13409 do not depend on `IsRunning` flag to ship the logs

* PMM-13409 get rid of the redundant task

* PMM-13409 Correctly handle done status for updates

* PMM-13409 Increase refetch interval to 1 sec

---------

Co-authored-by: Michael Okoko <[email protected]>
Co-authored-by: Matej Kubinec <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent 92800f8 commit 6e8faed
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
7 changes: 6 additions & 1 deletion build/ansible/roles/initialization/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
method: GET
retries: 20
delay: 5
ignore_errors: yes
ignore_errors: true

- name: init admin password on AMI
include_role:
Expand All @@ -139,4 +139,9 @@
file:
state: absent
path: /usr/share/pmm-server/maintenance/maintenance.html

- name: Remove the file provisioned by 'getStatus'
file:
state: absent
path: /srv/pmm-update.json
when: need_initialization or need_upgrade
16 changes: 10 additions & 6 deletions managed/services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type Params struct {

// NewServer returns new server for Server service.
func NewServer(params *Params) (*Server, error) {
path := os.TempDir()
path := "/srv"
if _, err := os.Stat(path); err != nil {
return nil, errors.WithStack(err)
}
Expand Down Expand Up @@ -359,6 +359,12 @@ func (s *Server) StartUpdate(ctx context.Context, req *serverv1.StartUpdateReque

// UpdateStatus returns PMM Server update status.
func (s *Server) UpdateStatus(ctx context.Context, req *serverv1.UpdateStatusRequest) (*serverv1.UpdateStatusResponse, error) {
if _, err := os.Stat(s.pmmUpdateAuthFile); err != nil && os.IsNotExist(err) {
return &serverv1.UpdateStatusResponse{
Done: true,
}, nil
}

token, err := s.readUpdateAuthToken()
if err != nil {
return nil, err
Expand All @@ -370,12 +376,10 @@ func (s *Server) UpdateStatus(ctx context.Context, req *serverv1.UpdateStatusReq
// wait up to 30 seconds for new log lines
var lines []string
var newOffset uint32
var done bool
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
for ctx.Err() == nil {
done = !s.updater.IsRunning()
if done {
if !s.updater.IsRunning() {
// give supervisord a second to flush logs to file
time.Sleep(time.Second)
}
Expand All @@ -385,7 +389,7 @@ func (s *Server) UpdateStatus(ctx context.Context, req *serverv1.UpdateStatusReq
s.l.Warn(err)
}

if len(lines) != 0 || done {
if len(lines) != 0 {
break
}

Expand All @@ -395,7 +399,7 @@ func (s *Server) UpdateStatus(ctx context.Context, req *serverv1.UpdateStatusReq
return &serverv1.UpdateStatusResponse{
LogLines: lines,
LogOffset: newOffset,
Done: done,
Done: false,
}, nil
}

Expand Down
1 change: 0 additions & 1 deletion managed/services/server/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ func (up *Updater) latest(ctx context.Context) ([]*version.DockerVersionInfo, *v
}

func (up *Updater) readFromFile() (*version.DockerVersionInfo, error) {
// Read from file, if it's not exist read from ENV variable, if it's not exist get the latest tag from DockerHub.
content, err := os.ReadFile(fileName)
if err != nil && !os.IsNotExist(err) {
up.l.WithError(err).Error("Failed to read file")
Expand Down
7 changes: 0 additions & 7 deletions ui/src/pages/updates/update-card/UpdateCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ import { KeyboardDoubleArrowUp } from '@mui/icons-material';
import { UpdateInfo } from '../update-info';
import { UpdateInProgressCard } from '../update-in-progress-card';
import { useUpdates } from 'contexts/updates';
import { useWaitForReadiness } from 'hooks/api/useReadiness';
import { ChangeLog } from '../change-log';

export const UpdateCard: FC = () => {
const { inProgress, status, setStatus } = useUpdates();
const { isLoading, data, error, isRefetching, refetch } = useCheckUpdates();
const { mutate: startUpdate } = useStartUpdate();
const [authToken, setAuthToken] = useState<string>();
const { waitForReadiness } = useWaitForReadiness();

const handleStartUpdate = async () => {
setStatus(UpdateStatus.Updating);
Expand All @@ -41,11 +39,6 @@ export const UpdateCard: FC = () => {
if (response) {
setStatus(UpdateStatus.Restarting);
setAuthToken(response.authToken);

// TODO: temporary till the done status works correctly on get status
waitForReadiness().then(() => {
setStatus(UpdateStatus.Completed);
});
}
},
onError: () => {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/pages/updates/update-log/UpdateLog.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useUpdateLog = (authToken: string) => {

return getUpdateStatus({ authToken, logOffset });
},
refetchInterval: 500,
refetchInterval: ({ state }) => (state.data?.done ? 0 : 1000),
});

useEffect(() => {
Expand Down

0 comments on commit 6e8faed

Please sign in to comment.