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

Add Host Observer #432

Merged
merged 5 commits into from Jul 28, 2020
Merged

Conversation

asuresh4
Copy link
Member

@asuresh4 asuresh4 commented Jul 13, 2020

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.

@asuresh4 asuresh4 requested a review from a team as a code owner July 13, 2020 22:43
@project-bot project-bot bot added this to In progress in Collector Jul 13, 2020
@asuresh4 asuresh4 marked this pull request as draft July 13, 2020 22:43
@codecov
Copy link

codecov bot commented Jul 14, 2020

Codecov Report

Merging #432 into master will decrease coverage by 0.09%.
The diff coverage is 90.66%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
#integration 71.09% <ø> (ø)
#unit 85.69% <90.66%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
extension/observer/hostobserver/extension.go 88.88% <88.88%> (ø)
extension/observer/endpoints.go 95.34% <100.00%> (+1.59%) ⬆️
extension/observer/endpointswatcher.go 94.87% <100.00%> (ø)
extension/observer/hostobserver/factory.go 100.00% <100.00%> (ø)
exporter/elasticexporter/factory.go 83.33% <0.00%> (-16.67%) ⬇️
receiver/sapmreceiver/factory.go 94.11% <0.00%> (-5.89%) ⬇️
exporter/kinesisexporter/factory.go 39.58% <0.00%> (-5.32%) ⬇️
receiver/sapmreceiver/trace_receiver.go 76.40% <0.00%> (-0.27%) ⬇️
exporter/sapmexporter/factory.go 100.00% <0.00%> (ø)
processor/k8sprocessor/factory.go 100.00% <0.00%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4fe8114...b3c292f. Read the comment docs.

@asuresh4 asuresh4 force-pushed the host-observer branch 3 times, most recently from 2a0ea24 to eabd8d4 Compare July 15, 2020 23:00
@asuresh4 asuresh4 marked this pull request as ready for review July 16, 2020 14:10
extension/observer/hostobserver/README.md Outdated Show resolved Hide resolved
extension/observer/hostobserver/README.md Outdated Show resolved Hide resolved
| 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" |
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Discussed with @jrcamp as well and we were thinking of updating these variables to transport_protocol (either TCP or UDP) and network_protocol (either ipv4 or ipv6). What do you think @keitwb ?

Copy link
Member Author

Choose a reason for hiding this comment

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

extension/observer/hostobserver/extension.go Show resolved Hide resolved
logger: logger,
EndpointsWatcher: observer.EndpointsWatcher{
RefreshInterval: config.RefreshInterval,
ListEndpoints: (&hostObserver{}).listEndpoints,
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member Author

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!

Collector automation moved this from In progress to Review in progress Jul 17, 2020
extension/observer/hostobserver/README.md Outdated Show resolved Hide resolved
logger: logger,
EndpointsWatcher: observer.EndpointsWatcher{
RefreshInterval: config.RefreshInterval,
ListEndpoints: (&hostObserver{}).listEndpoints,
Copy link
Contributor

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.

extension/observer/hostobserver/extension.go Show resolved Hide resolved
@asuresh4 asuresh4 force-pushed the host-observer branch 2 times, most recently from 976a3d0 to 0f3be44 Compare July 20, 2020 17:14
@jrcamp jrcamp self-assigned this Jul 20, 2020
@asuresh4 asuresh4 requested review from jrcamp and keitwb July 21, 2020 21:07
@jrcamp jrcamp added this to the Beta 0.7.0 milestone Jul 21, 2020
mxiamxia referenced this pull request in mxiamxia/opentelemetry-collector-contrib Jul 22, 2020
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

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 ^

Copy link
Member Author

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{},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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))
Copy link
Contributor

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))
to ensure we don't have id collision across two different host observer instances that discover the same endpoints.

It may not cause collisions for host observer but maybe better to keep consistent.


pd, err := collectProcessDetails(proc)
if err != nil {
e.logger.Error(
Copy link
Contributor

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",
Copy link
Contributor

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)"

@@ -50,6 +50,15 @@ type Port struct {
Transport Transport
}

// HostPort is an endpoint discovered on a host.
type HostPort struct {
Name string
Copy link
Contributor

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)

Copy link
Member Author

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)
Copy link
Contributor

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.

@asuresh4 asuresh4 requested a review from jrcamp July 23, 2020 22:23
// 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
Copy link
Contributor

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?

Copy link
Member Author

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,
Copy link
Contributor

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.

Collector automation moved this from Review in progress to Reviewer approved Jul 23, 2020
Copy link
Contributor

@jrcamp jrcamp left a 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.

Collector automation moved this from Reviewer approved to Review in progress Jul 24, 2020
@asuresh4
Copy link
Member Author

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.

@asuresh4 asuresh4 requested a review from jrcamp July 24, 2020 16:09
@asuresh4
Copy link
Member Author

asuresh4 commented Jul 24, 2020

make[2]: Entering directory '/home/circleci/project/receiver/signalfxreceiver'
running go unit test ./... + coverage in /home/circleci/project/receiver/signalfxreceiver
--- FAIL: Test_signalfxeceiver_EndToEnd (0.01s)
    receiver_test.go:142: 
        	Error Trace:	receiver_test.go:142
        	Error:      	Received unexpected error:
        	            	Post "http://127.0.0.1:45585/v2/datapoint": dial tcp 127.0.0.1:45585: connect: connection refused
        	Test:       	Test_signalfxeceiver_EndToEnd
FAIL
coverage: 95.8% of statements
FAIL	github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver	0.578s

Test failure seems unrelated to this PR, will try a rebase to re-trigger tests.

@asuresh4
Copy link
Member Author

ptal @jrcamp

Collector automation moved this from Review in progress to Reviewer approved Jul 24, 2020
}, nil
}

var getProcessName = func(proc *process.Process) (string, error) {
Copy link
Contributor

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.

Copy link
Member Author

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.

@bogdandrutu
Copy link
Member

Please rebase

@asuresh4
Copy link
Member Author

@bogdandrutu done - ready to merge when you are.

@tigrannajaryan tigrannajaryan merged commit 158e70c into open-telemetry:master Jul 28, 2020
Collector automation moved this from Reviewer approved to Done Jul 28, 2020
@asuresh4 asuresh4 deleted the host-observer branch January 19, 2021 17:03
ljmsc referenced this pull request in ljmsc/opentelemetry-collector-contrib Feb 21, 2022
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`.
bogdandrutu pushed a commit that referenced this pull request May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Collector
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants