Skip to content

Feature - OpenTelemetry support #92

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

Merged
merged 16 commits into from
Aug 22, 2024

Conversation

vitorvasc
Copy link
Contributor

Description

This PR adds support to export metrics through Open Telemetry protocol, which makes it easier to handle the generated data and process it by using multiple backends.

At first, this will export the same metrics that are currently being exported for Telegraf or Prometheus:

  • minecraft_status_healthy
  • minecraft_status_response_time_seconds
  • minecraft_status_players_online_count
  • minecraft_status_players_max_count

However, I'll be looking for other possibilites and other metrics to gather, since they always can be useful for monitoring a server.

Next steps

In the future, I feel excited about expanding the telemetry support for mc-monitor, so we can be able to export other signals like logs or even traces (if we think that this can be useful at all).

Since this is my very first contribution for itzg/minecraft projects, I'm very open for any comments or suggestions!

Thanks in advance.

Copy link
Owner

@itzg itzg left a comment

Choose a reason for hiding this comment

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

Thanks! This is great. Just a few minor suggestions.

I really need to have been organizing the code better with not so many things in the main package. Do you mind putting your new files in an otel package similar to slp?

Comment on lines 49 to 62
func (m *serverMetrics) RecordResponseTime(responseTime float64, attributes []attribute.KeyValue) {
_, err := meter.Float64ObservableGauge(
"minecraft_status_response_time",
metric.WithDescription("The response time of the server"),
metric.WithUnit("ms"),
metric.WithFloat64Callback(
func(ctx context.Context, observer metric.Float64Observer) error {
observer.Observe(responseTime, metric.WithAttributes(attributes...))
return nil
},
),
)
handleError("Error creating response time metric", err)
}
Copy link
Owner

Choose a reason for hiding this comment

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

There's a fair amount of repetition across these methods. Would be nice to have a consolidated method that takes the necessary differences like the name and description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed a new commit trying to reduce the verbosity, at least creating a method that handles the description and other options.

Also, changed the type for minecraft_players_online_count and minecraft_players_max_count, that were using Float64. It makes more sense to use Int64.

@vitorvasc
Copy link
Contributor Author

Thanks! This is great. Just a few minor suggestions.

I really need to have been organizing the code better with not so many things in the main package. Do you mind putting your new files in an otel package similar to slp?

Sure! I'll move these OTel implementations into a separate package. Even being a small implementation, I'm missing some unit tests just to make sure that future changes won't break anything 😬

Once this PR is merged I can work on separating Telegraf and Prometheus into their own packages also. ;)

otel/metrics.go Outdated
}

func (m *serverMetrics) RecordHealth(healthy bool, attributes []attribute.KeyValue) {
_ = NewInt64ObservableGauge(
Copy link
Owner

Choose a reason for hiding this comment

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

I'm thinking it's better not to return the gauge from the new functions if it's always ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. We're not using for now and I think it will not have any use in the future!

@itzg itzg merged commit 2896e1b into itzg:master Aug 22, 2024
2 checks passed
@vitorvasc vitorvasc deleted the feature/opentelemetry-collector branch August 22, 2024 17:10
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.

2 participants