Skip to content

Commit

Permalink
chore(remotestorage): Add prometheus metrics for remote storage kind
Browse files Browse the repository at this point in the history
Signed-off-by: Bartłomiej Święcki <bart@codenotary.com>
  • Loading branch information
Bartłomiej Święcki committed Jun 30, 2022
1 parent fbde7d8 commit 6c8bf97
Showing 9 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions embedded/appendable/remoteapp/remote_app_test.go
Original file line number Diff line number Diff line change
@@ -404,6 +404,10 @@ type remoteStorageMockingWrapper struct {
fnListEntries func(ctx context.Context, path string, next func() (entries []remotestorage.EntryInfo, subPaths []string, err error)) (entries []remotestorage.EntryInfo, subPaths []string, err error)
}

func (r *remoteStorageMockingWrapper) Kind() string {
return r.wrapped.Kind()
}

func (r *remoteStorageMockingWrapper) String() string {
return r.wrapped.String()
}
4 changes: 4 additions & 0 deletions embedded/remotestorage/memory/memory.go
Original file line number Diff line number Diff line change
@@ -49,6 +49,10 @@ func Open() *Storage {
}
}

func (r *Storage) Kind() string {
return "memory"
}

func (r *Storage) String() string {
return fmt.Sprintf("memory(%p):", r)
}
1 change: 1 addition & 0 deletions embedded/remotestorage/memory/memory_test.go
Original file line number Diff line number Diff line change
@@ -169,6 +169,7 @@ func TestRemoteStorageAPIMemoryPutError(t *testing.T) {
func TestRemoteStorageName(t *testing.T) {
storage := Open()
require.Contains(t, storage.String(), "memory")
require.Equal(t, "memory", storage.Kind())
}

func TestRemoteStorageGetInvalidParams(t *testing.T) {
3 changes: 3 additions & 0 deletions embedded/remotestorage/remote_storage.go
Original file line number Diff line number Diff line change
@@ -31,6 +31,9 @@ type EntryInfo struct {
}

type Storage interface {
// Kind returns the kind of remote storage, e.g. `s3`
Kind() string

// String returns a human-readable representation of the storage
String() string

4 changes: 4 additions & 0 deletions embedded/remotestorage/s3/s3.go
Original file line number Diff line number Diff line change
@@ -120,6 +120,10 @@ func Open(
}, nil
}

func (s *Storage) Kind() string {
return "s3"
}

func (s *Storage) String() string {
url, err := s.originalRequestURL("")
if err != nil {
1 change: 1 addition & 0 deletions embedded/remotestorage/s3/s3_test.go
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ func TestOpen(t *testing.T) {
)
require.NoError(t, err)
require.NotNil(t, s)
require.Equal(t, "s3", s.Kind())
require.Equal(t, "s3:http://localhost:9000/immudb/prefix/", s.String())
}

10 changes: 10 additions & 0 deletions pkg/server/metrics.go
Original file line number Diff line number Diff line change
@@ -55,6 +55,8 @@ type MetricsCollection struct {

RPCsPerClientCounters *prometheus.CounterVec
LastMessageAtPerClientGauges *prometheus.GaugeVec

RemoteStorageKind *prometheus.GaugeVec
}

var metricsNamespace = "immudb"
@@ -141,6 +143,14 @@ var Metrics = MetricsCollection{
},
[]string{"ip"},
),
RemoteStorageKind: promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "remote_storage_kind",
Help: "Set to 1 for remote storage kind for given database",
},
[]string{"db", "kind"},
),
}

// StartMetrics listens and servers the HTTP metrics server in a new goroutine.
7 changes: 7 additions & 0 deletions pkg/server/remote_storage.go
Original file line number Diff line number Diff line change
@@ -152,6 +152,13 @@ func (s *ImmuServer) storeOptionsForDB(name string, remoteStorage remotestorage.
}).
WithFileSize(1 << 20). // Reduce file size for better cache granularity
WithCompactionDisabled(true) // Disable index compaction

Metrics.RemoteStorageKind.WithLabelValues(name, remoteStorage.Kind()).Set(1)

} else {

// No remote storage
Metrics.RemoteStorageKind.WithLabelValues(name, "none").Set(1)
}

return stOpts
4 changes: 4 additions & 0 deletions pkg/server/remote_storage_test.go
Original file line number Diff line number Diff line change
@@ -43,6 +43,10 @@ type remoteStorageMockingWrapper struct {
fnListEntries func(ctx context.Context, path string, next func() (entries []remotestorage.EntryInfo, subPaths []string, err error)) (entries []remotestorage.EntryInfo, subPaths []string, err error)
}

func (r *remoteStorageMockingWrapper) Kind() string {
return r.wrapped.Kind()
}

func (r *remoteStorageMockingWrapper) String() string {
return r.wrapped.String()
}

0 comments on commit 6c8bf97

Please sign in to comment.