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

Add GCP Metrics Integration #2849

Merged
merged 22 commits into from
Feb 3, 2023

Conversation

kgeckhart
Copy link
Contributor

PR Description

Introduces a GCP metrics integration based on https://github.com/prometheus-community/stackdriver_exporter

Which issue(s) this PR fixes

Notes to the Reviewer

PR Checklist

  • CHANGELOG updated
  • Documentation added
  • Tests updated

@CLAassistant
Copy link

CLAassistant commented Jan 27, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@karengermond karengermond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments. I included some links to the Writers' Toolkit. Here's a link to the main page: https://grafana.com/docs/writers-toolkit/.


As an example,
for this load balancing metric
![gcp-exporter-config-metric](gcp-exporter-config-metric.png)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This image isn't showing up in my preview. Is it really needed? Could you link to the documentation topic rather than taking a screenshot of it? If you decide to keep the screenshot, here are guidelines: https://grafana.com/docs/writers-toolkit/writing-guide/image-guidelines/. Here's the section on where to store assets: https://grafana.com/docs/writers-toolkit/writing-guide/image-guidelines/#where-to-store-media-assets. You're supposed to use the asset uploader application and not store images locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's odd, what are you using to preview? https://github.com/grafana/agent/blob/2756dd7e62c13cb34f7a7dc70067dfcfda0c6d83/docs/sources/configuration/integrations/gcp-exporter-config.md renders it without issue.

GCP's docs aren't not really that descriptive about the three pieces of data below so I figured a screenshot breaking down what each piece means would be helpful. I can upload it if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I uploaded it let me know if it's helpful or should be removed

After deciding how the agent will obtain credentials you will need to ensure the account is set up with the IAM role `roles/monitoring.viewer`.
Since the exporter gathers all of its data from GCP Monitoring APIs this is the only permission needed.

## Configuration Examples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should include the reference section above the examples.

@kgeckhart kgeckhart force-pushed the daniele/hackathon-2022-12-keep-it-saasy-gcp-metrics branch 2 times, most recently from 3ef3907 to 32a2a9c Compare January 31, 2023 16:33
@kgeckhart
Copy link
Contributor Author

@karengermond, I fixed up all of your doc suggestions. Thank you for the feedback, would you be able to take another pass?

@marctc would it be possible to get a technical review sometime this week? Thanks.

@marctc
Copy link
Contributor

marctc commented Jan 31, 2023

@marctc would it be possible to get a technical review sometime this week? Thanks.

yes sir, tomorrow will be ready 👍

"golang.org/x/oauth2/google"
"google.golang.org/api/monitoring/v3"
"google.golang.org/api/option"
"gopkg.in/yaml.v3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we prefer to use v2, for some reason v3 is giving undesired results when marshaling sometimes

}

func (c *Config) Validate() error {
var configErrors []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong opinion, but maybe is better use multierror here?

}

googleClient.Timeout = httpTimeout
googleClient.Transport = rehttp.NewTransport(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look deeper, but you reckon we could use this instead? It's already in the dependencies and seems to be more popular than rehttp.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it a shot like,

	googleClient, err := google.DefaultClient(ctx, monitoring.MonitoringReadScope)
	if err != nil {
		return nil, fmt.Errorf("error creating Google client: %v", err)
	}

	retryClient := retryablehttp.NewClient()
	retryClient.RetryMax = 4
	retryClient.RetryWaitMin = time.Second
	retryClient.RetryWaitMax = 5 * time.Second
	retryClient.Logger = nil

	googleClient.Transport = &retryablehttp.RoundTripper{Client: retryClient}

	monitoringService, err := monitoring.NewService(ctx,
		option.WithHTTPClient(googleClient),
	)

Unfortunately, the end result seemed to disable the auth from the google.DefaultClient 😢

![gcp-exporter-config-metric-example](https://grafana.com/media/docs/agent/gcp-exporter-config-metric-example.png)

The following list shows its attributes: \
monitored_resource = `https_lb_rule`\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these \ used for? github rendering is not very happy about it

Copy link
Contributor Author

@kgeckhart kgeckhart Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird github is rendering it for me without issue,
image
The \'s create a newline without a paragraph break. I do need to remove the \ from line 24 though

rehttp.RetryAll(
rehttp.RetryMaxRetries(4),
rehttp.RetryStatuses(http.StatusServiceUnavailable)),
rehttp.ExpJitterDelay(time.Second, 5*time.Second),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @spartan0x117 if you need inspiration about the jitter

Copy link
Contributor

@marctc marctc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one comment but overall LGTM!

@kgeckhart
Copy link
Contributor Author

Thanks @marctc! I'll fix that up and rebase again after #2802 is merged.

@kgeckhart kgeckhart force-pushed the daniele/hackathon-2022-12-keep-it-saasy-gcp-metrics branch from a6c7358 to 1b8fcf2 Compare February 2, 2023 13:07
Copy link
Contributor

@karengermond karengermond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Some minor edits to the code blocks in the gcp-exporter-config.md.

@kgeckhart kgeckhart force-pushed the daniele/hackathon-2022-12-keep-it-saasy-gcp-metrics branch from 69875a4 to 75d7f69 Compare February 2, 2023 21:37
@marctc marctc merged commit fbfc748 into main Feb 3, 2023
@marctc marctc deleted the daniele/hackathon-2022-12-keep-it-saasy-gcp-metrics branch February 3, 2023 09:26
@github-actions github-actions bot added the frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed. label Mar 10, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants