github.com/Financial-Times/publish-availability-monitor@v1.12.0/config/config.go (about) 1 package config 2 3 import ( 4 "encoding/json" 5 "os" 6 "strings" 7 8 "github.com/Financial-Times/go-logger/v2" 9 ) 10 11 // AppConfig holds the application's configuration 12 type AppConfig struct { 13 Threshold int `json:"threshold"` //pub SLA in seconds, ex. 120 14 QueueConf QueueConfig `json:"queueConfig"` 15 MetricConf []MetricConfig `json:"metricConfig"` 16 SplunkConf SplunkConfig `json:"splunk-config"` 17 HealthConf HealthConfig `json:"healthConfig"` 18 ValidationEndpoints map[string]string `json:"validationEndpoints"` //contentType to validation endpoint mapping 19 Capabilities []Capability `json:"capabilities"` 20 GraphiteAddress string `json:"graphiteAddress"` 21 GraphiteUUID string `json:"graphiteUUID"` 22 Environment string `json:"environment"` 23 } 24 25 // QueueConfig is the configuration for kafka consumer queue 26 type QueueConfig struct { 27 ClusterARN string `json:"clusterARN"` 28 ConnectionString string `json:"connectionString"` 29 Topic string `json:"topic"` 30 ConsumerGroup string `json:"consumerGroup"` 31 LagTolerance int `json:"lagTolerance"` 32 } 33 34 // MetricConfig is the configuration of a PublishMetric 35 type MetricConfig struct { 36 Granularity int `json:"granularity"` //how we split up the threshold, ex. 120/12 37 Endpoint string `json:"endpoint"` 38 ContentTypes []string `json:"contentTypes"` //list of valid types for this metric 39 Alias string `json:"alias"` 40 Health string `json:"health,omitempty"` 41 APIKey string `json:"apiKey,omitempty"` 42 } 43 44 // SplunkConfig holds the SplunkFeeder-specific configuration 45 type SplunkConfig struct { 46 LogPrefix string `json:"logPrefix"` 47 } 48 49 // HealthConfig holds the application's healthchecks configuration 50 type HealthConfig struct { 51 FailureThreshold int `json:"failureThreshold"` 52 } 53 54 // Capability represents business capability configuration 55 type Capability struct { 56 Name string `json:"name"` 57 MetricAlias string `json:"metricAlias"` 58 TestIDs []string `json:"testIDs"` 59 } 60 61 // NewAppConfig opens the file at configFileName and unmarshals it into an AppConfig. 62 func NewAppConfig(configFileName string, log *logger.UPPLogger) (*AppConfig, error) { 63 file, err := os.ReadFile(configFileName) 64 if err != nil { 65 log.WithError(err).Errorf("Error reading configuration file [%v]", configFileName) 66 return nil, err 67 } 68 69 var conf AppConfig 70 err = json.Unmarshal(file, &conf) 71 if err != nil { 72 log.WithError(err).Errorf("Error unmarshalling configuration file [%v]", configFileName) 73 return nil, err 74 } 75 76 return &conf, nil 77 } 78 79 func (cfg *AppConfig) GetCapability(metricAlias string) *Capability { 80 for _, c := range cfg.Capabilities { 81 if c.MetricAlias == metricAlias { 82 return &c 83 } 84 } 85 86 return nil 87 } 88 89 func IsE2ETestTransactionID(tid string, e2eTestUUIDs []string) bool { 90 for _, testUUID := range e2eTestUUIDs { 91 if strings.Contains(tid, testUUID) { 92 return true 93 } 94 } 95 96 return false 97 }