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

Stats/Stackdriver: Use resource util to generate MonitoredResource #314

Conversation

mayurkale22
Copy link
Member

Fixes #130

@@ -158,7 +158,8 @@ async function getProjectId() {
/** Gets instance id from GCP instance metadata. */
async function getInstanceId() {
try {
return await gcpMetadata.instance('id');
const id = await gcpMetadata.instance('id');
Copy link
Member Author

Choose a reason for hiding this comment

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

This is numerical ID, need to convert to string before assigning to label value.

@codecov-io
Copy link

codecov-io commented Jan 30, 2019

Codecov Report

Merging #314 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #314      +/-   ##
=========================================
- Coverage    94.9%   94.9%   -0.01%     
=========================================
  Files         118     118              
  Lines        8030    8101      +71     
  Branches      717     723       +6     
=========================================
+ Hits         7621    7688      +67     
- Misses        409     413       +4
Impacted Files Coverage Δ
test/nocks.ts 62.06% <0%> (-1.2%) ⬇️
src/stackdriver-monitoring.ts 80% <0%> (-0.22%) ⬇️
test/test-stackdriver-stats-utils.ts 100% <0%> (ø) ⬆️
test/test-detect-resource.ts 100% <0%> (ø) ⬆️
src/resource-utils.ts 92.92% <0%> (+0.07%) ⬆️
test/test-stackdriver-monitoring.ts 95.31% <0%> (+0.07%) ⬆️
src/stackdriver-stats-utils.ts 99.2% <0%> (+0.17%) ⬆️

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 9414faf...975ae83. Read the comment docs.

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 overall, defer to @draffensperger for Node readability approval.

const labels: Labels = {project_id: projectId};
let mappings: Labels = {};
const autoDetectedResource = await resource.detectResource();
switch (autoDetectedResource.type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: if you make a helper function that implements the logic of this switch then you can make an assignment like const [type, mappings] = getTypeAndMappings(autoDetectedResource.type). This would avoid the let initializations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Make sense, Done.

@@ -237,6 +287,37 @@ function leftZeroPad(ns: number) {
return `${pad}${str}`;
}

function getGcpResourceLabelsMappings() {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the motivation for having these be functions and not just assign the values to the constants above?

IMO, having the constant right next to its value would make it clearer and more compact, but up to you on this.

Copy link
Member Author

Choose a reason for hiding this comment

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

taking a suggestion. 👍

it('should return a k8s MonitoredResource', async () => {
process.env.OC_RESOURCE_TYPE = 'k8s.io/container';
process.env.OC_RESOURCE_LABELS =
'k8s.io/pod/name=pod-xyz-123,k8s.io/container/name=c1,k8s.io/namespace/name=default,cloud.google.com/gce/zone=zone1';
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional nit: for long strings like this, I often like to break them up with the + operator to keep the line under 80 chars.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@mayurkale22
Copy link
Member Author

@draffensperger thanks for the review, PTAL again once you get time.

Copy link
Contributor

@draffensperger draffensperger left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@mayurkale22 mayurkale22 merged commit 4daea53 into census-instrumentation:master Jan 30, 2019
@mayurkale22 mayurkale22 deleted the inject_resource_stackdriver branch January 30, 2019 20:00
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.

5 participants