Skip to content

Commit 3918c80

Browse files
committed
internal/config: remove dependency on MonitoredResource proto
For golang/go#61399 Change-Id: I90070de1c2fcde2bb4056c30637d4ff4fdf100f5 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/515376 kokoro-CI: kokoro <[email protected]> Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]>
1 parent 5237f18 commit 3918c80

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

cmd/internal/cmdconfig/cmdconfig.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ import (
2525
"golang.org/x/pkgsite/internal/log/stackdriverlogger"
2626
"golang.org/x/pkgsite/internal/middleware"
2727
"golang.org/x/pkgsite/internal/postgres"
28+
mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
2829
)
2930

3031
// Logger configures a middleware.Logger.
3132
func Logger(ctx context.Context, cfg *config.Config, logName string) middleware.Logger {
3233
if cfg.OnGCP() {
33-
opts := []logging.LoggerOption{logging.CommonResource(cfg.MonitoredResource)}
34+
opts := []logging.LoggerOption{logging.CommonResource(&mrpb.MonitoredResource{
35+
Type: cfg.MonitoredResource.Type,
36+
Labels: cfg.MonitoredResource.Labels,
37+
})}
3438
if cfg.OnGKE() {
3539
opts = append(opts, logging.CommonLabels(map[string]string{
3640
"k8s-pod/env": cfg.DeploymentEnvironment(),

internal/config/config.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"golang.org/x/pkgsite/internal/derrors"
2929
"golang.org/x/pkgsite/internal/log"
3030
"golang.org/x/pkgsite/internal/secrets"
31-
mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
3231
"gopkg.in/yaml.v3"
3332
)
3433

@@ -151,7 +150,7 @@ type Config struct {
151150
// "An object representing a resource that can be used for monitoring, logging,
152151
// billing, or other purposes. Examples include virtual machine instances,
153152
// databases, and storage devices such as disks.""
154-
MonitoredResource *mrpb.MonitoredResource
153+
MonitoredResource *MonitoredResource
155154

156155
// FallbackVersionLabel is used as the VersionLabel when not hosting on
157156
// AppEngine.
@@ -193,6 +192,19 @@ type Config struct {
193192
VulnDB string
194193
}
195194

195+
// MonitoredResource represents the resource that is running the current binary.
196+
// It might be a Google AppEngine app, a Cloud Run service, or a Kubernetes pod.
197+
// See https://cloud.google.com/monitoring/api/resources for more
198+
// details:
199+
// "An object representing a resource that can be used for monitoring, logging,
200+
// billing, or other purposes. Examples include virtual machine instances,
201+
// databases, and storage devices such as disks."
202+
type MonitoredResource struct {
203+
Type string `yaml:"type,omitempty"`
204+
205+
Labels map[string]string `yaml:"labels,omitempty"`
206+
}
207+
196208
// AppVersionLabel returns the version label for the current instance. This is
197209
// the AppVersionID available, otherwise a string constructed using the
198210
// timestamp of process start.
@@ -444,7 +456,7 @@ func Init(ctx context.Context) (_ *Config, err error) {
444456
// Use the gae_app monitored resource. It would be better to use the
445457
// gae_instance monitored resource, but that's not currently supported:
446458
// https://cloud.google.com/logging/docs/api/v2/resource-list#resource-types
447-
cfg.MonitoredResource = &mrpb.MonitoredResource{
459+
cfg.MonitoredResource = &MonitoredResource{
448460
Type: "gae_app",
449461
Labels: map[string]string{
450462
"project_id": cfg.ProjectID,
@@ -454,7 +466,7 @@ func Init(ctx context.Context) (_ *Config, err error) {
454466
},
455467
}
456468
case cfg.OnCloudRun():
457-
cfg.MonitoredResource = &mrpb.MonitoredResource{
469+
cfg.MonitoredResource = &MonitoredResource{
458470
Type: "cloud_run_revision",
459471
Labels: map[string]string{
460472
"project_id": cfg.ProjectID,
@@ -464,7 +476,7 @@ func Init(ctx context.Context) (_ *Config, err error) {
464476
},
465477
}
466478
case cfg.OnGKE():
467-
cfg.MonitoredResource = &mrpb.MonitoredResource{
479+
cfg.MonitoredResource = &MonitoredResource{
468480
Type: "k8s_container",
469481
Labels: map[string]string{
470482
"project_id": cfg.ProjectID,
@@ -486,7 +498,7 @@ func Init(ctx context.Context) (_ *Config, err error) {
486498
cfg.InstanceID = id
487499
}
488500
} else { // running locally, perhaps
489-
cfg.MonitoredResource = &mrpb.MonitoredResource{
501+
cfg.MonitoredResource = &MonitoredResource{
490502
Type: "global",
491503
Labels: map[string]string{"project_id": cfg.ProjectID},
492504
}

internal/dcensus/dcensus.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"golang.org/x/pkgsite/internal/config"
2424
"golang.org/x/pkgsite/internal/derrors"
2525
"golang.org/x/pkgsite/internal/log"
26-
mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
2726
)
2827

2928
// KeyStatus is a tag key named "status".
@@ -109,7 +108,7 @@ func NewServer() (http.Handler, error) {
109108

110109
// monitoredResource wraps a *mrpb.MonitoredResource to implement the
111110
// monitoredresource.MonitoredResource interface.
112-
type monitoredResource mrpb.MonitoredResource
111+
type monitoredResource config.MonitoredResource
113112

114113
func (r *monitoredResource) MonitoredResource() (resType string, labels map[string]string) {
115114
return r.Type, r.Labels

0 commit comments

Comments
 (0)