-
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(queryLog): log instance hostname to distinguish log entries in m…
…ulti-instance installation(#319) (#756) * added hostname to util * added HostnameString * some leftover debug output? * added hostname to querylog * add optional volume mounts to documentation * changed documentation
- Loading branch information
Showing
7 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,40 @@ | ||
package util | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
) | ||
|
||
//nolint:gochecknoglobals | ||
var ( | ||
hostname string | ||
hostnameErr error | ||
) | ||
|
||
const hostnameFile string = "/etc/hostname" | ||
|
||
//nolint:gochecknoinits | ||
func init() { | ||
getHostname(hostnameFile) | ||
} | ||
|
||
// Direct replacement for os.Hostname | ||
func Hostname() (string, error) { | ||
return hostname, hostnameErr | ||
} | ||
|
||
// Only return the hostname(may be empty if there was an error) | ||
func HostnameString() string { | ||
return hostname | ||
} | ||
|
||
func getHostname(location string) { | ||
hostname, hostnameErr = os.Hostname() | ||
|
||
if hn, err := os.ReadFile(location); err == nil { | ||
hostname = strings.TrimSpace(string(hn)) | ||
hostnameErr = nil | ||
|
||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,52 @@ | ||
package util | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
"github.com/0xERR0R/blocky/helpertest" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Hostname function tests", func() { | ||
When("file is present", func() { | ||
var ( | ||
tmpDir *helpertest.TmpFolder | ||
) | ||
|
||
BeforeEach(func() { | ||
tmpDir = helpertest.NewTmpFolder("hostname") | ||
Expect(tmpDir.Error).Should(Succeed()) | ||
DeferCleanup(tmpDir.Clean) | ||
}) | ||
|
||
It("should be used", func() { | ||
tmpFile := tmpDir.CreateStringFile("filetest1", "TestName ") | ||
Expect(tmpFile.Error).Should(Succeed()) | ||
getHostname(tmpFile.Path) | ||
|
||
fhn, err := os.ReadFile(tmpFile.Path) | ||
Expect(err).Should(Succeed()) | ||
|
||
hn, err := Hostname() | ||
Expect(err).Should(Succeed()) | ||
|
||
Expect(hn).Should(Equal(strings.TrimSpace(string(fhn)))) | ||
}) | ||
}) | ||
|
||
When("file is not present", func() { | ||
It("should use os.Hostname", func() { | ||
getHostname("/does-not-exist") | ||
|
||
_, err := Hostname() | ||
Expect(err).Should(Succeed()) | ||
|
||
ohn, err := os.Hostname() | ||
Expect(err).Should(Succeed()) | ||
|
||
Expect(HostnameString()).Should(Equal(ohn)) | ||
}) | ||
}) | ||
}) |