mirror of https://github.com/k3s-io/k3s
Merge pull request #73686 from ShivangGoswami/master
Cleanup: Audit log and error capitalizationpull/564/head
commit
cdbc9d8567
|
@ -19,6 +19,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
goflag "flag"
|
goflag "flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -202,21 +203,21 @@ func getVersion(lastSeenBinaryVersion *string) error {
|
||||||
// Create the get request for the etcd version endpoint.
|
// Create the get request for the etcd version endpoint.
|
||||||
req, err := http.NewRequest("GET", etcdVersionScrapeURI, nil)
|
req, err := http.NewRequest("GET", etcdVersionScrapeURI, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create GET request for etcd version: %v", err)
|
return fmt.Errorf("failed to create GET request for etcd version: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the get request and receive a response.
|
// Send the get request and receive a response.
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to receive GET response for etcd version: %v", err)
|
return fmt.Errorf("failed to receive GET response for etcd version: %v", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
// Obtain EtcdVersion from the JSON response.
|
// Obtain EtcdVersion from the JSON response.
|
||||||
var version EtcdVersion
|
var version EtcdVersion
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&version); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(&version); err != nil {
|
||||||
return fmt.Errorf("Failed to decode etcd version JSON: %v", err)
|
return fmt.Errorf("failed to decode etcd version JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return without updating the version if it stayed the same since last time.
|
// Return without updating the version if it stayed the same since last time.
|
||||||
|
@ -228,7 +229,7 @@ func getVersion(lastSeenBinaryVersion *string) error {
|
||||||
if *lastSeenBinaryVersion != "" {
|
if *lastSeenBinaryVersion != "" {
|
||||||
deleted := etcdVersion.Delete(prometheus.Labels{"binary_version": *lastSeenBinaryVersion})
|
deleted := etcdVersion.Delete(prometheus.Labels{"binary_version": *lastSeenBinaryVersion})
|
||||||
if !deleted {
|
if !deleted {
|
||||||
return fmt.Errorf("Failed to delete previous version's metric")
|
return errors.New("failed to delete previous version's metric")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,14 +260,14 @@ func getVersionPeriodically(stopCh <-chan struct{}) {
|
||||||
func scrapeMetrics() (map[string]*dto.MetricFamily, error) {
|
func scrapeMetrics() (map[string]*dto.MetricFamily, error) {
|
||||||
req, err := http.NewRequest("GET", etcdMetricsScrapeURI, nil)
|
req, err := http.NewRequest("GET", etcdMetricsScrapeURI, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to create GET request for etcd metrics: %v", err)
|
return nil, fmt.Errorf("failed to create GET request for etcd metrics: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the get request and receive a response.
|
// Send the get request and receive a response.
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to receive GET response for etcd metrics: %v", err)
|
return nil, fmt.Errorf("failed to receive GET response for etcd metrics: %v", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue