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

Perfdata errors #116

Merged
merged 6 commits into from
Jun 20, 2024
Merged

Perfdata errors #116

merged 6 commits into from
Jun 20, 2024

Conversation

RincewindsHat
Copy link
Member

No description provided.

Lorenz Kästle added 4 commits June 17, 2024 14:28
This patch changes the function signature of Performance data formatting
functions to return errors.
This is a preparation step to allow the rejection of certain values,
which are valid values for that data type, but not valid as measurements
@RincewindsHat
Copy link
Member Author

closes #115

@martialblog
Copy link
Member

Nice. I'll have a look at it later today

perfdata/type.go Outdated
// Returns an eror in some known cases where the value of a data type does not
// represent a valid measurement, see the explanation for "formatNumeric" for
// perfdata values.
func (p Perfdata) String() (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't like that this is no longer implements the Stringer interface. https://pkg.go.dev/fmt#Stringer

I rather have the formatNumeric handle that and the Stringer interface be implemented, since it is more expectable when having a String() method on a struct.

Not sure how else we could or should communicate that NaN/Inf are not printed. Maybe just docs?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see your point. I think I have an idea.

Copy link
Member Author

@RincewindsHat RincewindsHat Jun 18, 2024

Choose a reason for hiding this comment

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

I restored the behaviour of String by using the new functionality and just ignoring errors.

Copy link
Member

Choose a reason for hiding this comment

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

Coolio. I'll have a look later.

RincewindsHat and others added 2 commits June 18, 2024 22:55
This commit restores the previous signature of String() for perfdata
by moving the functionality in a new method (which is also exported).
This new method validates the data and throws errors, the String()
method catches them and just returns the empty string then.
Copy link
Member

@martialblog martialblog left a comment

Choose a reason for hiding this comment

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

Can be merged.

We can still have a discussion on if and how to allow strings a values later

@RincewindsHat RincewindsHat merged commit 3ece825 into master Jun 20, 2024
2 checks passed
@RincewindsHat RincewindsHat deleted the perfdata_errors branch June 20, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants