Skip to content

Commit

Permalink
COSI-65: Update metrics address example and CI doc
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag4DSB committed Jan 7, 2025
1 parent e4b65e3 commit c1fcbef
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .github/scripts/e2e_tests_metrics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ log_and_run kubectl port-forward -n "$NAMESPACE" svc/"$SERVICE" "$LOCAL_PORT":"$
PORT_FORWARD_PID=$!

# Wait a few seconds to ensure port-forward is established
log_and_run sleep 5
while ! nc -vz localhost $LOCAL_PORT > /dev/null 2>&1 ; do
# echo sleeping
sleep 0.1
done

# Fetch metrics
log_and_run curl -s http://localhost:$LOCAL_PORT/metrics > /tmp/metrics_output.log
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/e2e-feature-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,14 @@ jobs:
run: |
.github/scripts/e2e_tests_brownfield_use_case.sh
# the script accepts number of requests for APIs for CREATE_BUCKET, DELETE_BUCKET, GET_INFO
# the script accepts number of requests for APIs: CREATE_BUCKET, DELETE_BUCKET, GET_INFO
# GRANT_ACCESS and REVOKE_ACCESS in order
# Example below we we are testing for 2 CREATE_BUCKET, 1 DELETE_BUCKET,
# 1 GET_INFO, 2 GRANT_ACCESS and 2 REVOKE_ACCESS API counts
# Example below we are testing for those API counts:
# - 2 CREATE_BUCKET
# - 1 DELETE_BUCKET
# - 1 GET_INFO
# - 2 GRANT_ACCESS
# - 2 REVOKE_ACCESS
- name: E2E tests for metrics using API call metrics generated from above tests
run: |
.github/scripts/e2e_tests_metrics.sh 2 1 1 2 2
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/helm-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ jobs:
run: |
.github/scripts/verify_helm_install.sh
# the script accepts number of requests for APIs for CREATE_BUCKET, DELETE_BUCKET, GET_INFO
# the script accepts number of requests for APIs: CREATE_BUCKET, DELETE_BUCKET, GET_INFO
# GRANT_ACCESS and REVOKE_ACCESS in order
# Example below we we are testing for 0 CREATE_BUCKET, 0 DELETE_BUCKET,
# 1 GET_INFO, 0 GRANT_ACCESS and 0 REVOKE_ACCESS API counts
# Example below we are testing for those API counts:
# - 0 CREATE_BUCKET
# - 0 DELETE_BUCKET
# - 1 GET_INFO
# - 0 GRANT_ACCESS
# - 0 REVOKE_ACCESS
- name: Verify metrics for healthcheck route
run: |
.github/scripts/e2e_tests_metrics.sh 0 0 1 0 0
Expand Down
9 changes: 4 additions & 5 deletions cmd/scality-cosi-driver/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ const (

var (
driverAddress = flag.String("driver-address", defaultDriverAddress, "driver address for the socket file, default: unix:///var/lib/cosi/cosi.sock")
driverPrefix = flag.String("driver-prefix", defaultDriverPrefix, "prefix for COSI driver, e.g. <prefix>.scality.com, default cosi.scality.com")
driverMetricsAddress = flag.String("driver-metrics-address", defaultMetricsAddress, "The address to expose Prometheus metrics, default: :8080")
driverPrefix = flag.String("driver-prefix", defaultDriverPrefix, "prefix for COSI driver, e.g. <prefix>.scality.com, default: cosi")
driverMetricsAddress = flag.String("driver-metrics-address", defaultMetricsAddress, "The address (hostname:port) to expose Prometheus metrics, default: 0.0.0.0:8080")
driverMetricsPath = flag.String("driver-metrics-path", defaultMetricsPath, "path for the metrics endpoint, default: /metrics")
driverMetricsPrefix = flag.String("driver-custom-metrics-prefix", defaultMetricsPrefix, "prefix for the metrics, default: scality_cosi_driver_")
driverMetricsPrefix = flag.String("driver-custom-metrics-prefix", defaultMetricsPrefix, "prefix for the metrics, default: scality_cosi_driver")
)

func init() {
Expand Down Expand Up @@ -89,8 +89,7 @@ func run(ctx context.Context) error {
}

err = server.Run(ctx, registry)
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer shutdownCancel()
shutdownCtx, _ := context.WithTimeout(context.Background(), 5*time.Second)
if shutdownErr := metricsServer.Shutdown(shutdownCtx); shutdownErr != nil {
klog.ErrorS(shutdownErr, "Failed to gracefully shutdown metrics server")
}
Expand Down
2 changes: 1 addition & 1 deletion docs/metrics-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ grpc_server_started_total{grpc_method="DriverGetInfo",grpc_service="cosi.v1alpha

## Additional Resource

- [gRPC-Go Prometheus Metrics](https://github.com/grpc-ecosystem/go-grpc-prometheus)
- [gRPC-Go Prometheus Metrics](https://github.com/grpc-ecosystem/go-grpc-middleware)
- [Default Prometheus Metrics](https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#pkg-subdirectories)
2 changes: 1 addition & 1 deletion pkg/grpcfactory/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *COSIProvisionerServer) Run(ctx context.Context, registry prometheus.Reg

srvMetrics := grpcprom.NewServerMetrics(
grpcprom.WithServerHandlingTimeHistogram(
grpcprom.WithHistogramBuckets([]float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120}),
grpcprom.WithHistogramBuckets([]float64{0.01, 0.1, 0.5, 1, 2, 5}),
),
)
if err := registry.Register(srvMetrics); err != nil {
Expand Down

0 comments on commit c1fcbef

Please sign in to comment.