Skip to content

Commit

Permalink
enabled prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag4DSB committed Dec 18, 2024
1 parent 08e8c70 commit 8fa0c4f
Show file tree
Hide file tree
Showing 5 changed files with 497 additions and 7 deletions.
27 changes: 21 additions & 6 deletions cmd/scality-cosi-driver/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,25 @@ import (
"context"
"flag"
"fmt"
"time"

"github.com/scality/cosi-driver/pkg/driver"
"k8s.io/klog/v2"

"github.com/scality/cosi-driver/pkg/grpcfactory"
"github.com/scality/cosi-driver/pkg/metrics"
"k8s.io/klog/v2"
)

const (
// TODO: add to constants
provisionerName = "scality.com"
defaultDriverPrefix = "cosi"
)

var (
driverAddress = flag.String("driver-address", "unix:///var/lib/cosi/cosi.sock", "driver address for the socket")
driverPrefix = flag.String("driver-prefix", "", "prefix for COSI driver, e.g. <prefix>.scality.com")
// TODO: add to constants
driverAddress = flag.String("driver-address", "unix:///var/lib/cosi/cosi.sock", "driver address for the socket")
driverPrefix = flag.String("driver-prefix", "", "prefix for COSI driver, e.g. <prefix>.scality.com")
metricsAddress = flag.String("metrics-address", ":8080", "The address to expose Prometheus metrics.")
)

func init() {
Expand All @@ -53,8 +57,12 @@ func init() {
}

func run(ctx context.Context) error {
driverName := *driverPrefix + "." + provisionerName
metricsServer, err := metrics.StartMetricsServer(*metricsAddress)
if err != nil {
return fmt.Errorf("failed to start metrics server: %w", err)
}

driverName := *driverPrefix + "." + provisionerName
identityServer, bucketProvisioner, err := driver.CreateDriver(ctx, driverName)
if err != nil {
return fmt.Errorf("failed to initialize Scality driver: %w", err)
Expand All @@ -65,5 +73,12 @@ func run(ctx context.Context) error {
return fmt.Errorf("failed to start the provisioner server: %w", err)
}

return server.Run(ctx)
err = server.Run(ctx)
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer shutdownCancel()
if err2 := metricsServer.Shutdown(shutdownCtx); err2 != nil {
klog.ErrorS(err2, "Failed to gracefully shutdown metrics server")
}

return err
}
2 changes: 1 addition & 1 deletion cmd/scality-cosi-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func main() {
}
}()

// Call the run function (defined in cmd.go)
if err := run(ctx); err != nil {
klog.ErrorS(err, "Scality COSI driver encountered an error, shutting down")
os.Exit(1)
}
}
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/aws/smithy-go v1.22.1
github.com/onsi/ginkgo/v2 v2.22.0
github.com/onsi/gomega v1.36.1
github.com/prometheus/client_golang v1.12.1
google.golang.org/grpc v1.69.0
k8s.io/client-go v0.31.3
k8s.io/klog/v2 v2.130.1
Expand All @@ -28,6 +29,12 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.24.7 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
)

Expand Down
Loading

0 comments on commit 8fa0c4f

Please sign in to comment.