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

blackbox monitoring core #6

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

blackbox monitoring core #6

wants to merge 4 commits into from

Conversation

adamplansky
Copy link
Owner

No description provided.

@adamplansky adamplansky requested a review from sev3ryn May 9, 2021 20:06
@adamplansky adamplansky self-assigned this May 9, 2021
blackbox/main.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@sev3ryn sev3ryn left a comment

Choose a reason for hiding this comment

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

not bad at all. But still there are some questions :)

if err := run(); err != nil {
log.Fatal(err)
}
os.Exit(0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

not required

func (l *logResult) Report(resp <-chan Result) {
for r := range resp {
if r.err != nil {
l.l.Error("unable to process request", zap.Error(r.err))
Copy link
Collaborator

Choose a reason for hiding this comment

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

worth adding too
l := l.l.With(
zap.String("URL", URL),
zap.Int("status", code),
zap.String("job_name", r.jobName),

return err
}

resultCh := s.RunReporter()
Copy link
Collaborator

Choose a reason for hiding this comment

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

will be nicer if you add this to NewLogResult()
and close the channel on logReporter.Close()

// RunReporter crates new report channel and spin up new go routine with Report method
// with this newly created channel. Every scraped job needs to report result into this
// newly created report channel.
func (s *Scraper) RunReporter() chan Result {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if this actually is need - it should be a method of logResult not Scraper

}, err
}

func (l *logResult) Report(resp <-chan Result) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if in the end - reporting is only required with the log and not something else - there is no need to gather it - log is concurrency free structure so it can be executed in multiple go routines at the same time

for range ticker {
responses = make([]http.Response, 0, len(j.Targets))
ctx, cancel := context.WithTimeout(context.Background(), j.Timeout)
g, ctx := errgroup.WithContext(ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do you need this context?

if err != nil {
return err
}
mu.Lock()
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is quite unusual to have mutex together with chan for collecting results
imho - worth changing Result a bit to be able to collect the parts of job and combine it to one job if needed

sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
<-sig

Copy link
Collaborator

Choose a reason for hiding this comment

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

you may catch panic on while closing app - "publish to closed channel" as you are not actually stopping scrapers

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.

2 participants