fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

mountinfo: introduce namespace config option (#447)

+23 -14
+1 -1
cmd/zoekt-sourcegraph-indexserver/main.go
··· 1073 1073 go oc.Run() 1074 1074 1075 1075 logger := sglog.Scoped("metricsRegistration", "") 1076 - mountinfo.MustRegisterNewMountPointInfoMetric(logger, map[string]string{"indexDir": conf.index}) 1076 + mountinfo.MustRegisterNewMountPointInfoMetric(logger, mountinfo.MountPointInfoOpts{Namespace: "zoekt_indexserver"}, map[string]string{"indexDir": conf.index}) 1077 1077 1078 1078 s.Run() 1079 1079 return nil
+1 -1
cmd/zoekt-webserver/main.go
··· 184 184 metricsLogger := sglog.Scoped("metricsRegistration", "") 185 185 186 186 mustRegisterMemoryMapMetrics(metricsLogger) 187 - mountinfo.MustRegisterNewMountPointInfoMetric(metricsLogger, map[string]string{"indexDir": *index}) 187 + mountinfo.MustRegisterNewMountPointInfoMetric(metricsLogger, mountinfo.MountPointInfoOpts{Namespace: "zoekt_webserver"}, map[string]string{"indexDir": *index}) 188 188 189 189 // Do not block on loading shards so we can become partially available 190 190 // sooner. Otherwise on large instances zoekt can be unavailable on the
+19 -10
internal/mountinfo/mountinfo.go
··· 17 17 // defaultSysMountPoint is the common mount point for the sysfs pseudo-filesystem. 18 18 const defaultSysMountPoint = "/sys" 19 19 20 + // MountPointInfoOpts modifies the behavior of the metric created 21 + // by MustRegisterNewMountPointInfoMetric. 22 + type MountPointInfoOpts struct { 23 + // If non-empty, Namespace prefixes the "mount_point_info" metric by the provided string and 24 + // an underscore ("_"). 25 + Namespace string 26 + } 27 + 20 28 // MustRegisterNewMountPointInfoMetric registers a Prometheus metric named "mount_point_info" that 21 29 // contains the names of the block storage devices that back each of the requested mounts. 22 30 // ··· 28 36 // 29 37 // This metric only works on Linux-based operating systems that have access to the sysfs pseudo-filesystem. 30 38 // On all other operating systems, this metric will not emit any values. 31 - func MustRegisterNewMountPointInfoMetric(logger sglog.Logger, mounts map[string]string) { 39 + func MustRegisterNewMountPointInfoMetric(logger sglog.Logger, opts MountPointInfoOpts, mounts map[string]string) { 32 40 logger = logger.Scoped("mountPointInfo", "registration logic for mount_point_info Prometheus metric") 33 41 34 42 metric := promauto.NewGaugeVec(prometheus.GaugeOpts{ 35 - Name: "mount_point_info", 36 - Help: "An info metric with a constant '1' value that contains mount_name, device mappings", 43 + Namespace: opts.Namespace, 44 + Name: "mount_point_info", 45 + Help: "An info metric with a constant '1' value that contains mount_name, device mappings", 37 46 }, []string{"mount_name", "device"}) 38 47 39 48 // This device discovery logic relies on the sysfs pseudo-filesystem, which only exists ··· 52 61 sglog.String("mountFilePath", filePath), 53 62 ) 54 63 55 - device, err := discoverDeviceName(discoveryLogger, discoverDeviceNameConfig{}, filePath) 64 + device, err := discoverDeviceName(discoveryLogger, discoverDeviceNameOpts{}, filePath) 56 65 if err != nil { 57 66 discoveryLogger.Warn("skipping metric registration", 58 67 sglog.String("reason", "failed to discover device name"), ··· 70 79 } 71 80 } 72 81 73 - type discoverDeviceNameConfig struct { 82 + type discoverDeviceNameOpts struct { 74 83 // sysfsMountPoint is the location of the sysfs mount point. 75 84 // If empty, defaultSysMountPoint will be used instead. 76 85 sysfsMountPoint string ··· 83 92 84 93 // discoverDeviceName returns the name of the block device that filePath is 85 94 // stored on. 86 - func discoverDeviceName(logger sglog.Logger, config discoverDeviceNameConfig, filePath string) (string, error) { 95 + func discoverDeviceName(logger sglog.Logger, opts discoverDeviceNameOpts, filePath string) (string, error) { 87 96 // Note: It's quite involved to implement the device discovery logic for 88 97 // every possible kind of storage device (e.x. logical volumes, NFS, etc.) See 89 98 // https://unix.stackexchange.com/a/11312 for more information. ··· 105 114 // - https://www.kernel.org/doc/ols/2005/ols2005v1-pages-321-334.pdf 106 115 107 116 getDeviceNumber := getDeviceNumber 108 - if config.getDeviceNumber != nil { 109 - getDeviceNumber = config.getDeviceNumber 117 + if opts.getDeviceNumber != nil { 118 + getDeviceNumber = opts.getDeviceNumber 110 119 } 111 120 112 121 sysfsMountPoint := defaultSysMountPoint 113 - if config.sysfsMountPoint != "" { 114 - sysfsMountPoint = config.sysfsMountPoint 122 + if opts.sysfsMountPoint != "" { 123 + sysfsMountPoint = opts.sysfsMountPoint 115 124 } 116 125 117 126 sysfsMountPoint = filepath.Clean(sysfsMountPoint)
+1 -1
internal/mountinfo/mountinfo_linux_test.go
··· 20 20 log.Fatalf("getting current working directory: %s", err) 21 21 } 22 22 23 - device, err := discoverDeviceName(logger, discoverDeviceNameConfig{}, filePath) 23 + device, err := discoverDeviceName(logger, discoverDeviceNameOpts{}, filePath) 24 24 if err != nil { 25 25 t.Fatalf("discovering device name for file path %q: %s", filePath, err) 26 26 }
+1 -1
internal/mountinfo/mountinfo_test.go
··· 114 114 // execute the test with our injected mocks 115 115 actualDeviceName, err := discoverDeviceName( 116 116 logger, 117 - discoverDeviceNameConfig{ 117 + discoverDeviceNameOpts{ 118 118 sysfsMountPoint: mockSysFSDir, 119 119 getDeviceNumber: mockGetDeviceNumber, 120 120 },