| 34 | } |
| 35 | |
| 36 | func initAnalytics() (*AnalyticsClient, error) { |
| 37 | host := env.GetEnvOrDefault("CQ_ANALYTICS_HOST", defaultAnalyticsHost) |
| 38 | var opts []grpc.DialOption |
| 39 | if strings.HasSuffix(host, ":443") { |
| 40 | systemRoots, err := x509.SystemCertPool() |
| 41 | if err != nil { |
| 42 | return nil, err |
| 43 | } |
| 44 | cred := credentials.NewTLS(&tls.Config{ |
| 45 | RootCAs: systemRoots, |
| 46 | }) |
| 47 | opts = []grpc.DialOption{grpc.WithAuthority(host), grpc.WithTransportCredentials(cred)} |
| 48 | } else { |
| 49 | opts = []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())} |
| 50 | } |
| 51 | // TODO: Remove once there's a documented migration path per https://github.com/grpc/grpc-go/issues/7244 |
| 52 | // nolint:staticcheck |
| 53 | conn, err := grpc.Dial(host, opts...) |
| 54 | if err != nil { |
| 55 | return nil, fmt.Errorf("failed to dial analytics host %v: %w", host, err) |
| 56 | } |
| 57 | return &AnalyticsClient{ |
| 58 | client: analytics.NewAnalyticsClient(conn), |
| 59 | conn: conn, |
| 60 | host: host, |
| 61 | }, nil |
| 62 | } |
| 63 | |
| 64 | func (c *AnalyticsClient) SendSyncMetrics(ctx context.Context, sourceSpec specs.Source, destinationsSpecs []specs.Destination, invocationUUID string, m *metrics.Metrics, exitReason ExitReason) error { |
| 65 | if m == nil { |