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

Collector fails to start with error in mongodb receiver invalid transport type "" #32199

Closed
ashish121092 opened this issue Apr 5, 2024 · 8 comments
Labels
bug Something isn't working receiver/mongodb

Comments

@ashish121092
Copy link

ashish121092 commented Apr 5, 2024

Using the following configuration for collector it fails to startup with error invalid configuration for mongodb receiver : invalid transport type "".

Collector image : otel/opentelemetry-collector-contrib:0.97.0

Collector configuration:

receivers:
  otlp:
    protocols:
      grpc:
      http:
  mongodb:
    hosts:
      - endpoint: 10.224.10.25:27017
      - endpoint: 10.224.10.28:27017
      - endpoint: 10.224.10.31:27017
    collection_interval: 60s
    initial_delay: 1s
    replica_set: rs0
    tls:
      insecure: true
      insecure_skip_verify: true

What is the expected behavior?

The mongodb receiver collects metrics from the hosts.

What is the actual behavior?

The collector fails to start with error invalid configuration for mongodb receiver. Invalid transport type "".

Error message : Error: invalid configuration: receivers::mongodb: invalid transport type ""; invalid transport type ""; invalid transport type ""
2024/04/05 17:05:32 collector server run finished with error: invalid configuration: receivers::mongodb: invalid transport type ""; invalid transport type ""; invalid transport type ""

@TylerHelmuth TylerHelmuth transferred this issue from open-telemetry/opentelemetry-collector-releases Apr 5, 2024
@TylerHelmuth TylerHelmuth added receiver/mongodb bug Something isn't working labels Apr 5, 2024
Copy link
Contributor

github-actions bot commented Apr 5, 2024

Pinging code owners for receiver/mongodb: @djaglowski @schmikei. See Adding Labels via Comments if you do not have permissions to add labels yourself.

@TylerHelmuth
Copy link
Member

@ashish121092 please format your configuration and share the entire error message

@TylerHelmuth
Copy link
Member

The issue is happening because you are specifying host configuration without specifying a transport protocol. If you do

mongodb:
  hosts:
    - endpoint: 10.224.10.25:27017
      transport: "tcp"
    - endpoint: 10.224.10.28:27017
      transport: "tcp"
    - endpoint: 10.224.10.31:27017
      transport: "tcp"

It should work.

@TylerHelmuth
Copy link
Member

TylerHelmuth commented Apr 5, 2024

@djaglowski @schmikei this is happening because validation was added to confignet to ensure a transport type is set when using AddrConfig.

Reviewing the receiver, I don't see the component taking advantage of AddrConfig - it appears to be using it only to store an endpoint. Assuming that is true, I suggest you change the config struct to not depend on AddrConfig.

If you need to use AddrConfig I suggest documenting in the README that transport is required and possibly setting a default value if the user does not supply one. If only tcp should be supported you could use confignet.TCPAddrConfig.

@ashish121092
Copy link
Author

@TylerHelmuth thanks it works after adding transport to the collector configuration.

@schmikei
Copy link
Contributor

schmikei commented Apr 8, 2024

I think we should only be supporting TCP, if I have some extra time I can take a look at this

@sumoanema
Copy link

Have seen same issue in memcached receiver as well. Its not documented to use transport attribute in the config.

djaglowski added a commit that referenced this issue Jun 11, 2024
**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
what changed:mongodbreceiver `Hosts` configuration use
`confignet.TCPAddrConfig`.

Hi master, I looked at the mongodbreceiver code: 

1. The error is caused by
[AddrConfig.Validate()](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/confignet/confignet.go#L122)
return error.
```go
func (na *AddrConfig) Validate() error {
	switch na.Transport {
	case TransportTypeTCP,
		...
		return nil
	default:
		return fmt.Errorf("invalid transport type %q", na.Transport)
	}
}
```

2. `mongodbreceiver` use
[go.mongodb.org/mongo-driver](https://github.com/mongodb/mongo-go-driver)to
connect mongodb.


https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/mongodbreceiver/go.mod#L13
```go
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mongodbreceiver

go 1.21

require (
	...
	go.mongodb.org/mongo-driver v1.15.0
	...
)
```


3. `go.mongodb.org/mongo-driver` based on `TCP`.


https://github.com/mongodb/mongo-go-driver/blob/v1/x/mongo/driver/dns/dns.go#L82
```go
_, addresses, err := r.LookupSRV(srvName, "tcp", host)
```

So I think mongodbreceiver only supporting TCP.

**Link to tracking Issue:** <Issue number if applicable>

#32199

---------

Co-authored-by: Tyler Helmuth <[email protected]>
Co-authored-by: Daniel Jaglowski <[email protected]>
Co-authored-by: Curtis Robert <[email protected]>
@TylerHelmuth
Copy link
Member

@sumoanema please open a new issue, as this one was specifically for mongodb and was fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working receiver/mongodb
Projects
None yet
Development

No branches or pull requests

4 participants