elastic / elastic/cloudbeat

Fetchers to return their own channel

Open
#1,351 4 comments 0 reactions 0 assignees View on GitHub
cloudbeat discuss Team:Cloud Security technical debt
Dominant language
Go
Stars
58
Forks
55
Avg merge
9h 9m
Merged PRs (30d)
424

Description

## Motivation
As we know, sending on a close channel causes a panic.
Therefore the best practices in golang is that the sender always the one to close the channel.
In our posture flavor, that's not the case, all the fetchers are sharing the same channel which none of them can close.
Instead, each fetcher should have full ownership on its channel.
One way of doing that is to modify the fetcher interface to return a receive-only channel.
```go
type Fetcher interface {
Fetch(context.Context, CycleMetadata) (chan <-fetching.ResourceInfo, error)
Stop()
}
```
Then the `manager` that trigger all the fetchers will mux the results into a single channel and return it `chan <-fetching.ResourceInfo`.

## Definition of done
- [ ] All fetchers should return a new receive-only channel
- [ ] Once a fetcher has completed it can close the channel
- [ ] A manager should mux all fetchers into a single channel
- [ ] When all fetchers has completed the manager can close the channel

### Related tasks/epics
Reference related issues and epics

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.