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

Draft: Configurable app name for tracing, defaults to gorse. #846

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ type OnlineConfig struct {
}

type TracingConfig struct {
AppName string `mapstructure:"app_name"`
EnableTracing bool `mapstructure:"enable_tracing"`
Exporter string `mapstructure:"exporter" validate:"oneof=jaeger zipkin otlp otlphttp"`
CollectorEndpoint string `mapstructure:"collector_endpoint"`
Expand Down Expand Up @@ -246,6 +247,7 @@ func GetDefaultConfig() *Config {
},
},
Tracing: TracingConfig{
AppName: "gorse",
Exporter: "jaeger",
Sampler: "always",
},
Expand All @@ -259,6 +261,10 @@ func (config *Config) Now() *time.Time {
return lo.ToPtr(time.Now().Add(config.Server.ClockError))
}

func (config TracingConfig) GetAppName() string {
return config.AppName
}

func (config *Config) UserNeighborDigest() string {
var builder strings.Builder
builder.WriteString(fmt.Sprintf("%v-%v", config.Recommend.UserNeighbors.NeighborType, config.Recommend.UserNeighbors.EnableIndex))
Expand Down Expand Up @@ -450,7 +456,7 @@ func (config *TracingConfig) NewTracerProvider() (trace.TracerProvider, error) {
tracesdk.WithBatcher(exporter),
tracesdk.WithResource(resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("gorse"),
semconv.ServiceNameKey.String(config.AppName),
)),
), nil
}
Expand Down Expand Up @@ -524,6 +530,7 @@ func setDefault() {
viper.SetDefault("recommend.online.fallback_recommend", defaultConfig.Recommend.Online.FallbackRecommend)
viper.SetDefault("recommend.online.num_feedback_fallback_item_based", defaultConfig.Recommend.Online.NumFeedbackFallbackItemBased)
// [tracing]
viper.SetDefault("tracing.app_name", defaultConfig.Tracing.AppName)
viper.SetDefault("tracing.exporter", defaultConfig.Tracing.Exporter)
viper.SetDefault("tracing.sampler", defaultConfig.Tracing.Sampler)
// [experimental]
Expand Down
3 changes: 3 additions & 0 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ num_feedback_fallback_item_based = 10

[tracing]

# App name
app_name = "gorse"

# Enable tracing for REST APIs. The default value is false.
enable_tracing = false

Expand Down
77 changes: 39 additions & 38 deletions master/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/samber/lo"
"github.com/zhenghaoz/gorse/config"
"github.com/zhenghaoz/gorse/storage/cache"
)

Expand All @@ -32,194 +33,194 @@

var (
LoadDatasetStepSecondsVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),

Check failure on line 36 in master/metrics.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to config.TracingConfig.GetAppName
Subsystem: "master",
Name: "load_dataset_step_seconds",
}, []string{LabelStep})
LoadDatasetTotalSeconds = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),

Check failure on line 41 in master/metrics.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to config.TracingConfig.GetAppName
Subsystem: "master",
Name: "load_dataset_total_seconds",
})
FindUserNeighborsSecondsVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),

Check failure on line 46 in master/metrics.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to config.TracingConfig.GetAppName
Subsystem: "master",
Name: "find_user_neighbors_seconds",
}, []string{LabelStep})
FindUserNeighborsTotalSeconds = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "find_user_neighbors_total_seconds",
})
FindItemNeighborsSecondsVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "find_item_neighbors_seconds",
}, []string{"step"})
FindItemNeighborsTotalSeconds = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "find_item_neighbors_total_seconds",
})
UpdateUserNeighborsTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "update_user_neighbors_total",
})
UpdateItemNeighborsTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "update_item_neighbors_total",
})
CacheScannedTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "cache_scanned_total",
})
CacheReclaimedTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "cache_reclaimed_total",
})
CacheScannedSeconds = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "cache_scanned_seconds",
})

CollaborativeFilteringFitSeconds = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "collaborative_filtering_fit_seconds",
})
CollaborativeFilteringSearchSeconds = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "collaborative_filtering_search_seconds",
})
CollaborativeFilteringNDCG10 = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "collaborative_filtering_ndcg_10",
})
CollaborativeFilteringPrecision10 = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "collaborative_filtering_precision_10",
})
CollaborativeFilteringRecall10 = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "collaborative_filtering_recall_10",
})
CollaborativeFilteringSearchPrecision10 = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "collaborative_filtering_search_precision_10",
})
RankingFitSeconds = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "ranking_fit_seconds",
})
RankingSearchSeconds = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "ranking_search_seconds",
})
RankingPrecision = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "ranking_model_precision",
})
RankingRecall = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "ranking_model_recall",
})
RankingAUC = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "ranking_model_auc",
})
RankingSearchPrecision = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "ranking_search_precision",
})
UserNeighborIndexRecall = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "user_neighbor_index_recall",
})
ItemNeighborIndexRecall = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "item_neighbor_index_recall",
})

UsersTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "users_total",
})
ActiveUsersTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "active_users_total",
})
InactiveUsersTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "inactive_users_total",
})
ItemsTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "items_total",
})
ActiveItemsTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "active_items_total",
})
InactiveItemsTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "inactive_items_total",
})
UserLabelsTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "user_labels_total",
})
ItemLabelsTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "item_labels_total",
})
FeedbacksTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "feedbacks_total",
})
ImplicitFeedbacksTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "implicit_feedbacks_total",
})
PositiveFeedbacksTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "positive_feedbacks_total",
})
NegativeFeedbackTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "negative_feedbacks_total",
})
MemoryInUseBytesVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),
Subsystem: "master",
Name: "memory_inuse_bytes",
}, []string{LabelData})
Expand Down
3 changes: 2 additions & 1 deletion server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/zhenghaoz/gorse/config"
)

var (
RestAPIRequestSecondsVec = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),

Check failure on line 25 in server/metrics.go

View workflow job for this annotation

GitHub Actions / unit tests

not enough arguments in call to config.TracingConfig.GetAppName
Subsystem: "server",
Name: "rest_api_request_seconds",
}, []string{"api"})
Expand Down
2 changes: 1 addition & 1 deletion server/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (s *RestServer) CreateWebService() {
Filter(s.LogFilter).
Filter(s.AuthFilter).
Filter(s.MetricsFilter).
Filter(otelrestful.OTelFilter("gorse"))
Filter(otelrestful.OTelFilter(s.Config.Tracing.AppName))

/* Health check */
ws.Route(ws.GET("/health/live").To(s.checkLive).
Expand Down
11 changes: 6 additions & 5 deletions worker/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/zhenghaoz/gorse/config"
)

const (
Expand All @@ -26,27 +27,27 @@

var (
UpdateUserRecommendTotal = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),

Check failure on line 30 in worker/metrics.go

View workflow job for this annotation

GitHub Actions / unit tests

not enough arguments in call to config.TracingConfig.GetAppName
Subsystem: "worker",
Name: "update_user_recommend_total",
})
OfflineRecommendStepSecondsVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),

Check failure on line 35 in worker/metrics.go

View workflow job for this annotation

GitHub Actions / unit tests

not enough arguments in call to config.TracingConfig.GetAppName
Subsystem: "worker",
Name: "offline_recommend_step_seconds",
}, []string{LabelStep})
OfflineRecommendTotalSeconds = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),

Check failure on line 40 in worker/metrics.go

View workflow job for this annotation

GitHub Actions / unit tests

not enough arguments in call to config.TracingConfig.GetAppName
Subsystem: "worker",
Name: "offline_recommend_total_seconds",
})
CollaborativeFilteringIndexRecall = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),

Check failure on line 45 in worker/metrics.go

View workflow job for this annotation

GitHub Actions / unit tests

not enough arguments in call to config.TracingConfig.GetAppName
Subsystem: "worker",
Name: "collaborative_filtering_index_recall",
})
MemoryInuseBytesVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "gorse",
Namespace: config.TracingConfig.GetAppName(),

Check failure on line 50 in worker/metrics.go

View workflow job for this annotation

GitHub Actions / unit tests

not enough arguments in call to config.TracingConfig.GetAppName
Subsystem: "worker",
Name: "memory_inuse_bytes",
}, []string{LabelData})
Expand Down
Loading