Allow multiple SAP system tags per host #160
Conversation
@rtorrero I would appreciate some screenshots of the changed templates of the frontend |
yes! I wanted to post some but my test environment is broken right now. Deploying a new one and should be able to add them soon |
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.
Hi @rtorrero ,
Many comments hehe
In general the implementation looks good, but I think we can remove and re-order many of the new changes.
Finally, as added in independent comment, it would be nice to have a screenshot/gif of the final result
agent/discovery/sapsystem.go
Outdated
@@ -33,33 +33,49 @@ func (d SAPSystemsDiscovery) Discover() error { | |||
return err | |||
} | |||
|
|||
sapSystems := make([]*sapsystem.SAPSystem, len(systems)) |
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.
Do we really need a new variable sapSystems
to store this information?
This looks like a replica of the systems/d.SAPSystems
variable just changing the map to list format
(systems
is of sapsystem.SAPSystemsList
, which is already a list)
agent/discovery/sapsystem.go
Outdated
envName, landName, sysName, err := loadSAPSystemTags(client, system.SID) | ||
if err != nil { | ||
return err | ||
func storeSAPSystemTags(client consul.Client, systems []*sapsystem.SAPSystem) error { |
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.
As commented above, I think we could use sapsystem.SAPSystemsList
as systems
type
agent/discovery/sapsystem.go
Outdated
var envName, landName string | ||
sysNames := "" | ||
var err error | ||
for i, system := range systems { |
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.
This looks a bit over complicated.
I suggest the next:
As envName
and landName
will be the same independtly which system.SID
we use, we could just call it once with the 1st SID.
After that, i would prefer the usage of strings.Join
to create the sids string. I don't know if we could use some kind of lamdba method to get the SID, otherwise we will need to loop though all the systems, create a SID string array, and apply the Join
function
internal/hosts/hosts.go
Outdated
return nil, err | ||
} | ||
|
||
systemsList := make(sapsystem.SAPSystemsList, len(systems)) |
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.
Why do we have this loop? Cannot we use directly the systems
map? At the end they have the same content
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 assume that by "using directly the systems
map you mean using the GetSAPSystems
method?
The thing is that if I use GetSAPSystems
in the template, I can't easily add a comma after each SID but the last one (since in a string map, each key is not an int but a string, so I can't easily figure out the len-1
case :/... It might be that I'm not familiar enough with templates. A bit more details if you can think of a way of using the string map in the template would help
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.
As we just need to split the string by the ,
, why don't we just add the Split
method to our templating system, so we can use it?
Here an example: https://stackoverflow.com/questions/19771787/golang-how-to-split-string-in-template
We would need to add the func here: https://github.com/trento-project/trento/blob/main/web/layout.go#L142
I see that you need this already 2 times, so it would make sense
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.
@rtorrero Some new comments
internal/hosts/hosts.go
Outdated
return nil, err | ||
} | ||
|
||
systemsList := make(sapsystem.SAPSystemsList, len(systems)) |
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.
As we just need to split the string by the ,
, why don't we just add the Split
method to our templating system, so we can use it?
Here an example: https://stackoverflow.com/questions/19771787/golang-how-to-split-string-in-template
We would need to add the func here: https://github.com/trento-project/trento/blob/main/web/layout.go#L142
I see that you need this already 2 times, so it would make sense
I think I've addressed all pending conversations; but be sure to take another look please @arbulu89 I'm aware of the repetition of code that happens between the two I've also added the missing screenshots now that my test env is working fine again |
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.
Hi @rtorrero ,
More comments
agent/discovery/sapsystem.go
Outdated
func storeSAPSystemTags(client consul.Client, system *sapsystem.SAPSystem) error { | ||
envName, landName, sysName, err := loadSAPSystemTags(client, system.SID) | ||
func storeSAPSystemTags(client consul.Client, systems sapsystem.SAPSystemsList) error { | ||
envName, landName, _, err := loadSAPSystemTags(client, systems[0].SID) |
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.
The loadSAPSystemTags
is only used here, so we could even remove this 3rd return value (which is not used)
@@ -107,6 +107,12 @@ func (l *Landscape) AddSystem(system *SAPSystem) { | |||
l.SAPSystems[system.Name] = system | |||
} | |||
|
|||
func (l *Landscape) AddSystems(systems []*SAPSystem) { |
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.
This new method is not used anywhere. I think you created this to replace the loop used above maybe, at line 62 of agent/discovery/sapsystem.go
.
You could whether remove this function or use it above replacing the loop (you might need to change the incoming variable type)
web/layout.go
Outdated
@@ -149,6 +150,9 @@ func (r *LayoutRender) addFileFromFS(templatesFS fs.FS, file string) { | |||
return a + b | |||
}, | |||
"markdown": markdownToHTML, | |||
"split": func(s string, sep string) []string { |
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.
Did you try just with "split": strings.Split
here?
web/templates/host.html.tmpl
Outdated
<dd class="inline"><a | ||
href="/sapsystems/{{ $SAPSys }}?environment={{ $Env }}&landscape={{ $Land }}">{{ $SAPSys }}</a> | ||
<dd class="inline"> | ||
{{- range $i, $v := split (.Host).GetSIDsString ","}}{{- if $i }},{{- end }} <a |
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.
Do we need this .Host.GetSIDsSting
function?
It will return the same value we have in the metadata, right?
I mean, why simply not: split (index .Host.TrentoMeta "trento-sap-systems) ","
And we get rid off GetSIDsString
function from the Host
struct
internal/sapsystem/sapsystem.go
Outdated
@@ -77,6 +78,26 @@ type CustomCommand func(name string, arg ...string) *exec.Cmd | |||
|
|||
var customExecCommand CustomCommand = exec.Command | |||
|
|||
func (sm SAPSystemsMap) GetSIDsString() string { |
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.
This duplication looks horrible hehe
I'm sure you will be able to remove this 1st function once you have remove the .Host.GetSIDstring
@arbulu89 should be fine now! thanks for the comments |
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.
Thanks @rtorrero ,
Now it looks great.
I have put some minor comments if you want to have a look
Sorry again... fixed |
This PR adds support for having multiple SIDs on the same host (useful in cost-optimized scenario). The host metadata field is now
trento-sap-systems
and the filters have been updated to allow matching e.g.PRD
in a host wherePRD,QAS
is stored in the metadata.Templates have been updated too to now show multiple SIDs where relevant.
Updated: Screenshots