Skip to content

Commit 6c8bf97

Browse files
author
Bartłomiej Święcki
committed
chore(remotestorage): Add prometheus metrics for remote storage kind
Signed-off-by: Bartłomiej Święcki <[email protected]>
1 parent fbde7d8 commit 6c8bf97

File tree

9 files changed

+38
-0
lines changed

9 files changed

+38
-0
lines changed

embedded/appendable/remoteapp/remote_app_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ type remoteStorageMockingWrapper struct {
404404
fnListEntries func(ctx context.Context, path string, next func() (entries []remotestorage.EntryInfo, subPaths []string, err error)) (entries []remotestorage.EntryInfo, subPaths []string, err error)
405405
}
406406

407+
func (r *remoteStorageMockingWrapper) Kind() string {
408+
return r.wrapped.Kind()
409+
}
410+
407411
func (r *remoteStorageMockingWrapper) String() string {
408412
return r.wrapped.String()
409413
}

embedded/remotestorage/memory/memory.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func Open() *Storage {
4949
}
5050
}
5151

52+
func (r *Storage) Kind() string {
53+
return "memory"
54+
}
55+
5256
func (r *Storage) String() string {
5357
return fmt.Sprintf("memory(%p):", r)
5458
}

embedded/remotestorage/memory/memory_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func TestRemoteStorageAPIMemoryPutError(t *testing.T) {
169169
func TestRemoteStorageName(t *testing.T) {
170170
storage := Open()
171171
require.Contains(t, storage.String(), "memory")
172+
require.Equal(t, "memory", storage.Kind())
172173
}
173174

174175
func TestRemoteStorageGetInvalidParams(t *testing.T) {

embedded/remotestorage/remote_storage.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type EntryInfo struct {
3131
}
3232

3333
type Storage interface {
34+
// Kind returns the kind of remote storage, e.g. `s3`
35+
Kind() string
36+
3437
// String returns a human-readable representation of the storage
3538
String() string
3639

embedded/remotestorage/s3/s3.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ func Open(
120120
}, nil
121121
}
122122

123+
func (s *Storage) Kind() string {
124+
return "s3"
125+
}
126+
123127
func (s *Storage) String() string {
124128
url, err := s.originalRequestURL("")
125129
if err != nil {

embedded/remotestorage/s3/s3_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestOpen(t *testing.T) {
4141
)
4242
require.NoError(t, err)
4343
require.NotNil(t, s)
44+
require.Equal(t, "s3", s.Kind())
4445
require.Equal(t, "s3:http://localhost:9000/immudb/prefix/", s.String())
4546
}
4647

pkg/server/metrics.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ type MetricsCollection struct {
5555

5656
RPCsPerClientCounters *prometheus.CounterVec
5757
LastMessageAtPerClientGauges *prometheus.GaugeVec
58+
59+
RemoteStorageKind *prometheus.GaugeVec
5860
}
5961

6062
var metricsNamespace = "immudb"
@@ -141,6 +143,14 @@ var Metrics = MetricsCollection{
141143
},
142144
[]string{"ip"},
143145
),
146+
RemoteStorageKind: promauto.NewGaugeVec(
147+
prometheus.GaugeOpts{
148+
Namespace: metricsNamespace,
149+
Name: "remote_storage_kind",
150+
Help: "Set to 1 for remote storage kind for given database",
151+
},
152+
[]string{"db", "kind"},
153+
),
144154
}
145155

146156
// StartMetrics listens and servers the HTTP metrics server in a new goroutine.

pkg/server/remote_storage.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ func (s *ImmuServer) storeOptionsForDB(name string, remoteStorage remotestorage.
152152
}).
153153
WithFileSize(1 << 20). // Reduce file size for better cache granularity
154154
WithCompactionDisabled(true) // Disable index compaction
155+
156+
Metrics.RemoteStorageKind.WithLabelValues(name, remoteStorage.Kind()).Set(1)
157+
158+
} else {
159+
160+
// No remote storage
161+
Metrics.RemoteStorageKind.WithLabelValues(name, "none").Set(1)
155162
}
156163

157164
return stOpts

pkg/server/remote_storage_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ type remoteStorageMockingWrapper struct {
4343
fnListEntries func(ctx context.Context, path string, next func() (entries []remotestorage.EntryInfo, subPaths []string, err error)) (entries []remotestorage.EntryInfo, subPaths []string, err error)
4444
}
4545

46+
func (r *remoteStorageMockingWrapper) Kind() string {
47+
return r.wrapped.Kind()
48+
}
49+
4650
func (r *remoteStorageMockingWrapper) String() string {
4751
return r.wrapped.String()
4852
}

0 commit comments

Comments
 (0)