···184184 metricsLogger := sglog.Scoped("metricsRegistration", "")
185185186186 mustRegisterMemoryMapMetrics(metricsLogger)
187187- mountinfo.MustRegisterNewMountPointInfoMetric(metricsLogger, map[string]string{"indexDir": *index})
187187+ mountinfo.MustRegisterNewMountPointInfoMetric(metricsLogger, mountinfo.MountPointInfoOpts{Namespace: "zoekt_webserver"}, map[string]string{"indexDir": *index})
188188189189 // Do not block on loading shards so we can become partially available
190190 // sooner. Otherwise on large instances zoekt can be unavailable on the
+19-10
internal/mountinfo/mountinfo.go
···1717// defaultSysMountPoint is the common mount point for the sysfs pseudo-filesystem.
1818const defaultSysMountPoint = "/sys"
19192020+// MountPointInfoOpts modifies the behavior of the metric created
2121+// by MustRegisterNewMountPointInfoMetric.
2222+type MountPointInfoOpts struct {
2323+ // If non-empty, Namespace prefixes the "mount_point_info" metric by the provided string and
2424+ // an underscore ("_").
2525+ Namespace string
2626+}
2727+2028// MustRegisterNewMountPointInfoMetric registers a Prometheus metric named "mount_point_info" that
2129// contains the names of the block storage devices that back each of the requested mounts.
2230//
···2836//
2937// This metric only works on Linux-based operating systems that have access to the sysfs pseudo-filesystem.
3038// On all other operating systems, this metric will not emit any values.
3131-func MustRegisterNewMountPointInfoMetric(logger sglog.Logger, mounts map[string]string) {
3939+func MustRegisterNewMountPointInfoMetric(logger sglog.Logger, opts MountPointInfoOpts, mounts map[string]string) {
3240 logger = logger.Scoped("mountPointInfo", "registration logic for mount_point_info Prometheus metric")
33413442 metric := promauto.NewGaugeVec(prometheus.GaugeOpts{
3535- Name: "mount_point_info",
3636- Help: "An info metric with a constant '1' value that contains mount_name, device mappings",
4343+ Namespace: opts.Namespace,
4444+ Name: "mount_point_info",
4545+ Help: "An info metric with a constant '1' value that contains mount_name, device mappings",
3746 }, []string{"mount_name", "device"})
38473948 // This device discovery logic relies on the sysfs pseudo-filesystem, which only exists
···5261 sglog.String("mountFilePath", filePath),
5362 )
54635555- device, err := discoverDeviceName(discoveryLogger, discoverDeviceNameConfig{}, filePath)
6464+ device, err := discoverDeviceName(discoveryLogger, discoverDeviceNameOpts{}, filePath)
5665 if err != nil {
5766 discoveryLogger.Warn("skipping metric registration",
5867 sglog.String("reason", "failed to discover device name"),
···7079 }
7180}
72817373-type discoverDeviceNameConfig struct {
8282+type discoverDeviceNameOpts struct {
7483 // sysfsMountPoint is the location of the sysfs mount point.
7584 // If empty, defaultSysMountPoint will be used instead.
7685 sysfsMountPoint string
···83928493// discoverDeviceName returns the name of the block device that filePath is
8594// stored on.
8686-func discoverDeviceName(logger sglog.Logger, config discoverDeviceNameConfig, filePath string) (string, error) {
9595+func discoverDeviceName(logger sglog.Logger, opts discoverDeviceNameOpts, filePath string) (string, error) {
8796 // Note: It's quite involved to implement the device discovery logic for
8897 // every possible kind of storage device (e.x. logical volumes, NFS, etc.) See
8998 // https://unix.stackexchange.com/a/11312 for more information.
···105114 // - https://www.kernel.org/doc/ols/2005/ols2005v1-pages-321-334.pdf
106115107116 getDeviceNumber := getDeviceNumber
108108- if config.getDeviceNumber != nil {
109109- getDeviceNumber = config.getDeviceNumber
117117+ if opts.getDeviceNumber != nil {
118118+ getDeviceNumber = opts.getDeviceNumber
110119 }
111120112121 sysfsMountPoint := defaultSysMountPoint
113113- if config.sysfsMountPoint != "" {
114114- sysfsMountPoint = config.sysfsMountPoint
122122+ if opts.sysfsMountPoint != "" {
123123+ sysfsMountPoint = opts.sysfsMountPoint
115124 }
116125117126 sysfsMountPoint = filepath.Clean(sysfsMountPoint)
+1-1
internal/mountinfo/mountinfo_linux_test.go
···2020 log.Fatalf("getting current working directory: %s", err)
2121 }
22222323- device, err := discoverDeviceName(logger, discoverDeviceNameConfig{}, filePath)
2323+ device, err := discoverDeviceName(logger, discoverDeviceNameOpts{}, filePath)
2424 if err != nil {
2525 t.Fatalf("discovering device name for file path %q: %s", filePath, err)
2626 }
+1-1
internal/mountinfo/mountinfo_test.go
···114114 // execute the test with our injected mocks
115115 actualDeviceName, err := discoverDeviceName(
116116 logger,
117117- discoverDeviceNameConfig{
117117+ discoverDeviceNameOpts{
118118 sysfsMountPoint: mockSysFSDir,
119119 getDeviceNumber: mockGetDeviceNumber,
120120 },