Skip to content

Commit

Permalink
wip:feat: add direct logMetric
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Pana <[email protected]>
  • Loading branch information
acpana committed Apr 3, 2024
1 parent 1483987 commit e22c0cb
Show file tree
Hide file tree
Showing 2 changed files with 450 additions and 0 deletions.
70 changes: 70 additions & 0 deletions pkg/controller/direct/logging/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package logging

import (
"context"
"fmt"

// todo acpana: is this stable?
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller"
api "google.golang.org/api/logging/v2"
"google.golang.org/api/option"
)

type gcpClient struct {
config controller.Config
}

func newGCPClient(ctx context.Context, config *controller.Config) (*gcpClient, error) {
gcpClient := &gcpClient{
config: *config,
}
return gcpClient, nil
}

func (m *gcpClient) options() ([]option.ClientOption, error) {
var opts []option.ClientOption
if m.config.UserAgent != "" {
opts = append(opts, option.WithUserAgent(m.config.UserAgent))
}
if m.config.HTTPClient != nil {
// TODO: Set UserAgent in this scenario (error is: WithHTTPClient is incompatible with gRPC dial options)
opts = append(opts, option.WithHTTPClient(m.config.HTTPClient))
}
if m.config.UserProjectOverride && m.config.BillingProject != "" {
opts = append(opts, option.WithQuotaProject(m.config.BillingProject))
}

// TODO: support endpoints?
// if m.config.Endpoint != "" {
// opts = append(opts, option.WithEndpoint(m.config.Endpoint))
// }

return opts, nil
}

func (m *gcpClient) newLogMetricsClient(ctx context.Context) (*api.ProjectsMetricsService, error) {
opts, err := m.options()
if err != nil {
return nil, err
}
service, err := api.NewService(ctx, opts...)
if err != nil {
return nil, fmt.Errorf("building service for logging: %w", err)
}

return api.NewProjectsMetricsService(service), nil
}
Loading

0 comments on commit e22c0cb

Please sign in to comment.