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

feat: add prometheus metrics support #37

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

j-bro
Copy link

@j-bro j-bro commented Oct 31, 2023

TODO

❯ go run ./cmd/cli -addr http://127.0.0.1:9000/metrics -proto prom
{
        "current_players": 1,
        "max_players": 2,
        "server_name": "Name",
        "game_type": "Game Type",
        "map": "Map",
        "port": 1000
}

@j-bro j-bro requested a review from a team as a code owner October 31, 2023 19:30
cmd/cli/bulk.go Outdated
@@ -156,7 +156,7 @@ func processBulkEntry(entry string) (*BulkResponseItem, error) {
return item, nil
}

client, err := svrquery.NewClient(querySection, addressSection, options...)
client, err := svrquery.NewUDPClient(querySection, addressSection, options...)
Copy link
Author

Choose a reason for hiding this comment

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

Will fix this

@j-bro j-bro requested a review from lwaddicor October 31, 2023 19:34
@j-bro j-bro self-assigned this Oct 31, 2023
@j-bro j-bro marked this pull request as draft October 31, 2023 19:34
Copy link
Collaborator

@lwaddicor lwaddicor left a comment

Choose a reason for hiding this comment

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

Starting to form up, a few points of feedback

cmd/cli/main.go Outdated
"github.com/multiplay/go-svrquery/lib/svrsample"
"github.com/multiplay/go-svrquery/lib/svrsample/common"
"log"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Import ordering here is wrong

// NewClient creates a new client that talks to addr.
func NewClient(proto, addr string, options ...Option) (*Client, error) {
// NewUDPClient creates a new client that talks to addr.
func NewUDPClient(proto, addr string, options ...Option) (*UDPClient, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is going to break users of the library as NewClient is publicly exported and the main way people will interact with the client.

Can we either have the struct do both or abstract it internally?

@@ -23,6 +23,7 @@ type Mapper interface {
// Client is an interface which is implemented by types which can act a query transport.
type Client interface {
io.ReadWriteCloser
Queryer
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of interest, is this just usability? I see we populate this from the protocol.Get(...) call so seems sensible but just checking

Copy link
Author

Choose a reason for hiding this comment

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

Mainly since I now have 2 types of clients, the interface was needed so that main.go can use them as both io.ReadWriteCloser and Queryer (the UDP client implementation already implemented both). But I'll rework the client to make it backwards compatible so this might change again.

resp.MaxPlayers = *v.Metric[0].Gauge.Value
case serverInfoMetricName:
if len(v.Metric) == 0 || v.Metric[0] == nil || len(v.Metric[0].Label) == 0 {
slog.Error("server_info metric is missing labels")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Logging messages like this will break the cli responses (e.g. when in json output mode) and in libraries is usually not done as you don't know the log format of the application running the code

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