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

fix: flusher_otlp stop nil log/metric/trace client #1994

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugins/flusher/opentelemetry/flusher_otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,21 @@ func (f *FlusherOTLP) IsReady(projectName string, logstoreName string, logstoreK
func (f *FlusherOTLP) Stop() error {
var err error

if f.logClient.grpcConn != nil {
if f.logClient != nil && f.logClient.grpcConn != nil {
yyuuttaaoo marked this conversation as resolved.
Show resolved Hide resolved
err = f.logClient.grpcConn.Close()
if err != nil {
logger.Error(f.context.GetRuntimeContext(), "FLUSHER_STOP_ALARM", "stop otlp logs flusher fail, error", err)
}
}

if f.metricClient.grpcConn != nil {
if f.metricClient != nil && f.metricClient.grpcConn != nil {
err = f.metricClient.grpcConn.Close()
if err != nil {
logger.Error(f.context.GetRuntimeContext(), "FLUSHER_STOP_ALARM", "stop otlp metrics flusher fail, error", err)
}
}

if f.traceClient.grpcConn != nil {
if f.traceClient != nil && f.traceClient.grpcConn != nil {
err = f.traceClient.grpcConn.Close()
if err != nil {
logger.Error(f.context.GetRuntimeContext(), "FLUSHER_STOP_ALARM", "stop otlp traces flusher fail, error", err)
Expand Down
9 changes: 9 additions & 0 deletions plugins/flusher/opentelemetry/flusher_otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func (t *TestOtlpLogService) Export(ctx context.Context, request *otlpv1.ExportL
}

func Test_Flusher_Init(t *testing.T) {
convey.Convey("When config is invalid", t, func() {
convey.Convey("When FlusherOTLP is not initialized", func() {
f := &FlusherOTLP{Version: v1, Logs: &helper.GrpcClientConfig{Endpoint: ":8080"}}
err := f.Stop()
convey.So(err, convey.ShouldBeNil)
})
})
convey.Convey("When init grpc service", t, func() {
_, server := newTestGrpcService(t, ":8080", time.Nanosecond)
defer func() {
Expand All @@ -61,6 +68,8 @@ func Test_Flusher_Init(t *testing.T) {
f := &FlusherOTLP{Version: v1, Logs: &helper.GrpcClientConfig{Endpoint: ":8080"}}
err := f.Init(logCtx)
convey.So(err, convey.ShouldBeNil)
err = f.Stop()
convey.So(err, convey.ShouldBeNil)
})
})
}
Expand Down
Loading