You've already forked nginx_exporter
mirror of
https://github.com/nginxinc/nginx-prometheus-exporter.git
synced 2025-08-08 05:02:04 +03:00
Fix error wrapping
This commit is contained in:
@@ -45,7 +45,7 @@ func NewNginxClient(httpClient *http.Client, apiEndpoint string) (*NginxClient,
|
|||||||
func (client *NginxClient) GetStubStats() (*StubStats, error) {
|
func (client *NginxClient) GetStubStats() (*StubStats, error) {
|
||||||
resp, err := client.httpClient.Get(client.apiEndpoint)
|
resp, err := client.httpClient.Get(client.apiEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get %v: %v", client.apiEndpoint, err)
|
return nil, fmt.Errorf("failed to get %v: %w", client.apiEndpoint, err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
@@ -55,13 +55,13 @@ func (client *NginxClient) GetStubStats() (*StubStats, error) {
|
|||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read the response body: %v", err)
|
return nil, fmt.Errorf("failed to read the response body: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var stats StubStats
|
var stats StubStats
|
||||||
err = parseStubStats(body, &stats)
|
err = parseStubStats(body, &stats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse response body %q: %v", string(body), err)
|
return nil, fmt.Errorf("failed to parse response body %q: %w", string(body), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &stats, nil
|
return &stats, nil
|
||||||
@@ -82,7 +82,7 @@ func parseStubStats(data []byte, stats *StubStats) error {
|
|||||||
|
|
||||||
actCons, err := strconv.ParseInt(activeConsParts[2], 10, 64)
|
actCons, err := strconv.ParseInt(activeConsParts[2], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid input for active connections %q: %v", activeConsParts[2], err)
|
return fmt.Errorf("invalid input for active connections %q: %w", activeConsParts[2], err)
|
||||||
}
|
}
|
||||||
stats.Connections.Active = actCons
|
stats.Connections.Active = actCons
|
||||||
|
|
||||||
@@ -93,19 +93,19 @@ func parseStubStats(data []byte, stats *StubStats) error {
|
|||||||
|
|
||||||
acceptedCons, err := strconv.ParseInt(miscParts[0], 10, 64)
|
acceptedCons, err := strconv.ParseInt(miscParts[0], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid input for accepted connections %q: %v", miscParts[0], err)
|
return fmt.Errorf("invalid input for accepted connections %q: %w", miscParts[0], err)
|
||||||
}
|
}
|
||||||
stats.Connections.Accepted = acceptedCons
|
stats.Connections.Accepted = acceptedCons
|
||||||
|
|
||||||
handledCons, err := strconv.ParseInt(miscParts[1], 10, 64)
|
handledCons, err := strconv.ParseInt(miscParts[1], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid input for handled connections %q: %v", miscParts[1], err)
|
return fmt.Errorf("invalid input for handled connections %q: %w", miscParts[1], err)
|
||||||
}
|
}
|
||||||
stats.Connections.Handled = handledCons
|
stats.Connections.Handled = handledCons
|
||||||
|
|
||||||
requests, err := strconv.ParseInt(miscParts[2], 10, 64)
|
requests, err := strconv.ParseInt(miscParts[2], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid input for requests %q: %v", miscParts[2], err)
|
return fmt.Errorf("invalid input for requests %q: %w", miscParts[2], err)
|
||||||
}
|
}
|
||||||
stats.Requests = requests
|
stats.Requests = requests
|
||||||
|
|
||||||
@@ -116,19 +116,19 @@ func parseStubStats(data []byte, stats *StubStats) error {
|
|||||||
|
|
||||||
readingCons, err := strconv.ParseInt(consParts[1], 10, 64)
|
readingCons, err := strconv.ParseInt(consParts[1], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid input for reading connections %q: %v", consParts[1], err)
|
return fmt.Errorf("invalid input for reading connections %q: %w", consParts[1], err)
|
||||||
}
|
}
|
||||||
stats.Connections.Reading = readingCons
|
stats.Connections.Reading = readingCons
|
||||||
|
|
||||||
writingCons, err := strconv.ParseInt(consParts[3], 10, 64)
|
writingCons, err := strconv.ParseInt(consParts[3], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid input for writing connections %q: %v", consParts[3], err)
|
return fmt.Errorf("invalid input for writing connections %q: %w", consParts[3], err)
|
||||||
}
|
}
|
||||||
stats.Connections.Writing = writingCons
|
stats.Connections.Writing = writingCons
|
||||||
|
|
||||||
waitingCons, err := strconv.ParseInt(consParts[5], 10, 64)
|
waitingCons, err := strconv.ParseInt(consParts[5], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid input for waiting connections %q: %v", consParts[5], err)
|
return fmt.Errorf("invalid input for waiting connections %q: %w", consParts[5], err)
|
||||||
}
|
}
|
||||||
stats.Connections.Waiting = waitingCons
|
stats.Connections.Waiting = waitingCons
|
||||||
|
|
||||||
|
@@ -201,7 +201,7 @@ func getListener(listenAddress string) (net.Listener, error) {
|
|||||||
if strings.HasPrefix(listenAddress, "unix:") {
|
if strings.HasPrefix(listenAddress, "unix:") {
|
||||||
path, _, pathError := parseUnixSocketAddress(listenAddress)
|
path, _, pathError := parseUnixSocketAddress(listenAddress)
|
||||||
if pathError != nil {
|
if pathError != nil {
|
||||||
return listener, fmt.Errorf("parsing unix domain socket listen address %s failed: %v", listenAddress, pathError)
|
return listener, fmt.Errorf("parsing unix domain socket listen address %s failed: %w", listenAddress, pathError)
|
||||||
}
|
}
|
||||||
listener, err = net.ListenUnix("unix", &net.UnixAddr{Name: path, Net: "unix"})
|
listener, err = net.ListenUnix("unix", &net.UnixAddr{Name: path, Net: "unix"})
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user