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

Add supports for printing pretty histogram to stdout #1028

Closed

Conversation

mujtaba-ahmed12
Copy link
Contributor

No description provided.

Copy link
Contributor

@jmacd jmacd left a comment

Choose a reason for hiding this comment

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

Please revert the unrelated go.mod and go.sum changes.

@mujtaba-ahmed12
Copy link
Contributor Author

Please revert the unrelated go.mod and go.sum changes.

This is happening make precommit command.

@MrAlias
Copy link
Contributor

MrAlias commented Aug 5, 2020

Please revert the unrelated go.mod and go.sum changes.

This is happening make precommit command.

The build is failing on go.sums not being up to date which would imply it was not run before the commit was made.

Are you sure you ran make precomit prior to the commit? Or, maybe the fix didn't get pushed?

Regardless of the validity of the module hashes, what @jmacd is pointing out is a lot of the changes to the go.sum files is from the modification to the go.mod files. These changes to the go.mod files look to be in error. They are unrelated to any changes in the code. The only code change in the PR adds an additional import of the standard math package. That is not what is being changed in all of the go.mod or go.sum files.

Please revert the changes to all go.mod files and sync the go.sum files. This can be accomplished by running make in the top of the package once the changes to go.mod files are reverted.

@MrAlias
Copy link
Contributor

MrAlias commented Aug 6, 2020

Took a deeper look into the go.mod modifications. It looks like there is some cleanup that can be done in the main modules that will remove a lot of indirect dependencies because of our cleanup efforts in other PRs. I'm going to wait on #1038 which will pull out another dependency before submitting a PR to do a deep clean.

That said, I'm still at a loss why your local system is making the changes it is. These are no automatically made by the local build system for me when I do not prune anything manually. It seems like my advice above about reverting changes to all go.mod files will help clean this up if you don't want to wait for my eventual "deep clean" PR.

@jmacd
Copy link
Contributor

jmacd commented Aug 6, 2020

I fell that I've seen this sort of problem arise as follows:

  1. work on a refactoring, e.g., change package names, do something so that go tries to resolve a non-existent package
  2. before failing to resolve a non-existent package, it will try to update the go.mod
  3. you fix the code because there is actually supposed to not be a package, and the go.mod changes are still there

I would basically revert the change and ignore it, since it seemed accidental.

@@ -44,10 +45,22 @@ type line struct {

Quantiles []quantile `json:"Quantiles,omitempty"`

Histogram []bucket `json:"histogram,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I see below a switch on e.config.PrettyPrint which directly calls Fprintf, and I wonder if the structure would be more readable if the pretty-form of histogram printed in-line with the JSON, formatted within quotes, like:

... 
      Histogram: "
_pretty representation_
...
"

This could be implemented using a new type with a MarshalJSON() method that switched on e.config.PrettyPrint itself. How does this sound?

@jmacd jmacd added the area:metrics Part of OpenTelemetry Metrics label Aug 11, 2020
@mujtaba-ahmed12 mujtaba-ahmed12 requested a review from jmacd August 12, 2020 21:48
@MrAlias MrAlias linked an issue Aug 20, 2020 that may be closed by this pull request
@@ -44,13 +45,37 @@ type line struct {

Quantiles []quantile `json:"Quantiles,omitempty"`

Histogram histogram `json:"histogram,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we follow the other naming structure here and make this capital.

Suggested change
Histogram histogram `json:"histogram,omitempty"`
Histogram histogram `json:"Histogram,omitempty"`

Comment on lines +55 to +62
boundary struct {
Min float64 `json:"min"`
Max float64 `json:"max"`
}

bucket struct {
boundary `json:"bounds"`
Count float64 `json:"count"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar here:

Suggested change
boundary struct {
Min float64 `json:"min"`
Max float64 `json:"max"`
}
bucket struct {
boundary `json:"bounds"`
Count float64 `json:"count"`
boundary struct {
Min float64 `json:"Min"`
Max float64 `json:"Max"`
}
bucket struct {
boundary `json:"Bounds"`
Count float64 `json:"Count"`

Comment on lines +74 to +78
bytes, err := json.Marshal(hist)
if err != nil {
return nil, err
}
return append(bytes, []byte("\n"+printHistogram(hist))...), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not following why we are Marshaling with json and printing the histogram. This is redundantly showing the same information.

return err
}
buckets := make([]bucket, 0, len(val.Boundaries))
lowerBound := float64(-math.MaxFloat64)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be negative infinity? Or is there a limitation here?

Suggested change
lowerBound := float64(-math.MaxFloat64)
lowerBound := math.Inf(-1)

})
lowerBound = val.Boundaries[i]
if i == len(val.Boundaries)-1 {
upperBound = float64(math.MaxFloat64)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
upperBound = float64(math.MaxFloat64)
upperBound = math.Inf(1)

)

func (hist histogram) MarshalJSON() ([]byte, error) {
bytes, err := json.Marshal(hist)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have the pretty print just return the similarly formatted JSON structure like the other formats and have the default return the tabular form? That would provide the expected consistency.

@MrAlias
Copy link
Contributor

MrAlias commented Oct 1, 2020

@evantorrie is going to take this over.

@MrAlias
Copy link
Contributor

MrAlias commented Nov 19, 2020

Closing due to staleness.

@MrAlias MrAlias closed this Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants