Skip to content

Commit

Permalink
incusd/loki: Set location field to local hostname on standalone systems
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Apr 17, 2024
1 parent 142c58b commit 4791c96
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cmd/incusd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,22 +788,24 @@ func (d *Daemon) setupLoki(URL string, cert string, key string, caCert string, i
return err
}

// Figure out the instance name.
if instanceName == "" {
if d.serverClustered {
instanceName = d.serverName
} else {
hostname, err := os.Hostname()
if err != nil {
return err
}
// Handle standalone systems.
var location string
if !d.serverClustered {
hostname, err := os.Hostname()
if err != nil {
return err
}

location = hostname
if instanceName == "" {
instanceName = hostname
}
} else if instanceName == "" {
instanceName = d.serverName
}

// Start a new client.
d.lokiClient = loki.NewClient(d.shutdownCtx, u, cert, key, caCert, instanceName, logLevel, labels, types)
d.lokiClient = loki.NewClient(d.shutdownCtx, u, cert, key, caCert, instanceName, location, logLevel, labels, types)

// Attach the new client to the log handler.
d.internalListener.AddHandler("loki", d.lokiClient.HandleEvent)
Expand Down

0 comments on commit 4791c96

Please sign in to comment.