Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 AT&T Intellectual Property. |
| 3 | * Copyright (c) 2018-2019 Nokia. |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | package main |
| 19 | |
| 20 | import ( |
| 21 | "gopkg.in/yaml.v2" |
| 22 | "time" |
| 23 | "io" |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame^] | 24 | "os" |
| 25 | "strconv" |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | func basicVespaConf() VESAgentConfiguration { |
| 29 | var vespaconf = VESAgentConfiguration { |
| 30 | DataDir: "/tmp/data", |
| 31 | Debug: false, |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 32 | Event: EventConfiguration { |
| 33 | VNFName: "vespa-demo", // XXX |
| 34 | ReportingEntityID: "1af5bfa9-40b4-4522-b045-40e54f0310f", // XXX |
| 35 | MaxSize: 2000000, |
| 36 | NfNamingCode: "hsxp", |
| 37 | NfcNamingCodes: [] NfcNamingCode { |
| 38 | NfcNamingCode { |
| 39 | Type: "oam", |
| 40 | Vnfcs: [] string {"lr-ope-0","lr-ope-1","lr-ope-2"}, |
| 41 | }, |
| 42 | NfcNamingCode { |
| 43 | Type: "etl", |
| 44 | Vnfcs: [] string {"lr-pro-0","lr-pro-1"}, |
| 45 | }, |
| 46 | }, |
| 47 | RetryInterval: time.Second * 5, |
| 48 | MaxMissed: 2, |
| 49 | }, |
| 50 | Measurement: MeasurementConfiguration { |
| 51 | DomainAbbreviation: "Mvfs", |
| 52 | MaxBufferingDuration: time.Hour, |
| 53 | Prometheus: PrometheusConfig { |
| 54 | Timeout: time.Second * 30, |
| 55 | KeepAlive: time.Second * 30, |
| 56 | Rules: MetricRules { |
| 57 | DefaultValues: &MetricRule { |
| 58 | VMIDLabel: "'{{.labels.instance}}'", |
| 59 | }, |
| 60 | }, |
| 61 | }, |
| 62 | }, |
| 63 | } |
| 64 | return vespaconf |
| 65 | } |
| 66 | |
| 67 | func getRules(vespaconf *VESAgentConfiguration) { |
| 68 | // XXX |
| 69 | makeRule := func(expr string, obj_name string, obj_instance string) MetricRule { |
| 70 | return MetricRule { |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame^] | 71 | Target: "AdditionalObjects", |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 72 | Expr: expr, |
| 73 | ObjectInstance: obj_instance, |
| 74 | ObjectName: obj_name, |
| 75 | ObjectKeys: [] Label { |
| 76 | Label { |
| 77 | Name: "ricComponentName", |
| 78 | Expr: "'{{.labels.app_kubernetes_io_instance}}'", |
| 79 | }, |
| 80 | }, |
| 81 | } |
| 82 | } |
| 83 | // Hard coded for now |
| 84 | vespaconf.Measurement.Prometheus.Rules.Metrics = []MetricRule { |
| 85 | makeRule("ricxapp_RMR_Received", "ricxappRMRreceivedCounter", "ricxappRMRReceived"), |
| 86 | makeRule("ricxapp_RMR_ReceiveError", "ricxappRMRReceiveErrorCounter", "ricxappRMRReceiveError"), |
| 87 | makeRule("ricxapp_RMR_Transmitted", "ricxappRMRTransmittedCounter", "ricxappRMRTransmitted"), |
| 88 | makeRule("ricxapp_RMR_TransmitError", "ricxappRMRTransmitErrorCounter", "ricxappRMRTransmitError"), |
| 89 | makeRule("ricxapp_SDL_Stored", "ricxappSDLStoredCounter", "ricxappSDLStored"), |
| 90 | makeRule("ricxapp_SDL_StoreError", "ricxappSDLStoreErrorCounter", "ricxappSDLStoreError"), |
| 91 | } |
| 92 | |
| 93 | } |
| 94 | |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame^] | 95 | func getCollectorConfiguration(vespaconf *VESAgentConfiguration) { |
| 96 | vespaconf.PrimaryCollector.User = os.Getenv("VESMGR_PRICOLLECTOR_USER") |
| 97 | vespaconf.PrimaryCollector.Password = os.Getenv("VESMGR_PRICOLLECTOR_PASSWORD") |
| 98 | vespaconf.PrimaryCollector.PassPhrase = os.Getenv("VESMGR_PRICOLLECTOR_PASSPHRASE") |
| 99 | vespaconf.PrimaryCollector.FQDN = os.Getenv("VESMGR_PRICOLLECTOR_ADDR") |
| 100 | vespaconf.PrimaryCollector.ServerRoot = os.Getenv("VESMGR_PRICOLLECTOR_SERVERROOT") |
| 101 | vespaconf.PrimaryCollector.Topic = os.Getenv("VESMGR_PRICOLLECTOR_TOPIC") |
| 102 | port_str := os.Getenv("VESMGR_PRICOLLECTOR_PORT") |
| 103 | if port_str == "" { |
| 104 | vespaconf.PrimaryCollector.Port = 8443 |
| 105 | } else { |
| 106 | port, _ := strconv.Atoi(port_str) |
| 107 | vespaconf.PrimaryCollector.Port = port |
| 108 | } |
| 109 | secure_str := os.Getenv("VESMGR_PRICOLLECTOR_SECURE") |
| 110 | if secure_str == "true" { |
| 111 | vespaconf.PrimaryCollector.Secure = true |
| 112 | } else { |
| 113 | vespaconf.PrimaryCollector.Secure = false |
| 114 | } |
| 115 | } |
| 116 | |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 117 | func createVespaConfig(writer io.Writer) { |
| 118 | vespaconf := basicVespaConf() |
| 119 | getRules(&vespaconf) |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame^] | 120 | getCollectorConfiguration(&vespaconf) |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 121 | err := yaml.NewEncoder(writer).Encode(vespaconf) |
| 122 | if err != nil { |
| 123 | logger.Error("Cannot write vespa conf file: %s", err.Error()) |
| 124 | return |
| 125 | } |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame^] | 126 | } |