Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateway/runservice: add api to delete step logs #157

Merged
merged 1 commit into from Nov 18, 2019

Conversation

camandel
Copy link
Contributor

A try to fix issue #41 for logs deletion.

@sgotti
Copy link
Member

sgotti commented Oct 31, 2019

@camandel Thanks for the PR! before reviewing, can you add some tests (as integration tests and runservice tests)?

Related agola-web issues: agola-io/agola-web#5 agola-io/agola-web#24

@camandel
Copy link
Contributor Author

camandel commented Nov 4, 2019

@sgotti I've add two integration tests in setup_test.go but I did not find a way to add runservice tests.
Could you indicate where to add these tests and an existing file to look at as example?

Copy link
Member

@sgotti sgotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camandel The integration tests looks good. For the runservice test there isn't an existing one right now. The idea is to create a test self contained in the runservice that will create a run and then delete the logs. But this could be done in another PR.

Comments inline. Tests are failing due to golangci-lint errors.

internal/services/runservice/api/api.go Outdated Show resolved Hide resolved
internal/services/runservice/api/api.go Outdated Show resolved Hide resolved
internal/services/runservice/api/api.go Outdated Show resolved Hide resolved
internal/services/runservice/api/api.go Outdated Show resolved Hide resolved
internal/services/runservice/api/api.go Outdated Show resolved Hide resolved
internal/services/runservice/api/api.go Outdated Show resolved Hide resolved
tests/setup_test.go Outdated Show resolved Hide resolved
tests/setup_test.go Outdated Show resolved Hide resolved
tests/setup_test.go Outdated Show resolved Hide resolved
internal/services/runservice/api/api.go Outdated Show resolved Hide resolved
@camandel
Copy link
Contributor Author

camandel commented Nov 6, 2019

@sgotti Modified to use httpError function and new errors types. Added new tests to check non existing logs.

@sgotti
Copy link
Member

sgotti commented Nov 7, 2019

@camandel Thanks. Looks like TestDirectRunLogs is failing.

@camandel
Copy link
Contributor Author

camandel commented Nov 9, 2019

I tried it in my env (all-in-one server with docker executor) but the test TestDirectRunLogs/test_delete_log_step_1passed all the times.
The error log delete error: Log for task XXXX in run YYYY is not yet archived could be due that in a distributed environment it needs a little bit more time to transfer the log from the executor to configstore.

I tried to add a delay of 5 seconds before to check if the log exists. Need it find a better way to handle this.

@sgotti
Copy link
Member

sgotti commented Nov 11, 2019

The error log delete error: Log for task XXXX in run YYYY is not yet archived could be due that in a distributed environment it needs a little bit more time to transfer the log from the executor to configstore.

Run fetching from the executor is always asyncronous:

func (s *Runservice) fetcherLoop(ctx context.Context) {
for {
log.Debugf("fetcher")
if err := s.fetcher(ctx); err != nil {
log.Errorf("err: %+v", err)
}
sleepCh := time.NewTimer(2 * time.Second).C
select {
case <-ctx.Done():
return
case <-sleepCh:
}
}
}

Now fetching is executed every 2 seconds. The test fails for me also locally because it's not related to being in a single process or not since they always are distinct components.

You should wait for it for being archived but the run response provided by the gateway doesn't export information on the logs/archives fetch state (they are low level information that don't have to be exposed to external clients) so currently sleeping is the unique way in these integration tests.

@sgotti
Copy link
Member

sgotti commented Nov 12, 2019

You should wait for it for being archived but the run response provided by the gateway doesn't export information on the logs/archives fetch state (they are low level information that don't have to be exposed to external clients)

Thinking more about this, if we want to show a Delete Log button in the ui, we should expose if the log is archived (and show the button only when archived). So the gateway api should expose something about the log state (LogArchived) in the RunTaskResponseStep (another PR)

@sgotti
Copy link
Member

sgotti commented Nov 14, 2019

Now that #175 is merged we can use it in the tests to wait for the log to be archived.

internal/services/gateway/action/run.go Outdated Show resolved Hide resolved
internal/services/runservice/api/api.go Show resolved Hide resolved
internal/services/runservice/api/api.go Outdated Show resolved Hide resolved
@camandel camandel force-pushed the api_delete_logs branch 2 times, most recently from 5979f73 to 6bf38e2 Compare November 14, 2019 11:47
@camandel
Copy link
Contributor Author

Code modified as indicated and fixed the integration test (it checked logArchived only for step one).

tests/setup_test.go Outdated Show resolved Hide resolved
tests/setup_test.go Outdated Show resolved Hide resolved
internal/services/runservice/api/api.go Outdated Show resolved Hide resolved
internal/services/runservice/api/api.go Outdated Show resolved Hide resolved
internal/services/runservice/api/api.go Outdated Show resolved Hide resolved
tests/setup_test.go Outdated Show resolved Hide resolved
@camandel
Copy link
Contributor Author

For tests on logs with no existing step I used strings.Compare because the error message changes (runid , taskid and for get also the error prefix):

error getting log: log doesn't exist: no such step for task XXX in run YYY
error deleting log: no such step for task XXX in run YYY

I was wondering if it's possible to align the prefix log doesn't exist also for delete and if it's possible to check the error type (with util.IsNotExist) and not a substring of the error message. Thanks.

@sgotti
Copy link
Member

sgotti commented Nov 17, 2019

For tests on logs with no existing step I used strings.Compare because the error message changes (runid , taskid and for get also the error prefix):

error getting log: log doesn't exist: no such step for task XXX in run YYY
error deleting log: no such step for task XXX in run YYY

was wondering if it's possible to align the prefix log doesn't exist also for delete

Yes, just use the same code used in LogsHandler to add the log doesn't exist::

switch {
case util.IsNotExist(err):
httpError(w, util.NewErrNotExist(errors.Errorf("log doesn't exist: %w", err)))
default:
httpError(w, err)
}

and if it's possible to check the error type (with util.IsNotExist) and not a substring of the error message.

You can use strings.HasPrefix which is cleaner than strings.Compare. Using only util.IsNotExits will check the error type but won't check the expected error text so it'll also catch an ErrNotExist caused by another code path.

@camandel
Copy link
Contributor Author

Aligned error message prefix and changed check with strings.HasPrefix.

@sgotti
Copy link
Member

sgotti commented Nov 18, 2019

@camandel Thanks a lot! Merging.

@sgotti sgotti merged commit f5998a7 into agola-io:master Nov 18, 2019
@camandel camandel deleted the api_delete_logs branch November 27, 2019 08:50
tulliobotti64 pushed a commit to tulliobotti64/agola that referenced this pull request Oct 19, 2022
gateway/runservice: add api to delete step logs
tulliobotti64 pushed a commit to tulliobotti64/agola that referenced this pull request Oct 19, 2022
gateway/runservice: add api to delete step logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants