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

[WIP][collector] Switch to OTEL's http/grpc server #6277

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

chahatsagarmain
Copy link
Contributor

@chahatsagarmain chahatsagarmain commented Nov 29, 2024

Which problem is this PR solving?

Description of the changes

How was this change tested?

Checklist

Signed-off-by: chahatsagarmain <[email protected]>
Copy link

codecov bot commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.01%. Comparing base (4a14e87) to head (624bb69).
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6277      +/-   ##
==========================================
+ Coverage   48.78%   49.01%   +0.23%     
==========================================
  Files         179      180       +1     
  Lines       10799    11060     +261     
==========================================
+ Hits         5268     5421     +153     
- Misses       5088     5190     +102     
- Partials      443      449       +6     
Flag Coverage Δ
badger_v1 8.90% <ø> (+0.58%) ⬆️
badger_v2 1.63% <ø> (-0.05%) ⬇️
cassandra-4.x-v1 ?
cassandra-4.x-v1-manual 14.84% <ø> (?)
cassandra-4.x-v2 ?
cassandra-4.x-v2-auto 1.57% <ø> (?)
cassandra-4.x-v2-manual 1.57% <ø> (?)
cassandra-5.x-v1 ?
cassandra-5.x-v1-manual 14.84% <ø> (?)
cassandra-5.x-v2 ?
cassandra-5.x-v2-auto 1.57% <ø> (?)
cassandra-5.x-v2-manual 1.57% <ø> (?)
elasticsearch-6.x-v1 18.60% <ø> (+0.01%) ⬆️
elasticsearch-7.x-v1 18.68% <ø> (+<0.01%) ⬆️
elasticsearch-8.x-v1 18.84% <ø> (-0.02%) ⬇️
elasticsearch-8.x-v2 1.63% <ø> (-0.04%) ⬇️
grpc_v1 10.37% <ø> (+0.92%) ⬆️
grpc_v2 7.91% <ø> (+0.92%) ⬆️
kafka-v1 8.58% <ø> (-0.30%) ⬇️
kafka-v2 1.63% <ø> (-0.05%) ⬇️
memory_v2 1.62% <ø> (-0.05%) ⬇️
opensearch-1.x-v1 18.73% <ø> (-0.01%) ⬇️
opensearch-2.x-v1 18.73% <ø> (-0.01%) ⬇️
opensearch-2.x-v2 1.62% <ø> (-0.06%) ⬇️
tailsampling-processor 0.45% <ø> (-0.02%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -106,7 +104,7 @@ func applyGRPCSettings(cfg *configgrpc.ServerConfig, opts *flags.GRPCOptions) {
cfg.NetAddr.Endpoint = opts.HostPort
}
if opts.TLS.Enabled {
cfg.TLSSetting = applyTLSSettings(&opts.TLS)
cfg.TLSSetting = opts.TLS.ToOtelServerConfig()
Copy link
Member

Choose a reason for hiding this comment

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

the approach in the other PRs is to replace the config field type with configtls, can we use that here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we use configtls.ServerConfig here

TLS tlscfg.Options
but the config has no enabled field or insecure field like clientConfig . Then how should i deal with opts.TLS.Enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ToOtelServerConfig just returns nil if tls is not enabled , This will work .

Copy link
Member

Choose a reason for hiding this comment

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

Then how should i deal with opts.TLS.Enabled

we should deal with it the same way as in the other PRs. The interface in v1 is CLI flags, it doesn't matter if we translate them into internal TLS config of the one from OTEL.

@@ -142,7 +143,7 @@ type HTTPOptions struct {
// HostPort is the host:port address that the server listens on
Copy link
Member

Choose a reason for hiding this comment

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

I think we should get rid of these HTTPOptions/GRPCOptions types and use confighttp/configgrpc from OTEL. That will also take care of the TLS automatically.

See examples in #6121 and #6055

Copy link
Member

Choose a reason for hiding this comment

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

I booked #6279

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so we replace HTTPOptions/GRPCOptions types with the ones from OTEL in CollectorOptions struct?

Copy link
Member

Choose a reason for hiding this comment

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

yes

Signed-off-by: chahatsagarmain <[email protected]>
@chahatsagarmain chahatsagarmain marked this pull request as draft November 29, 2024 21:05
@chahatsagarmain chahatsagarmain changed the title [collector] Use OTEL helper in Collector [WIP][collector] Use OTEL helper in Collector Nov 29, 2024
@chahatsagarmain
Copy link
Contributor Author

@yurishkuro how do i handle tenancy for GRPC after utilzing configgrpc ?

@chahatsagarmain chahatsagarmain changed the title [WIP][collector] Use OTEL helper in Collector [WIP][collector] Switch to OTEL's http/grpc server Nov 29, 2024
Comment on lines +244 to +245
corsOpts := corsOTLPFlags.InitFromViper(v)
cOpts.OTLP.HTTP.CORS = corsOpts.ToOTELCorsConfig()
Copy link
Member

Choose a reason for hiding this comment

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

why isn't it part of initHTTPFromViper()?

@@ -52,9 +53,9 @@ func StartGRPCServer(params *GRPCServerParams) (*grpc.Server, error) {
MaxConnectionAgeGrace: params.MaxConnectionAgeGrace,
}))

if params.TLSConfig.Enabled {
if params.TLSConfig != nil {
Copy link
Member

Choose a reason for hiding this comment

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

please see the PRs I linked before - this code now becomes much simpler, we just use OTEL helpers to create listener and server, and TLS is handled automatically

type Options struct {
AllowedOrigins []string
AllowedHeaders []string
}

func (o *Options) ToOTELCorsConfig() *confighttp.CORSConfig{
Copy link
Member

Choose a reason for hiding this comment

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

don't believe we need this, CORS is built into confighttp.Config

@yurishkuro
Copy link
Member

how do i handle tenancy for GRPC after utilzing configgrpc ?

See examples in #6121 and #6055. There are standard inteceptors for tenancy that we add to both http and grpc.

Signed-off-by: chahatsagarmain <[email protected]>
@@ -103,24 +99,24 @@ func (c *Collector) Start(options *flags.CollectorOptions) error {
c.spanHandlers = handlerBuilder.BuildHandlers(c.spanProcessor)

grpcServer, err := server.StartGRPCServer(&server.GRPCServerParams{
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest changing server.GRPCServerParams to directly embed configgrpc struct, so that you don't have to do any field copying here

Signed-off-by: chahatsagarmain <[email protected]>
@chahatsagarmain
Copy link
Contributor Author

chahatsagarmain commented Nov 30, 2024

fmt.Printf("OTLP HTTP Endpoint: %s\n", otlpReceiverConfig.HTTP.ServerConfig.Endpoint)

@yurishkuro the endpoint is being set correctly in test OTLP HTTP Endpoint: :0 OTLP GRPC Endpoint: :0 but the its throwing an error could not start OTLP receiver: could not start the OTLP receiver: listen: unknown network

Comment on lines +107 to +114
ServerConfig: &configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Endpoint: options.GRPC.NetAddr.Endpoint,
},
TLSSetting: options.GRPC.TLSSetting,
MaxRecvMsgSizeMiB: options.GRPC.MaxRecvMsgSizeMiB,
Keepalive: options.GRPC.Keepalive,
},
Copy link
Member

Choose a reason for hiding this comment

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

couldn't we just assign the whole struct?

Suggested change
ServerConfig: &configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Endpoint: options.GRPC.NetAddr.Endpoint,
},
TLSSetting: options.GRPC.TLSSetting,
MaxRecvMsgSizeMiB: options.GRPC.MaxRecvMsgSizeMiB,
Keepalive: options.GRPC.Keepalive,
},
ServerConfig: options.GRPC,

})
if err != nil {
return fmt.Errorf("could not start gRPC server: %w", err)
}
c.grpcServer = grpcServer

httpServer, err := server.StartHTTPServer(&server.HTTPServerParams{
Copy link
Member

Choose a reason for hiding this comment

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

same as above

c.logger.Info("Not listening for Zipkin HTTP traffic, port not configured")
} else {
fmt.Printf("%v zipkin\n", options.Zipkin.Endpoint)
Copy link
Member

Choose a reason for hiding this comment

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

add a log instead

}
opts.TLSSetting = tlsOpts.ToOtelServerConfig()
opts.NetAddr.Endpoint = ports.FormatHostPort(v.GetString(cfg.prefix + "." + flagSuffixHostPort))
opts.MaxRecvMsgSizeMiB = v.GetInt(cfg.prefix+"."+flagSuffixGRPCMaxReceiveMessageLength) * 1024 * 1024
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
opts.MaxRecvMsgSizeMiB = v.GetInt(cfg.prefix+"."+flagSuffixGRPCMaxReceiveMessageLength) * 1024 * 1024
opts.MaxRecvMsgSizeMiB = v.GetInt(cfg.prefix+"."+flagSuffixGRPCMaxReceiveMessageLength) / (1024 * 1024)

cOpts.Zipkin.KeepAlive = v.GetBool(flagZipkinKeepAliveEnabled)
cOpts.Zipkin.HTTPHostPort = ports.FormatHostPort(v.GetString(flagZipkinHTTPHostPort))
// cOpts.Zipkin. = v.GetBool(flagZipkinKeepAliveEnabled)
cOpts.Zipkin.Endpoint = ports.FormatHostPort(v.GetString(flagZipkinHTTPHostPort))
Copy link
Member

Choose a reason for hiding this comment

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

should't this be simply initHTTPFromViper(..., &cOpts.Zipkin, ...)?

@@ -107,7 +107,7 @@ func TestCollectorOptionsWithFlags_CheckMaxReceiveMessageLength(t *testing.T) {
_, err := c.InitFromViper(v, zap.NewNop())
require.NoError(t, err)

assert.Equal(t, 8388608, c.GRPC.MaxReceiveMessageLength)
assert.Equal(t, 8388608, c.GRPC.MaxRecvMsgSizeMiB)
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't there be a change in the expectation here, due to different units?

"--collector.zipkin.keep-alive=false",
})
c.InitFromViper(v, zap.NewNop())
// func TestCollectorOptionsWithFlags_CheckZipkinKeepAlive(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

@chahatsagarmain chahatsagarmain Dec 1, 2024

Choose a reason for hiding this comment

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

After using confighttp.ServerConfig for Zipkin how should i use keepalive ?

Copy link
Member

Choose a reason for hiding this comment

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

confighttp has liveness settings too, what's the problem?

MaxReceiveMessageLength int
MaxConnectionAge time.Duration
MaxConnectionAgeGrace time.Duration
*configgrpc.ServerConfig
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
*configgrpc.ServerConfig
configgrpc.ServerConfig

@@ -24,7 +25,7 @@ import (

// HTTPServerParams to construct a new Jaeger Collector HTTP Server
type HTTPServerParams struct {
TLSConfig tlscfg.Options
TLSConfig *configtls.ServerConfig
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
TLSConfig *configtls.ServerConfig
TLSConfig configtls.ServerConfig

if params.TLSConfig.Enabled {
tlsCfg, err := params.TLSConfig.Config(params.Logger) // This checks if the certificates are correctly provided
if params.TLSConfig != nil {
tlsCfg, err := params.TLSConfig.LoadTLSConfig(context.Background())
Copy link
Member

Choose a reason for hiding this comment

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

below you are creating a listener manually. The point was to use ToListener and ToServer from confighttp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the next thing to do after fixing all reviewed issues 👍

@yurishkuro
Copy link
Member

could not start the OTLP receiver: listen: unknown network

Are you missing something like this?

$ rg '=.*TCP'
cmd/jaeger/internal/extension/jaegerquery/server_test.go
216:  tt.config.GRPC.NetAddr.Transport = confignet.TransportTypeTCP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[collector] Switch to use OTEL's http/grpc servers
2 participants