Skip to content

Refactor perfdata strings#88

Merged
RincewindsHat merged 2 commits into
masterfrom
refactor/perfdata-strings
Jun 29, 2023
Merged

Refactor perfdata strings#88
RincewindsHat merged 2 commits into
masterfrom
refactor/perfdata-strings

Conversation

@martialblog
Copy link
Copy Markdown
Member

  • Moved util.go into type.go since 'util' is too generic a name
  • Made formatting function private, since they should not be used outside the module
  • Refactored tests to be table driven
  • Less restrictive character set for labels
    • According to the nagios development guides on performance data: "label can contain any characters except the equals sign or single quote (')"

Fixes #48

Also:

  • Add benchmark for perfdata
    • The perfdata code does a lot of string operations, we might want to optimize it in the future
    • Example usage go test -run=. -bench=. -count=12 ./perfdata/... | tee my.benchmark

The benchmark for the refactor.

Current master:

BenchmarkPerfdataString-8   	  822433	      1288 ns/op	     192 B/op	      13 allocs/op
BenchmarkPerfdataString-8   	  864208	      1293 ns/op	     192 B/op	      13 allocs/op
BenchmarkPerfdataString-8   	  827318	      1305 ns/op	     193 B/op	      13 allocs/op

Refactor:

BenchmarkPerfdataString-8   	 1394638	       862.3 ns/op	     160 B/op	      11 allocs/op
BenchmarkPerfdataString-8   	 1378656	       868.1 ns/op	     160 B/op	      11 allocs/op
BenchmarkPerfdataString-8   	 1363088	       880.1 ns/op	     160 B/op	      11 allocs/op

 - The perfdata code does a lot of string operations, we might want to optimize it in the future
 - Example usage go test -run=. -bench=BenchmarkPerfdataString -count=10 ./... | tee 1.benchmark
@martialblog martialblog added this to the v0.5.0 milestone Jun 26, 2023
@martialblog martialblog requested a review from pdorschner June 26, 2023 09:36
@martialblog martialblog self-assigned this Jun 26, 2023
 - Moved util.go into type.go since 'util' is too generic a name
 - Made formatting function private, since they should not be used outside the module
 - Refactored tests to be table driven
 - Less restrictive character set for labels
@martialblog martialblog force-pushed the refactor/perfdata-strings branch from ca220b3 to 4e4b05c Compare June 26, 2023 09:41
Copy link
Copy Markdown
Member

@RincewindsHat RincewindsHat left a comment

Choose a reason for hiding this comment

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

Looks sane

@RincewindsHat RincewindsHat merged commit e9ecd19 into master Jun 29, 2023
@RincewindsHat RincewindsHat deleted the refactor/perfdata-strings branch June 29, 2023 09:45
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.

Evaluate the allowed characters for perfdata label

2 participants