Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: OCPP-J and Websocket server metrics #343

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

xBlaz3kx
Copy link
Contributor

@xBlaz3kx xBlaz3kx commented Feb 2, 2025

Proposed changes

Based on my feature request in #334, I added support for OCPP-J and Websocket server metrics.

Watch out for a breaking change: Go version updated to 1.22, because the OTel SDKs require at least 1.22.

  • Metrics support via OpenTelemetry SDK
  • Split websocket implementation in separate files for client and server (for readability purposes)
  • Added OCPPJ server metrics (inbound/outbound requests)
  • Added websocket metrics (connected clients, WIP on the message rate, etc)
  • Updated examples, so observabilty/metrics can be configured via env variables
  • Updated docker-compose for both TLS and non-tls examples so observability can be configured
  • Added makefile commands so deploying examples is easier

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of
them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before
merging your code.

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

List of things that should be noted/addressed in the future:

  1. In the example, OpenTelemetry SDK exports metrics via insecure GRPC only
  2. Havent added websocket request rate metric, which could be useful
  3. Potential Tracing integration?
  4. Currently, OCPPJ and websocket error metrics are not handled properly, as this is a proof of concept.
  5. Documentation update

type OcppMetricsError string

const (
ChargePointError = OcppMetricsError("charge_point_error")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any other suggestions for the errors?

@@ -58,8 +60,20 @@ func NewServer(wsServer ws.WsServer, dispatcher ServerDispatcher, stateHandler S
dispatcher.SetNetworkServer(wsServer)
dispatcher.SetPendingRequestState(stateHandler)

meterProvider := otel.GetMeterProvider()
metrics, err := newOcppMetrics(meterProvider, "")
if err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Error handling here should be improved

ocppj/server.go Outdated
jsonMessage, err := call.MarshalJSON()
if err != nil {
s.metrics.IncrementOutboundRequests(context.Background(), clientID, request.GetFeatureName(), nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Error handling not fully implemented


conn.SetPingHandler(func(appData string) error {
log.Debugf("ping received from %s", ws.ID())
ws.pingMessage <- []byte(appData)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: Measuring pingPong duration

Suggestions on the approach?

@xBlaz3kx xBlaz3kx changed the title Feature: OCPP-J and Websocket server observability Feature: OCPP-J and Websocket server metrics Feb 2, 2025
@xBlaz3kx xBlaz3kx force-pushed the feature/observability branch from 7a1d09a to a624578 Compare February 2, 2025 17:18
@xBlaz3kx
Copy link
Contributor Author

xBlaz3kx commented Feb 2, 2025

I'll need some help with this PR to capture metrics at points where it makes most sense and since Im not that familiar with the flows right now, Im open to suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant