Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ settings.yaml

# Build
/.build/
/dist/
18 changes: 13 additions & 5 deletions cmd/data-aggregation-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/rs/zerolog/log"

"github.com/criteo/data-aggregation-api/internal/api/router"
"github.com/criteo/data-aggregation-api/internal/app"
"github.com/criteo/data-aggregation-api/internal/config"
"github.com/criteo/data-aggregation-api/internal/convertor/device"
"github.com/criteo/data-aggregation-api/internal/job"
Expand All @@ -32,9 +33,10 @@ func configureLogging(logLevel string, pretty bool) error {
}

var (
version = ""
buildTime = "unknown"
buildUser = "unknown"
version = ""
date = "unknown"
commit = "unknown"
builtBy = "unknown"
)

func run() error {
Expand All @@ -49,8 +51,9 @@ func run() error {
}

log.Info().Str("version", version).Send()
log.Info().Str("build-time", buildTime).Send()
log.Info().Str("build-user", buildUser).Send()
log.Info().Str("commit", commit).Send()
log.Info().Str("build-time", date).Send()
log.Info().Str("build-user", builtBy).Send()

deviceRepo := device.NewSafeRepository()
reports := report.NewRepository()
Expand All @@ -66,6 +69,11 @@ func run() error {
}

func main() {
app.Info.Version = version
app.Info.BuildTime = date
app.Info.BuildUser = builtBy
app.Info.Commit = commit

if err := run(); err != nil {
log.Fatal().Err(err).Send()
}
Expand Down
6 changes: 6 additions & 0 deletions internal/api/router/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/rs/zerolog/log"

"github.com/criteo/data-aggregation-api/internal/app"
"github.com/criteo/data-aggregation-api/internal/convertor/device"
"github.com/julienschmidt/httprouter"
)
Expand All @@ -21,6 +22,11 @@ func healthCheck(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
fmt.Fprintf(w, `{"status": "ok"}`)
}

func getVersion(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
w.Header().Set(contentType, applicationJSON)
fmt.Fprintf(w, `{"version": "%s", "build_time": "%s", "build_user": "%s"}`, app.Info.Version, app.Info.BuildTime, app.Info.BuildUser)
}

func prometheusMetrics(h http.Handler) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
h.ServeHTTP(w, r)
Expand Down
1 change: 1 addition & 0 deletions internal/api/router/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (m *Manager) ListenAndServe(ctx context.Context, address string, port int)
router := httprouter.New()

router.GET("/metrics", prometheusMetrics(promhttp.Handler()))
router.GET("/api/version", getVersion)
router.GET("/api/health", healthCheck)
router.GET("/v1/devices/:hostname/afk_enabled", withAuth.Wrap(m.getAFKEnabled))
router.GET("/v1/devices/:hostname/openconfig", withAuth.Wrap(m.getDeviceOpenConfig))
Expand Down
10 changes: 10 additions & 0 deletions internal/app/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package app

type info struct {
Version string
BuildTime string
BuildUser string
Commit string
}

var Info = info{}
12 changes: 12 additions & 0 deletions internal/metrics/registry.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package metrics

import (
"github.com/criteo/data-aggregation-api/internal/app"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

type Registry struct {
AppInfo *prometheus.GaugeVec
BuiltDevicesNumber *prometheus.GaugeVec
lastBuildStatus *prometheus.GaugeVec
buildTotal *prometheus.CounterVec
}

func NewRegistry() Registry {
appInfo := promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "data_aggregation_api_info",
Help: "Version of the application",
},
[]string{"version", "commit", "build_time", "built_by"},
)
appInfo.WithLabelValues(app.Info.Version, app.Info.Commit, app.Info.BuildTime, app.Info.BuildUser).Set(1)

return Registry{
AppInfo: appInfo,
BuiltDevicesNumber: promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "built_devices_number",
Expand Down