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
Add Host Observer #432
Add Host Observer #432
Conversation
Codecov Report
@@ Coverage Diff @@
## master #432 +/- ##
==========================================
- Coverage 85.96% 85.87% -0.10%
==========================================
Files 187 189 +2
Lines 10063 10108 +45
==========================================
+ Hits 8651 8680 +29
- Misses 1091 1103 +12
- Partials 321 325 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
2a0ea24
to
eabd8d4
Compare
| port | port number | | ||
| command | full command used to invoke this process, including the executable itself at the beginning | | ||
| is_ipv6 | `true` if the endpoint is IPv6 | | ||
| protocol | "TCP" or "UDP" | |
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 really the transport protocol and IPv4 vs v6 is the network protocol. That distinction was not made very clear in the Smart Agent host observer.
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.
Would you rather have endpoint variables called transport_protocol
and network_protocol
instead of protocol
and is_ipv6
?
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.
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.
logger: logger, | ||
EndpointsWatcher: observer.EndpointsWatcher{ | ||
RefreshInterval: config.RefreshInterval, | ||
ListEndpoints: (&hostObserver{}).listEndpoints, |
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 pretty ugly creating a completely separate instance of the host observer to pass the listEndpoints method to. Why don't you just make listEndpoints a plain function instead?
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.
Also logger would be nil
in listEndpoints which is not going to behave properly.
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 refactor this and also make sure there's test coverage around this!
logger: logger, | ||
EndpointsWatcher: observer.EndpointsWatcher{ | ||
RefreshInterval: config.RefreshInterval, | ||
ListEndpoints: (&hostObserver{}).listEndpoints, |
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.
I wonder if ListEndpoints should be an interface instead of a function. I think it'd look a little cleaner to use since you'd pass in &hostObserver{}
. Not critical but see what you think.
976a3d0
to
0f3be44
Compare
This PR takes over from #432 - Added SamplingManager to the `jReceiver` struct - Added new parameters to configure remote sampling endpoint (`remote_sampling:fetch_endpoint`) - Added tests and updated README
@@ -7,34 +7,35 @@ require ( | |||
github.com/golangci/golangci-lint v1.28.3 | |||
github.com/google/addlicense v0.0.0-20200622132530-df58acafd6d5 | |||
github.com/jstemmer/go-junit-report v0.9.1 | |||
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/alibabacloudlogserviceexporter v0.0.0-00010101000000-000000000000 |
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.
Were these deviations from https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/487/files#diff-37aff102a57d3d7b797f152915a6dc16 intentional?
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.
@bogdandrutu do you know why these were all changed ^
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.
Yes, these were intentional. Typically we just have the version be v0.0.0
for modules in this repo. Not sure why it was updated. But @bogdandrutu 's changes are as desired, I'll leave it unchanged in this diff.
var endpointsMap map[EndpointID]Endpoint | ||
func setup() (*mockEndpointsLister, EndpointsWatcher, mockNotifier) { | ||
ml := &mockEndpointsLister{ | ||
Mutex: sync.Mutex{}, |
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.
Mutex: sync.Mutex{}, |
Explicit initialization not needed.
// still do discovery rules on such sockets. | ||
if c.Pid == 0 { | ||
cd := collectConnectionDetails(c) | ||
id := observer.EndpointID(fmt.Sprintf("%s-%d-%s", c.Laddr.IP, cd.port, cd.transport)) |
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.
I think we want to include the name of the component instance here. See:
podID := observer.EndpointID(fmt.Sprintf("%s/%s", h.idNamespace, pod.UID)) |
It may not cause collisions for host observer but maybe better to keep consistent.
|
||
pd, err := collectProcessDetails(proc) | ||
if err != nil { | ||
e.logger.Error( |
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.
nit: this doesn't look terribly long if it was just all one one line.
pd, err := collectProcessDetails(proc) | ||
if err != nil { | ||
e.logger.Error( | ||
"Skipping process", |
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.
Maybe "failed collecting process details (skipping)"
extension/observer/endpoints.go
Outdated
@@ -50,6 +50,15 @@ type Port struct { | |||
Transport Transport | |||
} | |||
|
|||
// HostPort is an endpoint discovered on a host. | |||
type HostPort struct { | |||
Name string |
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.
What is name for? Looks like below it's set to the ID but is that useful? Please add comment to each one like Pod (though looks like I didn't add them to Port, oops)
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.
Added descriptions to both, fields in HostPort
and Port
.
} | ||
|
||
for _, c := range conns { | ||
cd := collectConnectionDetails(*c) |
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 it's already a pointer probably better to just pass as a pointer instead of making a copy.
// Port, this value is set by the observer to be "IP-Port-Transport" | ||
// prefixed by the name of the host_observer instance, | ||
// "(host_observer/2)127.0.0.1-9099-UDP" for example. | ||
Name string |
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 we can't collect it should we just make name be empty string? Why set it to id?
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.
That sounds good. Will update.
cd := collectConnectionDetails(&c) | ||
id := observer.EndpointID( | ||
fmt.Sprintf( | ||
"(%s)%s-%d-%s", e.observerName, c.Laddr.IP, cd.port, cd.transport, |
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.
I'd like to make it and k8sobserver id format similar but there's some tweaks I want to make to id so I'll just do that separately in another PR.
I think it's better if we use metadata on the end of the ID, similar to what receiver_creator does:
// Sets dynamically created receiver to something like receiver_creator/1/redis{endpoint="localhost:6380"}. |
So this would look something like:
hostobserver/2{endpoint="127.0.0.1:23", protocol="UDP", pid=3482}
or something like that.
(Just as an aside RC should probably just use the endpoint ID to resolve that TODO)
tl;dr: nothing for you to change here right now, just notes on things to fix sometime.
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.
Just noticed, look like host observer test failed due to races.
Looks like the race was from a couple of tests where I tried to mock failures of third-party packages. Removing those tests for now. Let me know if you feel strongly about adding those back. |
Test failure seems unrelated to this PR, will try a rebase to re-trigger tests. |
ptal @jrcamp |
}, nil | ||
} | ||
|
||
var getProcessName = func(proc *process.Process) (string, error) { |
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.
Maybe in followup PR you could try refactoring this into a struct and/or interface that can be injected by a mock implementation for tests. Should be safer than trying to modify package level variables in test. Can talk about it more offline if it's not clear what I mean.
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.
I think understand what you mean. Will make a subsequent PR to refactor.
Please rebase |
@bogdandrutu done - ready to merge when you are. |
Rename the package from "export" to "metric". Note that all the existing imports of this package use an explicit name of `export` and, therefore, no import declaration changes are included. Rename the `MetricKind` to `Kind` to not stutter in the type usage. Note this does not include a method name change for the `Descriptor` method `MetricKind`.
Depends on #427
Description: Add host observer to look for listening network endpoints on host
Testing: Unit tests added. Manually tested with
receivercreator
receiver.Documentation: README.md.