-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
blackbox/blackbox/httpjob.go
Outdated
for range ticker { | ||
responses = make([]http.Response, 0, len(j.Targets)) | ||
ctx, cancel := context.WithTimeout(context.Background(), j.Timeout) | ||
g, ctx := errgroup.WithContext(ctx) |
There was a problem hiding this comment.
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?
blackbox/blackbox/httpjob.go
Outdated
if err != nil { | ||
return err | ||
} | ||
mu.Lock() |
There was a problem hiding this comment.
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 | ||
|
There was a problem hiding this comment.
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
No description provided.