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 <noreply+kokoro@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
diff --git a/cmd/internal/cmdconfig/cmdconfig.go b/cmd/internal/cmdconfig/cmdconfig.go
index e5a7ee2..3b5d4d5 100644
--- a/cmd/internal/cmdconfig/cmdconfig.go
+++ b/cmd/internal/cmdconfig/cmdconfig.go
@@ -25,12 +25,16 @@
"golang.org/x/pkgsite/internal/log/stackdriverlogger"
"golang.org/x/pkgsite/internal/middleware"
"golang.org/x/pkgsite/internal/postgres"
+ mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
)
// Logger configures a middleware.Logger.
func Logger(ctx context.Context, cfg *config.Config, logName string) middleware.Logger {
if cfg.OnGCP() {
- opts := []logging.LoggerOption{logging.CommonResource(cfg.MonitoredResource)}
+ opts := []logging.LoggerOption{logging.CommonResource(&mrpb.MonitoredResource{
+ Type: cfg.MonitoredResource.Type,
+ Labels: cfg.MonitoredResource.Labels,
+ })}
if cfg.OnGKE() {
opts = append(opts, logging.CommonLabels(map[string]string{
"k8s-pod/env": cfg.DeploymentEnvironment(),
diff --git a/internal/config/config.go b/internal/config/config.go
index 900e2d2..5c07106 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -28,7 +28,6 @@
"golang.org/x/pkgsite/internal/derrors"
"golang.org/x/pkgsite/internal/log"
"golang.org/x/pkgsite/internal/secrets"
- mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
"gopkg.in/yaml.v3"
)
@@ -151,7 +150,7 @@
// "An object representing a resource that can be used for monitoring, logging,
// billing, or other purposes. Examples include virtual machine instances,
// databases, and storage devices such as disks.""
- MonitoredResource *mrpb.MonitoredResource
+ MonitoredResource *MonitoredResource
// FallbackVersionLabel is used as the VersionLabel when not hosting on
// AppEngine.
@@ -193,6 +192,19 @@
VulnDB string
}
+// MonitoredResource represents the resource that is running the current binary.
+// It might be a Google AppEngine app, a Cloud Run service, or a Kubernetes pod.
+// See https://cloud.google.com/monitoring/api/resources for more
+// details:
+// "An object representing a resource that can be used for monitoring, logging,
+// billing, or other purposes. Examples include virtual machine instances,
+// databases, and storage devices such as disks."
+type MonitoredResource struct {
+ Type string `yaml:"type,omitempty"`
+
+ Labels map[string]string `yaml:"labels,omitempty"`
+}
+
// AppVersionLabel returns the version label for the current instance. This is
// the AppVersionID available, otherwise a string constructed using the
// timestamp of process start.
@@ -444,7 +456,7 @@
// Use the gae_app monitored resource. It would be better to use the
// gae_instance monitored resource, but that's not currently supported:
// https://cloud.google.com/logging/docs/api/v2/resource-list#resource-types
- cfg.MonitoredResource = &mrpb.MonitoredResource{
+ cfg.MonitoredResource = &MonitoredResource{
Type: "gae_app",
Labels: map[string]string{
"project_id": cfg.ProjectID,
@@ -454,7 +466,7 @@
},
}
case cfg.OnCloudRun():
- cfg.MonitoredResource = &mrpb.MonitoredResource{
+ cfg.MonitoredResource = &MonitoredResource{
Type: "cloud_run_revision",
Labels: map[string]string{
"project_id": cfg.ProjectID,
@@ -464,7 +476,7 @@
},
}
case cfg.OnGKE():
- cfg.MonitoredResource = &mrpb.MonitoredResource{
+ cfg.MonitoredResource = &MonitoredResource{
Type: "k8s_container",
Labels: map[string]string{
"project_id": cfg.ProjectID,
@@ -486,7 +498,7 @@
cfg.InstanceID = id
}
} else { // running locally, perhaps
- cfg.MonitoredResource = &mrpb.MonitoredResource{
+ cfg.MonitoredResource = &MonitoredResource{
Type: "global",
Labels: map[string]string{"project_id": cfg.ProjectID},
}
diff --git a/internal/dcensus/dcensus.go b/internal/dcensus/dcensus.go
index ff2b477..3b2f76e 100644
--- a/internal/dcensus/dcensus.go
+++ b/internal/dcensus/dcensus.go
@@ -23,7 +23,6 @@
"golang.org/x/pkgsite/internal/config"
"golang.org/x/pkgsite/internal/derrors"
"golang.org/x/pkgsite/internal/log"
- mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
)
// KeyStatus is a tag key named "status".
@@ -109,7 +108,7 @@
// monitoredResource wraps a *mrpb.MonitoredResource to implement the
// monitoredresource.MonitoredResource interface.
-type monitoredResource mrpb.MonitoredResource
+type monitoredResource config.MonitoredResource
func (r *monitoredResource) MonitoredResource() (resType string, labels map[string]string) {
return r.Type, r.Labels