Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Add GetMonitoredResource option #46

Merged

Conversation

semistrict
Copy link
Contributor

This allows customizing the MonitoredResource based on tag values.

@semistrict semistrict force-pushed the customize-monitoredres branch 7 times, most recently from e5e6bd7 to 82e3217 Compare October 4, 2018 00:44
@semistrict semistrict requested a review from rghetia October 4, 2018 00:59
stackdriver.go Outdated
//
// The MonitoredResource field is ignored if this field is set to a non-nil
// value.
GetMonitoredResource func([]tag.Tag) monitoredresource.Interface
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this take an ViewData and also return a new ViewData and MonitorResource. User usually want to remove that tag probably.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also some people want to configure the project id as well. This is useful when export metrics on behalf of others.

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 made it take and return a []tag.Tag since I think this will accomplish the same thing without the complexity of having to clone and mutate a full ViewData. Regarding the project ID, it is part of the MonitoredResource.

@semistrict semistrict force-pushed the customize-monitoredres branch 2 times, most recently from 18bf666 to 1eb1b2e Compare October 4, 2018 16:30
@@ -101,11 +101,3 @@ func TestAWSEC2InstanceMonitoredResources(t *testing.T) {
t.Errorf("AWSEC2InstanceMonitoredResource Failed: %v", autoDetected)
}
}

func TestNullMonitoredResources(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was failing on Travis because (I guess) the Travis worker is an EC2 instance.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's actually a GCE instance :) Tests failed because GCE resource is detected correctly, which is a good indication.

@@ -1105,7 +1264,7 @@ func TestExporter_customContext(t *testing.T) {
var timedOut = 0
createMetricDescriptor = func(ctx context.Context, c *monitoring.MetricClient, mdr *monitoringpb.CreateMetricDescriptorRequest) (*metric.MetricDescriptor, error) {
select {
case <-time.After(15 * time.Millisecond):
case <-time.After(1 * time.Second):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Increase time because it was failing intermittently on Travis

@semistrict
Copy link
Contributor Author

@bogdandrutu updated PTAL

stackdriver.go Outdated

// GetMonitoredResource may be provided to supply the details of the
// monitored resource dynamically based on the tags associated with each
// data point. Most users will not need need to set this, but should instead
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:s/need need/need/

stackdriver.go Outdated
//
// The MonitoredResource field is ignored if this field is set to a non-nil
// value.
GetMonitoredResource func([]tag.Tag) ([]tag.Tag, monitoredresource.Interface)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the purpose here to create monitored resource labels based only on Tags? OR will it be a combination of two (based on tag and GCEInstance/GKE/AWS)?
Since MonitoredResource and GetMonitoredResource both cannot be set and GetMonitoredResource supersedes MonitoredResource, can MonitoredResource be deprecated?
we also have this PR on monitored resources. We would have three different ways to create monitored resources.

Copy link
Contributor

Choose a reason for hiding this comment

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

/cc @rakyll

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 don't think MonitoredResource should be deprecated even though there is a lot of overlap in functionality. GetMonitoredResources is really an advanced feature that most users should not need to care about. MonitoredResource on the other hand should usually be set by most users and is much easier to understand.

@semistrict semistrict force-pushed the customize-monitoredres branch from 1eb1b2e to 8d57087 Compare October 6, 2018 12:40
@semistrict
Copy link
Contributor Author

@bogdandrutu updated to allow modification of the tags, PTAL

This allows customizing the MonitoredResource based on tag values.
@semistrict
Copy link
Contributor Author

ping @bogdandrutu

Copy link
Contributor

@songy23 songy23 left a comment

Choose a reason for hiding this comment

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

This change LGTM though I don't have much context about the background. /cc @fabxc.

@@ -101,11 +101,3 @@ func TestAWSEC2InstanceMonitoredResources(t *testing.T) {
t.Errorf("AWSEC2InstanceMonitoredResource Failed: %v", autoDetected)
}
}

func TestNullMonitoredResources(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's actually a GCE instance :) Tests failed because GCE resource is detected correctly, which is a good indication.

@semistrict semistrict merged commit f6033e3 into census-ecosystem:master Oct 22, 2018
@fabxc
Copy link
Contributor

fabxc commented Oct 30, 2018

I wanted to submit a PR with support for resources and this certainly conflicts.

@bogdandrutu @Ramonza could you provide some background on the use case this was added for? I'd like to find a good way to accommodate this use case within the new resources.

@semistrict
Copy link
Contributor Author

@fabxc this was added so that you can record against more than one monitored resource based on what tags are set. For example, if you are recording stats on behalf of another process.

@fabxc
Copy link
Contributor

fabxc commented Oct 31, 2018

We deliberately deferred the discussion of multiple resources from a single process initially. I thought this would rather be an aspect of the core library as well and would either way be discussed in the scope of a language and exporter independent spec.
Solving it at the level of an individual exporter seems to invite a lot of fragmented and incompatible approaches. This particular implementation states that view and tags can mutate the resources, which has implications that I'd have liked to see discussed.

The only way forward right now seems to be to provide the intended core resource handling as a GetMonitoredResource function that ignores the tags. I strongly dislike this since the exporter by default effectively ignores the core resource concept.
I also thought the monitoredresource package would become deprecated entirely, since the actual logic in there was factored out to census-ecosystem/opencensus-go-resource. But due to the monitoredresource.Interface type it would now be around forever.

@bogdandrutu

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

Successfully merging this pull request may close these issues.

6 participants