-
Notifications
You must be signed in to change notification settings - Fork 22
auto-tune: refactor to use text/template library #58
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
base: main
Are you sure you want to change the base?
Conversation
While reviewing this to understand the story better, I noticed that we could simplify creating the cnf file by using the text/template package This feels a little more clear about what's happening compared to hacking together the strings as it was done before The only gotcha - we need to use hyphens, "-", to clean up whitespace and make sure we don't accidentally add newlines. But the existing tests drove this out [TNZ-36064](https://jira.eng.vmware.com/browse/TNZ-36064) Authored-by: Ryan Wittrup <[email protected]>
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/format" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ go vet ./...
vet: ./auto_tune_generator_test.go:9:2: "github.com/onsi/gomega/format" imported and not used
$ go run github.com/onsi/ginkgo/v2/ginkgo run -v
...
# github.com/cloudfoundry/generate-auto-tune-mysql_test [github.com/cloudfoundry/generate-auto-tune-mysql.test]
./auto_tune_generator_test.go:9:2: "github.com/onsi/gomega/format" imported and not used
tmpl, _ := template.New("auto_tune").Parse(` | ||
[mysqld] | ||
innodb_buffer_pool_size = {{.BufferPoolSize}} | ||
{{if ne .TargetPercentageOfDisk 0.0 -}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand we were programmatically comparing this before, but I would be keen to consider turning this into a boolean to reduce template logic, particularly around float comparisons.
i.e. Compute the inputs up-front and the template is just rendering logic.
For example, this go playground snippet:
maxBinlogSize := min(int64(binLogSpaceLimit/3), 1024*1024*1024) | ||
maxBinlogSize = (maxBinlogSize / binlogBlockSize) * binlogBlockSize | ||
|
||
tmpl, _ := template.New("auto_tune").Parse(` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would feel better if we assert the error though.
There are conditionals that are hopefully driven out in the unit tests (effectively exercising all the template paths).
Since this should only be a programmatic error, maybe https://pkg.go.dev/text/template#Must could be reasonable.
While reviewing this to understand the story better, I noticed that we could simplify creating the cnf file by using the text/template package
This feels a little more clear about what's happening compared to hacking together the strings as it was done before
The only gotcha - we need to use hyphens, "-", to clean up whitespace and make sure we don't accidentally add newlines. But the existing tests drove this out
TNZ-36064
Authored-by: Ryan Wittrup [email protected]