Skip to content
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

googlecloudmonitoringreceiver gives no valid credentials found Error #36607

Closed
HazemAbdelmagid opened this issue Dec 1, 2024 · 8 comments · Fixed by #36648
Closed

googlecloudmonitoringreceiver gives no valid credentials found Error #36607

HazemAbdelmagid opened this issue Dec 1, 2024 · 8 comments · Fixed by #36648
Assignees
Labels

Comments

@HazemAbdelmagid
Copy link

Component(s)

receiver/googlecloudmonitoring

What happened?

Description

I have been trying to integrate OTEL with googlecloudmonitoring receiver to collect metrics related to memorystore and then forward them to prometheus which exists in a different cluster but it is not working.
When I try to add the googlecloudmonitoring receiver configurations and give the service account of the collector access for collecting those metrics, it doesn't work and gives this error messges:

2024-12-01T16:28:37.861Z        error   graph/graph.go:426      Failed to start component       {"error": "no valid credentials found", "type": "Receiver", "id": "googlecloudmonitoring"}
2024-12-01T16:28:37.861Z        info    [email protected]/service.go:266 Starting shutdown...
2024-12-01T16:28:37.861Z        info    extensions/extensions.go:66     Stopping extensions...
2024-12-01T16:28:37.861Z        info    [email protected]/service.go:280 Shutdown complete.
Error: cannot start pipelines: no valid credentials found
2024/12/01 16:28:37 collector server run finished with error: cannot start pipelines: no valid credentials found

Steps to Reproduce

apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: collector-with-ta
  namespace: opentelemetry-operator-system
spec:
  config:
    exporters:
      debug:
        verbosity: detailed
      googlecloudpubsub:
        project: <redacted>
        topic: projects/<redacted>/topics/metrics-pubsub
    processors:
      batch:
        timeout: 5s
      memory_limiter:
        check_interval: 1s
        limit_percentage: 75
        spike_limit_percentage: 10
    receivers:
      googlecloudmonitoring:
        collection_interval: 5m
        project_id: <redacted>
        metrics_list:
        - metric_name: "redis.googleapis.com/instance/stats/cpu_utilization"
    service:
      pipelines:
        metrics:
          exporters:
          - googlecloudpubsub
          - debug
          processors:
          - batch
          - memory_limiter
          receivers:
          - googlecloudmonitoring
      telemetry:
        metrics:
          address: 0.0.0.0:8888
  image: otel/opentelemetry-collector-contrib:0.112.0
  mode: statefulset
  replicas: 1
  serviceAccount: opentelemetry-collector-sa
---
apiVersion: v1
  kind: ServiceAccount
  metadata:
    annotations:
      iam.gke.io/gcp-service-account: opentelemetry-collector@<redacted>.iam.gserviceaccount.com
    name: opentelemetry-collector-sa
    namespace: opentelemetry-operator-system

gcloud projects get-iam-policy <redacted> --flatten="bindings[].members" --filter="bindings.members:serviceAccount:opentelemetry-collector@<redacted>.iam.gserviceaccount.com" --format="table(bindings.role)"
ROLE: roles/monitoring.viewer

Expected Result

OTEL collector to get the listed metrics.

Actual Result

error   graph/graph.go:426      Failed to start component       {"error": "no valid credentials found", "type": "Receiver", "id": "googlecloudmonitoring"}
2024-12-01T16:44:25.863Z        info    [email protected]/service.go:266 Starting shutdown...
2024-12-01T16:44:25.863Z        info    extensions/extensions.go:66     Stopping extensions...
2024-12-01T16:44:25.863Z        info    [email protected]/service.go:280 Shutdown complete.
Error: cannot start pipelines: no valid credentials found
2024/12/01 16:44:25 collector server run finished with error: cannot start pipelines: no valid credentials found

Collector version

v0.112.0

Environment information

Environment

GKE Cluster

OpenTelemetry Collector configuration

config:
    exporters:
      debug:
        verbosity: detailed
      googlecloudpubsub:
        project: <redacted>
        topic: projects/<redacted>/topics/metrics-pubsub
    processors:
      batch:
        timeout: 5s
      memory_limiter:
        check_interval: 1s
        limit_percentage: 75
        spike_limit_percentage: 10
    receivers:
      googlecloudmonitoring:
        collection_interval: 5m
        project_id: <redacted>
        metrics_list:
        - metric_name: "redis.googleapis.com/instance/stats/cpu_utilization"
    service:
      pipelines:
        metrics:
          exporters:
          - googlecloudpubsub
          - debug
          processors:
          - batch
          - memory_limiter
          receivers:
          - googlecloudmonitoring

Log output

error   graph/graph.go:426      Failed to start component       {"error": "no valid credentials found", "type": "Receiver", "id": "googlecloudmonitoring"}
2024-12-01T16:44:25.863Z        info    [email protected]/service.go:266 Starting shutdown...
2024-12-01T16:44:25.863Z        info    extensions/extensions.go:66     Stopping extensions...
2024-12-01T16:44:25.863Z        info    [email protected]/service.go:280 Shutdown complete.
Error: cannot start pipelines: no valid credentials found
2024/12/01 16:44:25 collector server run finished with error: cannot start pipelines: no valid credentials found

Additional context

No response

@HazemAbdelmagid HazemAbdelmagid added bug Something isn't working needs triage New item requiring triage labels Dec 1, 2024
Copy link
Contributor

github-actions bot commented Dec 1, 2024

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@VihasMakwana
Copy link
Contributor

@HazemAbdelmagid do you have GOOGLE_APPLICATION_CREDENTIALS environment variable set pointing to the credentials file?

@VihasMakwana
Copy link
Contributor

@VihasMakwana VihasMakwana added waiting for author and removed needs triage New item requiring triage labels Dec 2, 2024
@HazemAbdelmagid
Copy link
Author

@VihasMakwana why do I need to use GOOGLE_APPLICATION_CREDENTIALS since I am using a service account on K8s which has annotation for gcp service account that has been assigned monitoring.viewer role, and it's mentioned in the README.md file for the receiver the following:

Note that if your workload is running on Google Cloud Platform (GCP), the service account credentials will be used automatically without needing to set the environment variable manually.

@VihasMakwana
Copy link
Contributor

Right. In that case, you don't need an env.
Here's the offending code:

creds, err := google.FindDefaultCredentials(ctx, "https://www.googleapis.com/auth/monitoring.read")
if err != nil {
return fmt.Errorf("failed to find default credentials: %w", err)
}
if creds == nil || creds.JSON == nil {
return errors.New("no valid credentials found")
}

We're exiting on creds.JSON == nil but from the documentation,

// JSON contains the raw bytes from a JSON credentials file.
// This field may be nil if authentication is provided by the
// environment and not with a credentials file, e.g. when code is
// running on Google Cloud Platform.

So, maybe we don't need to check for creds.JSON?
cc: @dashpole

@dashpole
Copy link
Contributor

dashpole commented Dec 2, 2024

Yes, we definitely should not be checking creds.JSON: https://pkg.go.dev/golang.org/x/oauth2/google#Credentials

 	// JSON contains the raw bytes from a JSON credentials file.
	// This field may be nil if authentication is provided by the
	// environment and not with a credentials file, e.g. when code is
	// running on Google Cloud Platform.
        JSON [][byte](https://pkg.go.dev/builtin#byte)

Looking at the source, it also isn't necessary to check if creds is nil, since it will always be non-nil if no error was returned: https://cs.opensource.google/go/x/oauth2/+/master:google/default.go;l=194;drc=d0e617c58cf747cf27df9762003502f814dd524c

@VihasMakwana
Copy link
Contributor

I can file a fix for it, unless you're already working on it. Let me know!

@dashpole
Copy link
Contributor

dashpole commented Dec 2, 2024

Go for it @VihasMakwana

@VihasMakwana VihasMakwana self-assigned this Dec 2, 2024
codeboten pushed a commit that referenced this issue Dec 4, 2024
#### Description
Fix "no validation found" error if workload is running on Google Cloud
Platform.
There's no need to check for `creds` or `creds.JSON` explicitly. If any
errors are encountered, it will be thrown by `FindDefaultCredentials`.

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes
#36607
shivanthzen pushed a commit to shivanthzen/opentelemetry-collector-contrib that referenced this issue Dec 5, 2024
…try#36648)

#### Description
Fix "no validation found" error if workload is running on Google Cloud
Platform.
There's no need to check for `creds` or `creds.JSON` explicitly. If any
errors are encountered, it will be thrown by `FindDefaultCredentials`.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes
open-telemetry#36607
ZenoCC-Peng pushed a commit to ZenoCC-Peng/opentelemetry-collector-contrib that referenced this issue Dec 6, 2024
…try#36648)

#### Description
Fix "no validation found" error if workload is running on Google Cloud
Platform.
There's no need to check for `creds` or `creds.JSON` explicitly. If any
errors are encountered, it will be thrown by `FindDefaultCredentials`.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes
open-telemetry#36607
sbylica-splunk pushed a commit to sbylica-splunk/opentelemetry-collector-contrib that referenced this issue Dec 17, 2024
…try#36648)

#### Description
Fix "no validation found" error if workload is running on Google Cloud
Platform.
There's no need to check for `creds` or `creds.JSON` explicitly. If any
errors are encountered, it will be thrown by `FindDefaultCredentials`.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes
open-telemetry#36607
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants