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

Add option to provide resource based on metric descriptor. #231

Merged
merged 4 commits into from
Oct 29, 2019

Conversation

rghetia
Copy link
Contributor

@rghetia rghetia commented Oct 25, 2019

fixes #230

@rghetia
Copy link
Contributor Author

rghetia commented Oct 25, 2019

/cc @yanweiguo

@codecov-io
Copy link

codecov-io commented Oct 25, 2019

Codecov Report

Merging #231 into master will increase coverage by 0.34%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #231      +/-   ##
==========================================
+ Coverage   73.37%   73.72%   +0.34%     
==========================================
  Files          15       15              
  Lines        1615     1625      +10     
==========================================
+ Hits         1185     1198      +13     
+ Misses        352      350       -2     
+ Partials       78       77       -1
Impacted Files Coverage Δ
stackdriver.go 32.98% <ø> (ø) ⬆️
metrics.go 80.79% <100%> (+1.84%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8033da9...ee1e818. Read the comment docs.

metrics.go Outdated
resource := se.metricRscToMpbRsc(metric.Resource)
var resource *monitoredrespb.MonitoredResource
if get := se.o.ResourceByDescriptor; get != nil {
mr := get(&metric.Descriptor)
Copy link
Contributor

Choose a reason for hiding this comment

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

What metric.Descriptor will be if I register the following:

requestCountM = stats.Int64(
       "request_count",
	"The number of requests",
	stats.UnitDimensionless)
view.Register(
		&view.View{
			Description: "The number of requests",
			Measure:     requestCountM,
			Aggregation: view.Count(),
			TagKeys: append(metrics.CommonRevisionKeys, metrics.PodTagKey, metrics.ContainerTagKey,
				metrics.ResponseCodeKey, metrics.ResponseCodeClassKey, metrics.NumTriesKey),
		})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

metric.Descriptor{
	Name:        "request_count",
	Description: "The number of requests",
	Unit:        metricdata.	UnitDimensionless,
	Type:        metric.TypeCumulativeInt64,
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we determine resource type by name? Name is more like an ID instead of the description. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually Descriptor.Name = View.Name.

knative does determine resource type from name as per this.
It seems you also need tags, can you confirm?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah got it.

The tags are used to set the values of monitored resource labels. For example, project_id.

Copy link
Contributor

@yanweiguo yanweiguo left a comment

Choose a reason for hiding this comment

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

LGTM. Just some nits.

Thanks a lot for this quick fix.

stackdriver.go Outdated
// The ResourceByDescriptor is called to derive monitored resources from
// metric.Descriptor and label map associated with the metric. If any label is
// used for the derived resource then it will be removed the label map.
// Returned label map would then be a subset of the original map.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you describe what the return label maps are used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added the description.

metrics_test.go Outdated
@@ -559,3 +560,313 @@ func TestMetricsToMonitoringMetrics_fromProtoPoint(t *testing.T) {
}
}
}

func TestGetMonitorResource(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.

nit: Should the name be TestResourceByDescriptor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed.

@rghetia rghetia requested a review from songy23 October 28, 2019 17:03
@rghetia
Copy link
Contributor Author

rghetia commented Oct 28, 2019

@yanweiguo PTAL.

@yanweiguo
Copy link
Contributor

LGTM

@rghetia
Copy link
Contributor Author

rghetia commented Oct 28, 2019

@bogdandrutu, @songy23 , @dinooliva can one of you please review this?

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.

LGTM except one minor nit.

metrics.go Outdated

var rsc *monitoredrespb.MonitoredResource
var mr monitoredresource.Interface
if get := se.o.ResourceByDescriptor; get != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: why not just se.o.ResourceByDescriptor != nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor Author

@rghetia rghetia left a comment

Choose a reason for hiding this comment

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

@songy23 Thanks for reviewing.

metrics.go Outdated

var rsc *monitoredrespb.MonitoredResource
var mr monitoredresource.Interface
if get := se.o.ResourceByDescriptor; get != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

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.

Support multiple monitored resource types in one process
5 participants