Skip to content

Conversation

@withinboredom
Copy link
Member

@withinboredom withinboredom commented Dec 15, 2024

closes #1225

This adds a new global set by -X ld variable, VersionString which is injected during the Docker build. This can be fetched via the frankenphp_version labels, as well as the current php version reported.


var metricsNameRegex = regexp.MustCompile(`\W+`)
var metricsNameFixRegex = regexp.MustCompile(`^_+|_+$`)
var VersionString = "dev"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe could you use https://pkg.go.dev/runtime/debug#ReadBuildInfo instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll take a look!

Copy link
Member

Choose a reason for hiding this comment

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

Actually, the version of the FrankenPHP module (and of all other installed modules) should already be exposed by Caddy: https://github.com/caddyserver/caddy/blob/v2.8.4/metrics.go#L15

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the string currently output from a production instance:

go_build_info{checksum="",path="github.com/dunglas/frankenphp/caddy",version="(devel)"} 1

It doesn't seem too useful :(

Copy link
Member

Choose a reason for hiding this comment

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

Hum this looks like an issue in my release script 😅 (because of the replace). Isn't the version of lib (not the Caddy module) displayed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what you mean, but that is the only thing in the metrics.

Copy link
Member

@dunglas dunglas Dec 20, 2024

Choose a reason for hiding this comment

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

I mean we should have the version of github.com/dunglas/frankenphp too

Copy link
Member Author

Choose a reason for hiding this comment

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

There are no dependencies listed, just the top-level.

@dunglas
Copy link
Member

dunglas commented Jan 28, 2025

I think the best fix would be to update our release pipeline to:

  • publish the new version of the github.com/dunglas/frankenphp module on pkg.go.dev
  • publish the new version of the github.com/dunglas/frankenphp/caddy module depending on the updated github.com/dunglas/frankenphp module on pkg.go.dev
  • build the binaries and the Docker images either using xcaddy, or a command depending on the newly released versions

@withinboredom
Copy link
Member Author

It looks like it is already there: https://pkg.go.dev/github.com/dunglas/frankenphp/caddy

So, to get the version string to show up properly, we just need to change how we are building it, if I understand correctly?

@withinboredom
Copy link
Member Author

Holy hell this was a rabbit hole. Apparently, prior to go 1.24, it was hardcoded to devel version unless it was installed via go install and only go install...

:sigh:

Since 1.24, it is now based on git tags when building locally:

# create tag on a branch with non-tracked files:
go_build_info{checksum="",path="github.com/dunglas/frankenphp/caddy",version="v1.4.3+dirty"}
# branch from main branch:
go_build_info{checksum="",path="github.com/dunglas/frankenphp/caddy",version="v1.4.2-0.20250215125226-cdbf1bd60113"}

So, do we want to upgrade from go 1.22 to 1.24 @dunglas?

@dunglas
Copy link
Member

dunglas commented Feb 17, 2025

Sure! We'll upgrade to Go 1.24 as soon as dependencies (especially Caddy) are compatible with it.

@dunglas
Copy link
Member

dunglas commented Mar 4, 2025

Now that we upgraded to Go 1.24, we get go_build_info{checksum="",path="caddy",version="v1.4.4+dirty"} 1 for the static binary.

It's indeed better. It would be nice to get rid of the +dirty part but I don't understand why it is added.

For the Docker image, we still get go_build_info{checksum="",path="github.com/dunglas/frankenphp/caddy",version="(devel)"} 1.

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.

Prometheus metrics to get FrankenPHP and PHP version

3 participants