c364196fae9bc497fbe6782adfab35f6b6a20d67
[ric-plt/vespamgr.git] / cmd / vespamgr / types.go
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  *  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18  *  platform project (RICP).
19  *
20  */
21
22 package main
23
24 import (
25         "time"
26 )
27
28 type VespaMgr struct {
29         rmrReady             bool
30         vesAgent             *CommandRunner
31         chVesagent           chan error
32         appmgrHost           string
33         appmgrUrl            string
34         appmgrNotifUrl       string
35         appmgrSubsUrl        string
36         appmgrRetry          int
37         hbInterval           string
38         measInterval         string
39         prometheusAddr       string
40         alertManagerBindAddr string
41         subscriptionId       string
42 }
43
44 // Structs are copied from https://github.com/nokia/ONAP-VESPA/tree/master/ves-agent/config
45 // and from https://github.com/nokia/ONAP-VESPA/blob/master/govel/config.go
46 // Using tag v0.3.0
47
48 // HeartbeatConfiguration parameters
49 type HeartbeatConfiguration struct {
50         DefaultInterval time.Duration `yaml:"defaultInterval"`
51 }
52
53 // Label represents a VES field by it's name, with an expression
54 // for getting its value
55 type Label struct {
56         Name string `yaml:"name"`
57         Expr string `yaml:"expr"`
58 }
59
60 // MetricRule defines how to retrieve metrics and map them
61 // into a list of evel.EventMeasurement struct
62 type MetricRule struct {
63         Target         string  `yaml:"target"`          // Target VES event field
64         Expr           string  `yaml:"expr"`            // Prometheus query expression
65         VMIDLabel      string  `yaml:"vmId"`            // Metric label holding the VNF ID
66         Labels         []Label `yaml:"labels"`          // Set of VES fields to map to values of given label
67         ObjectName     string  `yaml:"object_name"`     // JSON Object Name
68         ObjectInstance string  `yaml:"object_instance"` // JSON Object instance
69         ObjectKeys     []Label `yaml:"object_keys"`     // JSON Object keys
70 }
71
72 // MetricRules defines a list of rules, and defaults values for them
73 type MetricRules struct {
74         DefaultValues *MetricRule  `yaml:"defaults"` // Default rules to apply (except for expr), labels are merged
75         Metrics       []MetricRule `yaml:"metrics"`  // List of query and mapping of rules
76 }
77
78 // PrometheusConfig parameters
79 type PrometheusConfig struct {
80         Address   string        `yaml:"address"`   // Base URL to prometheus API
81         Timeout   time.Duration `yaml:"timeout"`   // API request timeout
82         KeepAlive time.Duration `yaml:"keepalive"` // HTTP Keep-Alive
83         Rules     MetricRules   `yaml:"rules"`     // Querying rules
84 }
85
86 // MeasurementConfiguration parameters
87 type MeasurementConfiguration struct {
88         DomainAbbreviation   string           `yaml:"domainAbbreviation"`   // "Measurement" or "Mfvs"
89         DefaultInterval      time.Duration    `yaml:"defaultInterval"`      // Default measurement interval
90         MaxBufferingDuration time.Duration    `yaml:"maxBufferingDuration"` // Maximum timeframe size of buffering
91         Prometheus           PrometheusConfig `yaml:"prometheus"`           // Prometheus configuration
92 }
93
94 // CollectorConfiguration parameters
95 type CollectorConfiguration struct {
96         ServerRoot string `yaml:"serverRoot"`
97         FQDN       string `yaml:"fqdn"`
98         Port       int    `yaml:"port"`
99         Secure     bool   `yaml:"secure"`
100         Topic      string `yaml:"topic"`
101         User       string `yaml:"user"`
102         Password   string `yaml:"password"`
103         PassPhrase string `yaml:"passphrase,omitempty"` // passPhrase used to encrypt collector password in file
104 }
105
106 //NfcNamingCode mapping bettween NfcNamingCode (oam or etl) and Vnfcs
107 type NfcNamingCode struct {
108         Type  string   `yaml:"type"`
109         Vnfcs []string `yaml:"vnfcs"`
110 }
111
112 // EventConfiguration parameters
113 type EventConfiguration struct {
114         VNFName             string          `yaml:"vnfName"`             // Name of this VNF, eg: dpa2bhsxp5001v
115         ReportingEntityName string          `yaml:"reportingEntityName"` // Value of reporting entity field. Usually local VM (VNFC) name
116         ReportingEntityID   string          `yaml:"reportingEntityID"`   // Value of reporting entity UUID. Usually local VM (VNFC) UUID
117         MaxSize             int             `yaml:"maxSize"`
118         NfNamingCode        string          `yaml:"nfNamingCode,omitempty"` // "hspx"
119         NfcNamingCodes      []NfcNamingCode `yaml:"nfcNamingCodes,omitempty"`
120         RetryInterval       time.Duration   `yaml:"retryInterval,omitempty"`
121         MaxMissed           int             `yaml:"maxMissed,omitempty"`
122 }
123
124 // VESAgentConfiguration parameters
125 type VESAgentConfiguration struct {
126         PrimaryCollector CollectorConfiguration   `yaml:"primaryCollector"`
127         Heartbeat        HeartbeatConfiguration   `yaml:"heartbeat,omitempty"`
128         Measurement      MeasurementConfiguration `yaml:"measurement,omitempty"`
129         Event            EventConfiguration       `yaml:"event,omitempty"`
130         Debug            bool                     `yaml:"debug,omitempty"`
131         CaCert           string                   `yaml:"caCert,omitempty"` // Root certificate content
132         DataDir          string                   `yaml:"datadir"`          // Path to directory containing data
133 }
134
135 // AppMetricsStruct contains xapplication metrics definition
136 type AppMetricsStruct struct {
137         MoId           string
138         MeasType       string
139         MeasId         string
140         MeasInterval   string
141         ObjectName     string
142         ObjectInstance string
143         CounterId      string
144 }
145
146 // AppMetrics contains metrics definitions for all Xapps
147 type AppMetrics map[string]AppMetricsStruct
148
149 var Version string
150 var Hash string