flyte
flyte copied to clipboard
[Docs] .hostname is not available in log templates
Description
.hostname is mentioned as variable in several places in docs but actually is not resolveable by code
https://github.com/flyteorg/flyteplugins/blob/b0684d97a1cf240f1a44f310f4a79cc21844caa9/go/tasks/pluginmachinery/tasklog/template.go#L69
Are you sure this issue hasn't been raised already?
- [X] Yes
Have you read the Code of Conduct?
- [X] Yes
🤖
Hey @olyashok! Good to see you back. Hope you're doing well!
Thank you for bringing this to our attention. Based on the code in the Flyte repository, the .hostname
variable is indeed resolvable.
The initDefaultRegexes()
function creates a regular expression for the hostname
variable using the MustCreateRegex()
function. This regular expression is then stored in the Hostname
field of the templateRegexes
struct.
Later, in the templateVarsForScheme()
function, the Hostname
regular expression is used to create a TemplateVar
struct, which pairs the regular expression with the actual value of the hostname (input.HostName
). This is done in the TemplateSchemePod
case of the switch statement.
Finally, in the GetTaskLogs()
function, the replaceAll()
function is called, which replaces all instances of the hostname
variable in the template string with the actual value of the hostname.
Here is the relevant code:
func initDefaultRegexes() templateRegexes {
return templateRegexes{
// ...
MustCreateRegex("hostname"),
// ...
}
}
// ...
func (input Input) templateVarsForScheme(scheme TemplateScheme) TemplateVars {
// ...
case TemplateSchemePod:
// ...
vars = append(
vars,
TemplateVar{defaultRegexes.Hostname, input.HostName},
)
// ...
}
// ...
}
// ...
func (p TemplateLogPlugin) GetTaskLogs(input Input) (Output, error) {
// ...
Uri: replaceAll(templateURI, templateVars),
// ...
}
As for the discrepancy between the Flyte documentation and the actual implementation of the .hostname
variable in the codebase, I wasn't able to find an answer within the repository. The same goes for any known issues or bugs related to the .hostname
variable in the Flyte codebase.
If you have more specific information or examples that could help clarify the issue, it would be greatly appreciated.
Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
good catch! Hostname is indeed not being handled right now, although it should be very easy to add. Before we add it, it's worth understanding how hostname is set in k8s, which is described here. We simply have to add hostname when instantiating taskLog.Input
here.
I am interested in this issue.
@novahow , feel free to work on it. Tag me on the PR and I'll gladly review it.