Skip to content

system/telemetry metrics OTLP GRPC Exporter: add CA certificate support #11633

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

Merged
merged 8 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions service/telemetry/internal/otelinit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/resource"
"google.golang.org/grpc/credentials"

semconv "go.opentelemetry.io/collector/semconv/v1.18.0"
)
Expand Down Expand Up @@ -224,6 +225,14 @@ func initOTLPgRPCExporter(ctx context.Context, otlpConfig *config.OTLPMetric) (s
opts = append(opts, otlpmetricgrpc.WithEndpoint(u.Host))
if u.Scheme == "http" {
opts = append(opts, otlpmetricgrpc.WithInsecure())
} else {
if otlpConfig.Certificate != nil {
creds, err := credentials.NewClientTLSFromFile(*otlpConfig.Certificate, "")
if err != nil {
return nil, fmt.Errorf("could not create client tls credentials: %w", err)
}
opts = append(opts, otlpmetricgrpc.WithTLSCredentials(creds))
}
}
}

Expand Down
42 changes: 42 additions & 0 deletions service/telemetry/internal/otelinit/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package otelinit
import (
"context"
"errors"
"fmt"
"net/url"
"path/filepath"
"reflect"
"sync"
"testing"
Expand Down Expand Up @@ -527,6 +529,46 @@ func TestMetricReader(t *testing.T) {
},
wantErr: errors.New("unsupported temporality preference \"invalid\""),
},
{
name: "periodic/otlp-grpc-good-ca-certificate",
reader: config.MetricReader{
Periodic: &config.PeriodicMetricReader{
Exporter: config.MetricExporter{
OTLP: &config.OTLPMetric{
Protocol: "grpc/protobuf",
Endpoint: "https://localhost:4317",
Compression: strPtr("gzip"),
Timeout: intPtr(1000),
Certificate: strPtr(filepath.Join("testdata", "ca.crt")),
Headers: map[string]string{
"test": "test1",
},
},
},
},
},
wantReader: sdkmetric.NewPeriodicReader(otlpGRPCExporter),
},
{
name: "periodic/otlp-grpc-bad-ca-certificate",
reader: config.MetricReader{
Periodic: &config.PeriodicMetricReader{
Exporter: config.MetricExporter{
OTLP: &config.OTLPMetric{
Protocol: "grpc/protobuf",
Endpoint: "https://localhost:4317",
Compression: strPtr("gzip"),
Timeout: intPtr(1000),
Certificate: strPtr(filepath.Join("testdata", "bad_cert.crt")),
Headers: map[string]string{
"test": "test1",
},
},
},
},
},
wantErr: fmt.Errorf("could not create client tls credentials: %w", errors.New("credentials: failed to append certificates")),
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is intentionally not a PEM formatted cert file.
20 changes: 20 additions & 0 deletions service/telemetry/internal/otelinit/testdata/ca.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDNjCCAh4CCQC0I5IQT7eziDANBgkqhkiG9w0BAQsFADBdMQswCQYDVQQGEwJB
VTESMBAGA1UECAwJQXVzdHJhbGlhMQ8wDQYDVQQHDAZTeWRuZXkxEjAQBgNVBAoM
CU15T3JnTmFtZTEVMBMGA1UEAwwMTXlDb21tb25OYW1lMB4XDTIyMDgwMzA0MTky
MVoXDTMyMDczMTA0MTkyMVowXTELMAkGA1UEBhMCQVUxEjAQBgNVBAgMCUF1c3Ry
YWxpYTEPMA0GA1UEBwwGU3lkbmV5MRIwEAYDVQQKDAlNeU9yZ05hbWUxFTATBgNV
BAMMDE15Q29tbW9uTmFtZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
AMhGP0dy3zvkdx9zI+/XV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