Repository: prometheus/snmp_exporter
Pull request #921 (2023-07-18 20:41:55)

Remove confusing config versioning
Remove the confusing and premature optimization of versioning the config format. It is too easily confused with SNMP versions.


Patch:
diff --git a/config/config.go b/config/config.go
index 0c15c41..973ad7c 100644
--- a/config/config.go
+++ b/config/config.go
@@ -14,7 +14,6 @@
 package config
 
 import (
-	"errors"
 	"fmt"
 	"os"
 	"regexp"
@@ -34,9 +33,6 @@ func LoadFile(filename string) (*Config, error) {
 	if err != nil {
 		return nil, err
 	}
-	if cfg.Version != 2 {
-		return cfg, ErrUnsupportedVersion
-	}
 	return cfg, nil
 }
 
@@ -63,15 +59,12 @@ var (
 	DefaultRegexpExtract = RegexpExtract{
 		Value: "$1",
 	}
-
-	ErrUnsupportedVersion = errors.New("unsupported config version")
 )
 
 // Config for the snmp_exporter.
 type Config struct {
 	Auths   map[string]*Auth   `yaml:"auths,omitempty"`
 	Modules map[string]*Module `yaml:"modules,omitempty"`
-	Version int                `yaml:"version"`
 }
 
 type WalkParams struct {
diff --git a/generator/FORMAT.md b/generator/FORMAT.md
index 2793937..80f4db0 100644
--- a/generator/FORMAT.md
+++ b/generator/FORMAT.md
@@ -4,7 +4,6 @@ This is generated by the generator, so only those doing development should
 have to care about how this works.
 
 ```
-version: 2
 auths:
   public_v2:
     version: 2
diff --git a/generator/README.md b/generator/README.md
index ad2329c..edc5749 100644
--- a/generator/README.md
+++ b/generator/README.md
@@ -70,7 +70,6 @@ make docker-generate
 The simplest module is just a name and a set of OIDs to walk.
 
 ```yaml
-version: 2
 auths:
   auth_name:
     version: 2  # SNMP version to use. Defaults to 2.
diff --git a/generator/config.go b/generator/config.go
index 1576287..78a28c7 100644
--- a/generator/config.go
+++ b/generator/config.go
@@ -23,7 +23,6 @@ import (
 type Config struct {
 	Auths   map[string]*config.Auth  `yaml:"auths"`
 	Modules map[string]*ModuleConfig `yaml:"modules"`
-	Version int                      `yaml:"version"`
 }
 
 type MetricOverrides struct {
diff --git a/generator/generator.yml b/generator/generator.yml
index f182722..6c018ab 100644
--- a/generator/generator.yml
+++ b/generator/generator.yml
@@ -1,7 +1,4 @@
 ---
-# The generator config format version.
-version: 2
-
 auths:
   public_v1:
     version: 1
diff --git a/generator/main.go b/generator/main.go
index 28efbf6..168760b 100644
--- a/generator/main.go
+++ b/generator/main.go
@@ -45,12 +45,8 @@ func generateConfig(nodes *Node, nameToNode map[string]*Node, logger log.Logger)
 	if err != nil {
 		return fmt.Errorf("error parsing yml config: %s", err)
 	}
-	if cfg.Version != 2 {
-		return config.ErrUnsupportedVersion
-	}
 
 	outputConfig := config.Config{}
-	outputConfig.Version = cfg.Version
 	outputConfig.Auths = cfg.Auths
 	outputConfig.Modules = make(map[string]*config.Module, len(cfg.Modules))
 	for name, m := range cfg.Modules {
diff --git a/snmp.yml b/snmp.yml
index 254680c..a026322 100644
--- a/snmp.yml
+++ b/snmp.yml
@@ -49214,4 +49214,3 @@ modules:
       indexes:
       - labelname: fanNumber
         type: gauge
-version: 2


Test patch:
diff --git a/testdata/snmp-auth.yml b/testdata/snmp-auth.yml
index d0b504e..78257dc 100644
--- a/testdata/snmp-auth.yml
+++ b/testdata/snmp-auth.yml
@@ -7,4 +7,3 @@ auths:
     auth_protocol: SHA256
     priv_protocol: AES
     priv_password: mysecret
-version: 2
diff --git a/testdata/snmp-with-overrides.yml b/testdata/snmp-with-overrides.yml
index bf11fda..160ba6c 100644
--- a/testdata/snmp-with-overrides.yml
+++ b/testdata/snmp-with-overrides.yml
@@ -9,4 +9,3 @@ modules:
       regex_extracts:
         Temp:
         - regex:
-version: 2