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

Revised Monitoring example #96

Merged
merged 5 commits into from Sep 13, 2020
Merged

Revised Monitoring example #96

merged 5 commits into from Sep 13, 2020

Conversation

DazWilkin
Copy link
Contributor

The example in the Monitoring README is insufficient.

I believe this is a working example.

I removed the curious explanation of importing modules. In my experience (and editor), I can simply reference the imports in code and go.mod is revised automatically (or will be revised on go run or go build). So, I simplified this and made the imports exhaustive.

I was unable to use popts == nil and so have used the example resource.New(...) approach here too.

The Google Project ID is required if run off-cloud and so I've added it here. I noticed, after-the-fact, that the Trace README correctly specifies WithProjectID(os.Getenv("GOOGLE_CLOUD_PROJECT")) and so, both READMEs are now consistent. However, neither piece of documentation explains the requirement to export GOOGLE_CLOUD_PROJECT="..." and likely should.

)

// Initialize exporter option.
opts := []mexporter.Option{}
projectID := os.Getenv("GOOGLE_CLOUD_PROJECT")
Copy link
Contributor

@nilebox nilebox Sep 10, 2020

Choose a reason for hiding this comment

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

As I commented in #95 (comment), this shouldn't be necessary when the application is running in GCP environment.

So I would prefer to omit this in the initial example, and then add a separate short paragraph describing how to set / override project ID 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.

OK. Will revise. Would you like me to make the change to the Trace README example too to keep them consistent? if so, I'll submit the Trace change as a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed: 2edc480

mexporter.WithProjectID(projectID),
}
popts:= []push.Option{
push.WithResource(
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is useful for the minimal example. Maybe we should fix the InstallNewPipeline to allow null popts instead? Alternatively, just make an empty slice.

Copy link

Choose a reason for hiding this comment

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

Apologies if this is an obvious question, but what does having a resource do here? My understanding is that if the application is running on GCP the resource is autodetected, otherwise the labels in the resource would need to fully match and populate a GCP monitored resource here. If it doesn't match anything, it goes to "global". That would be the case for the labels below.

If the example is for something where the resource can't be autodetected, then it'd be better to guide users toward generic_node or generic_task. Support would need to be added in the exporter for those but "global" as a monitored resource is not recommended for performance and scalability reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, supporting nil is best ;-)

If I use v0.11.0 then an empty slice generates an error:

2020/09/11 10:04:55 Error during exporting TimeSeries: currently the aggregator is not supported: &{{0 0} 123 [123]}
2020/09/11 10:04:55 rpc error: code = InvalidArgument desc = Request was missing field timeSeries.

If I use v0.11.1-0.20200910093037-ef5e24b7fcfc then an empty slice works. Will change to proactively permit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed: 7e67ff1

@@ -42,16 +51,18 @@ defer pusher.Stop()
ctx := context.Background()
meter := pusher.Provider().Meter("cloudmonitoring/example")

counter := metric.Must(meter).NewInt64Counter("counter-foo")
labels := []kv.KeyValue{kv.Key("key").String("value")}
counter := metric.Must(meter).NewInt64Counter("counter.foo")
Copy link
Contributor

Choose a reason for hiding this comment

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

Any specific reason for replacing - with . in the metric name?

Google Cloud Monitoring is actually using / and _ as separators normally, e.g. see metrics in https://cloud.google.com/monitoring/api/metrics_kubernetes

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'd thought I'd seen counter.foo used in another example and so inadvertently copied. Will revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted: 0fee3ad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants