Skip to content

Commit

Permalink
Fr 14 (#15)
Browse files Browse the repository at this point in the history
* start modification

* DONE  Add constants as idioms
DONE  Functions to get params as string directly from Family object

* Implementing also the auto calculation for the connections

* Update README.md

* Update README.md

* Update README.md

* Update help

* grouping constants

* Adjust several calculation to better represent the load scenarios.
add the CpuConncetionMillFactor const which is the key to tune the load factor

* Adjust several calculation to better represent the load scenarios.
add the CpuConncetionMillFactor const which is the key to tune the load factor

* some comments for future development

* Version fix
  • Loading branch information
Tusamarco authored Oct 18, 2023
1 parent d49a2bf commit 450a902
Show file tree
Hide file tree
Showing 6 changed files with 443 additions and 256 deletions.
98 changes: 90 additions & 8 deletions src/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"fmt"
MO "github.com/Tusamarco/mysqloperatorcalculator/src/mysqloperatorcalculator"
"strconv"
"syscall"
)

func main() {
var my MO.MysqlOperatorCalculator
var moc MO.MysqlOperatorCalculator

testSupportedJson(my.GetSupportedLayouts(), my)
testSupportedJson(moc.GetSupportedLayouts(), moc)

testGetconfiguration(my)
testGetconfiguration(moc)

}

Expand Down Expand Up @@ -47,11 +48,24 @@ func testGetconfiguration(moc MO.MysqlOperatorCalculator) {
var myRequest MO.ConfigurationRequest
var err error

myRequest.LoadType = MO.LoadType{Id: 2}
myRequest.Dimension = MO.Dimension{Id: 999, Cpu: 4000, Memory: 2.5}
myRequest.DBType = "group_replication" //"pxc"
myRequest.Output = "human" //"human"
myRequest.Connections = 70
myRequest.LoadType = MO.LoadType{Id: MO.LoadTypeSomeWrites}
// Memory resource can be set as bytes using MemoryBytes ...
myRequest.Dimension = MO.Dimension{Id: MO.DimensionOpen, Cpu: 4000, MemoryBytes: 2684354560}
//OR in literal using M G GB etc with Memory
// We can assign the value...
myRequest.Dimension = MO.Dimension{Id: MO.DimensionOpen, Cpu: 4000, Memory: "2.5G"}
// Then convert and validate it if it follows the standards:
var errConv error
myRequest.Dimension.MemoryBytes, errConv = myRequest.Dimension.ConvertMemoryToBytes(myRequest.Dimension.Memory)
// If any error then do what you want ...
if errConv != nil {
println(errConv.Error())
syscall.Exit(1)
}

myRequest.DBType = MO.DbTypeGroupReplication //"pxc"
myRequest.Output = MO.ResultOutputFormatHuman //"human"
myRequest.Connections = 0
myRequest.Mysqlversion = MO.Version{8, 0, 33}

moc.Init(myRequest)
Expand All @@ -64,6 +78,74 @@ func testGetconfiguration(moc MO.MysqlOperatorCalculator) {
fmt.Errorf(strconv.Itoa(responseMessage.MType) + ": " + responseMessage.MName + " " + responseMessage.MText)
}
if len(families) > 0 {

// IF Using HUMAN than:
// we can use the by group parsing option:
//----------------------------------------------------------
//1 Parsing families and Groups one by one
//----------------------------------------------------------

// Parsing MySQL
MySQLfamily, err1 := moc.GetFamily(MO.FamilyTypeMysql)
if err1 != nil {
print(err1.Error())
}
mysqlStBuffer, err1 := MySQLfamily.ParseFamilyGroup(MO.GroupNameMySQLd, " ")
probesStBuffer, err1 := MySQLfamily.ParseFamilyGroup(MO.GroupNameProbes, " ")
resourcesStBuffer, err1 := MySQLfamily.ParseFamilyGroup(MO.GroupNameResources, " ")

if err1 == nil {
println("[mysql configuration]")
println(mysqlStBuffer.String())
println("[mysql probes]")
println(probesStBuffer.String())
println("[mysql resources]")
println(resourcesStBuffer.String())
} else {
println(err1.Error())
}

//Parsing Proxy
proxyFamily, err1 := moc.GetFamily(MO.FamilyTypeProxy)
if err1 != nil {
print(err1.Error())
}
proxyStBuffer, err1 := proxyFamily.ParseFamilyGroup(MO.GroupNameHAProxy, " ")
proxyProbesStBuffer, err1 := proxyFamily.ParseFamilyGroup(MO.GroupNameProbes, " ")
proxyResourcesStBuffer, err1 := proxyFamily.ParseFamilyGroup(MO.GroupNameResources, " ")
if err1 == nil {
println("[haproxy configuration]")
println(proxyStBuffer.String())
println("[haproxy probes]")
println(proxyProbesStBuffer.String())
println("[haproxy resources]")
println(proxyResourcesStBuffer.String())

} else {
println(err1.Error())
}

//Parsing Monitoring
monitorFamily, err1 := moc.GetFamily(MO.FamilyTypeMonitor)
if err1 != nil {
print(err1.Error())
}
monitorProbesStBuffer, err1 := monitorFamily.ParseFamilyGroup(MO.GroupNameProbes, " ")
monitorResourcesStBuffer, err1 := monitorFamily.ParseFamilyGroup(MO.GroupNameResources, " ")
if err1 == nil {
println("[monitor probes]")
println(monitorProbesStBuffer.String())
println("[monitor resources]")
println(monitorResourcesStBuffer.String())

} else {
println(err1.Error())
}

//----------------------------------------------------------
//2 Parsing All in one shot (mainly for Json output)
//----------------------------------------------------------

if myRequest.Output == "json" {
b, err = moc.GetJSONOutput(responseMessage, myRequest, families)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ To get supported scenarios:
to test:
curl -i -X GET -H "Content-Type: application/json" -d '{"output":"human","dbtype":"pxc", "dimension": {"id": 2}, "loadtype": {"id": 2}, "connections": 5}' http://127.0.0.1:8080/calculator
curl -i -X GET -H "Content-Type: application/json" -d '{"output":"human","dbtype":"pxc", "dimension": {"id": 2}, "loadtype": {"id": 2}, "connections": 5,"mysqlversion":{"major":8,"minor":0,"patch":33}}' http://127.0.0.1:8080/calculator
Expand Down
Loading

0 comments on commit 450a902

Please sign in to comment.