go.ligato.io/vpp-agent/v3@v3.5.0/plugins/telemetry/config.go (about)

     1  //  Copyright (c) 2018 Cisco and/or its affiliates.
     2  //
     3  //  Licensed under the Apache License, Version 2.0 (the "License");
     4  //  you may not use this file except in compliance with the License.
     5  //  You may obtain a copy of the License at:
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  //  Unless required by applicable law or agreed to in writing, software
    10  //  distributed under the License is distributed on an "AS IS" BASIS,
    11  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //  See the License for the specific language governing permissions and
    13  //  limitations under the License.
    14  
    15  package telemetry
    16  
    17  import "time"
    18  
    19  const (
    20  	// default period between updates
    21  	defaultUpdatePeriod = time.Second * 30
    22  	// minimum period between updates
    23  	minimumUpdatePeriod = time.Second * 1
    24  )
    25  
    26  // Config file representation for telemetry plugin
    27  type Config struct {
    28  	// Custom polling interval, default value is 30s
    29  	PollingInterval time.Duration `json:"polling-interval"`
    30  	// Allows to disable plugin
    31  	Disabled bool `json:"disabled"`
    32  	// Allows to export prometheus in telemetry plugin
    33  	PrometheusDisabled bool `json:"prometheus-disabled"`
    34  	// Skip collecting some of the metrics:
    35  	// 	runtime, memory, buffers, nodes, interfaces
    36  	Skipped []string `json:"skipped"`
    37  }
    38  
    39  func defaultConfig() *Config {
    40  	return &Config{
    41  		PollingInterval: defaultUpdatePeriod,
    42  	}
    43  }
    44  
    45  // loadConfig returns telemetry plugin file configuration if exists
    46  func (p *Plugin) loadConfig() (*Config, error) {
    47  	cfg := defaultConfig()
    48  
    49  	found, err := p.Cfg.LoadValue(cfg)
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  	if !found {
    54  		p.Log.Debug("Telemetry config not found")
    55  		return nil, nil
    56  	}
    57  
    58  	p.Log.Debugf("Telemetry config found: %+v", cfg)
    59  
    60  	return cfg, err
    61  }