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

add zero bucket if not present. #89

Merged
merged 2 commits into from
Feb 27, 2019

Conversation

rghetia
Copy link
Contributor

@rghetia rghetia commented Feb 26, 2019

No description provided.

@@ -458,6 +459,27 @@ func newTypedValue(vd *view.View, r *view.Row) *monitoringpb.TypedValue {
return nil
}

func shouldInsertZeroBound(bounds ...float64) bool {
if len(bounds) > 0 && bounds[0] != 0.0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check if the first bound is negative?

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@songy23 negative value is checked here

@mayurkale22 the reason for checking 0 value is that you could have different version (older version) of core library which would send 0 bound bucket. So you need to insert it conditionally.

Choose a reason for hiding this comment

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

SGTM

@songy23
Copy link
Contributor

songy23 commented Feb 26, 2019

/cc @mayurkale22

metrics.go Outdated
// The first bucket bound should be 0.0 because the Metrics first bucket is
// [0, first_bound) but Stackdriver monitoring bucket bounds begin with -infinity
// (first bucket is (-infinity, 0))
Bounds: addZeroBound(insertZeroBound, bexp.Explicit.Bounds...),
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 better readability consider

if insertZeroBound {
  addZeroBound(bexp.Explicit.Bounds...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it would be something like this.

                        insertZeroBound := false
			if bopts := dv.BucketOptions; bopts != nil && bopts.Type != nil {
				bexp, ok := bopts.Type.(*metricspb.DistributionValue_BucketOptions_Explicit_)
				if ok && bexp != nil && bexp.Explicit != nil {
					// The first bucket bound should be 0.0 because the Metrics first bucket is
					// [0, first_bound) but Stackdriver monitoring bucket bounds begin with -infinity
					// (first bucket is (-infinity, 0))
					insertZeroBound = shouldInsertZeroBound(bexp.Explicit.Bounds...)
					var bounds []float64
					if insertZeroBound {
						bounds = addZeroBound(bexp.Explicit.Bounds...)
					} else {
						bounds = bexp.Explicit.Bounds
					}
					mv.DistributionValue.BucketOptions = &distributionpb.Distribution_BucketOptions{
						Options: &distributionpb.Distribution_BucketOptions_ExplicitBuckets{
							ExplicitBuckets:  &distributionpb.Distribution_BucketOptions_Explicit{
								Bounds: bounds,
							},		
						},
					}
				}
			}
			var buckets []int64
			if insertZeroBound {
				buckets = addZeroBucketCount(bucketCounts(dv.Buckets)...)
			} else {
				buckets = bucketCounts(dv.Buckets)
			}
			mv.DistributionValue.BucketCounts = buckets

May be I can change the method name to addZeroBoundOnCondition

Copy link
Contributor Author

@rghetia rghetia Feb 27, 2019

Choose a reason for hiding this comment

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

@songy23 are you ok with renaming the method or you want me to make the change as shown above?

Copy link
Contributor

Choose a reason for hiding this comment

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

Renaming the method sounds good.

metrics.go Outdated
},
},
}
}
}
mv.DistributionValue.BucketCounts = addZeroBucketCount(insertZeroBound, bucketCounts(dv.Buckets)...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

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

@rghetia rghetia merged commit 14131f5 into census-ecosystem:master Feb 27, 2019
@rghetia rghetia deleted the zero_bucket branch March 1, 2019 17:56
@rghetia
Copy link
Contributor Author

rghetia commented Mar 1, 2019

fixes #87

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.

4 participants