mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-11 05:24:26 +00:00
refactor: ♻️ ach package accepts its configuration as a parameter rather than reading from global config
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in -25m44s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in -25m19s
Build , Vet Test, and Lint / Lint Code (push) Successful in -25m18s
Build , Vet Test, and Lint / Build (push) Successful in -25m30s
Tests / Unit Tests (push) Failing after -25m51s
Tests / Integration Tests (push) Failing after -25m53s
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in -25m44s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in -25m19s
Build , Vet Test, and Lint / Lint Code (push) Successful in -25m18s
Build , Vet Test, and Lint / Build (push) Successful in -25m30s
Tests / Unit Tests (push) Failing after -25m51s
Tests / Integration Tests (push) Failing after -25m53s
This commit is contained in:
64
pkg/metrics/example_test.go
Normal file
64
pkg/metrics/example_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package metrics_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/bitechdev/ResolveSpec/pkg/metrics"
|
||||
)
|
||||
|
||||
// ExampleNewPrometheusProvider_default demonstrates using default configuration
|
||||
func ExampleNewPrometheusProvider_default() {
|
||||
// Initialize with default configuration
|
||||
provider := metrics.NewPrometheusProvider(nil)
|
||||
metrics.SetProvider(provider)
|
||||
|
||||
fmt.Println("Provider initialized with defaults")
|
||||
// Output: Provider initialized with defaults
|
||||
}
|
||||
|
||||
// ExampleNewPrometheusProvider_custom demonstrates using custom configuration
|
||||
func ExampleNewPrometheusProvider_custom() {
|
||||
// Create custom configuration
|
||||
config := &metrics.Config{
|
||||
Enabled: true,
|
||||
Provider: "prometheus",
|
||||
Namespace: "myapp",
|
||||
HTTPRequestBuckets: []float64{0.01, 0.05, 0.1, 0.5, 1, 2, 5},
|
||||
DBQueryBuckets: []float64{0.001, 0.01, 0.05, 0.1, 0.5, 1},
|
||||
}
|
||||
|
||||
// Initialize with custom configuration
|
||||
provider := metrics.NewPrometheusProvider(config)
|
||||
metrics.SetProvider(provider)
|
||||
|
||||
fmt.Println("Provider initialized with custom config")
|
||||
// Output: Provider initialized with custom config
|
||||
}
|
||||
|
||||
// ExampleDefaultConfig demonstrates getting default configuration
|
||||
func ExampleDefaultConfig() {
|
||||
config := metrics.DefaultConfig()
|
||||
fmt.Printf("Default provider: %s\n", config.Provider)
|
||||
fmt.Printf("Default enabled: %v\n", config.Enabled)
|
||||
// Output:
|
||||
// Default provider: prometheus
|
||||
// Default enabled: true
|
||||
}
|
||||
|
||||
// ExampleConfig_ApplyDefaults demonstrates applying defaults to partial config
|
||||
func ExampleConfig_ApplyDefaults() {
|
||||
// Create partial configuration
|
||||
config := &metrics.Config{
|
||||
Namespace: "myapp",
|
||||
// Other fields will be filled with defaults
|
||||
}
|
||||
|
||||
// Apply defaults
|
||||
config.ApplyDefaults()
|
||||
|
||||
fmt.Printf("Provider: %s\n", config.Provider)
|
||||
fmt.Printf("Namespace: %s\n", config.Namespace)
|
||||
// Output:
|
||||
// Provider: prometheus
|
||||
// Namespace: myapp
|
||||
}
|
||||
Reference in New Issue
Block a user