Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we replace github.com/prometheus/common/log with log/slog? #121

Merged
merged 8 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: wangyoucao577/go-release-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goversion: 1.18
goversion: 1.21
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
release_tag: ${{ github.event.release.tag_name || github.event.inputs.tag }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18 as build
FROM golang:1.21 as build

WORKDIR /go/artifactory_exporter
ADD . /go/artifactory_exporter
Expand Down
5 changes: 2 additions & 3 deletions artifactory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package artifactory

import (
"crypto/tls"
"log/slog"
"net/http"

"github.com/go-kit/log"

"github.com/peimanja/artifactory_exporter/config"
)

Expand All @@ -16,7 +15,7 @@ type Client struct {
cred config.Credentials
optionalMetrics config.OptionalMetrics
client *http.Client
logger log.Logger
logger *slog.Logger
}

// NewClient returns an initialized Artifactory HTTP Client.
Expand Down
10 changes: 4 additions & 6 deletions artifactory/federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package artifactory

import (
"encoding/json"

"github.com/go-kit/log/level"
)

const federationMirrorsLagEndpoint = "federation/status/mirrorsLag"
Expand Down Expand Up @@ -34,7 +32,7 @@ type MirrorLags struct {
// FetchMirrorLags makes the API call to federation/status/mirrorsLag endpoint and returns []MirrorLag
func (c *Client) FetchMirrorLags() (MirrorLags, error) {
var mirrorLags MirrorLags
level.Debug(c.logger).Log("msg", "Fetching mirror lags")
c.logger.Debug("Fetching mirror lags")
resp, err := c.FetchHTTP(federationMirrorsLagEndpoint)
if err != nil {
if err.(*APIError).status == 404 {
Expand All @@ -45,7 +43,7 @@ func (c *Client) FetchMirrorLags() (MirrorLags, error) {
mirrorLags.NodeId = resp.NodeId

if err := json.Unmarshal(resp.Body, &mirrorLags.MirrorLags); err != nil {
level.Error(c.logger).Log("msg", "There was an issue when try to unmarshal mirror lags respond")
c.logger.Error("There was an issue when try to unmarshal mirror lags respond")
return mirrorLags, &UnmarshalError{
message: err.Error(),
endpoint: federationMirrorsLagEndpoint,
Expand All @@ -71,7 +69,7 @@ type UnavailableMirrors struct {
// FetchUnavailableMirrors makes the API call to federation/status/unavailableMirrors endpoint and returns []UnavailableMirror
func (c *Client) FetchUnavailableMirrors() (UnavailableMirrors, error) {
var unavailableMirrors UnavailableMirrors
level.Debug(c.logger).Log("msg", "Fetching unavailable mirrors")
c.logger.Debug("Fetching unavailable mirrors")
resp, err := c.FetchHTTP(federationUnavailableMirrorsEndpoint)
if err != nil {
if err.(*APIError).status == 404 {
Expand All @@ -82,7 +80,7 @@ func (c *Client) FetchUnavailableMirrors() (UnavailableMirrors, error) {
unavailableMirrors.NodeId = resp.NodeId

if err := json.Unmarshal(resp.Body, &unavailableMirrors.UnavailableMirrors); err != nil {
level.Error(c.logger).Log("msg", "There was an issue when try to unmarshal unavailable mirrors respond")
c.logger.Error("There was an issue when try to unmarshal unavailable mirrors respond")
return unavailableMirrors, &UnmarshalError{
message: err.Error(),
endpoint: federationUnavailableMirrorsEndpoint,
Expand Down
11 changes: 5 additions & 6 deletions artifactory/openmetrics.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package artifactory

import (
"github.com/go-kit/log/level"
)

const openMetricsEndpoint = "v1/metrics"

type OpenMetrics struct {
Expand All @@ -14,7 +10,7 @@ type OpenMetrics struct {
// FetchOpenMetrics makes the API call to open metrics endpoint and returns all the open metrics
func (c *Client) FetchOpenMetrics() (OpenMetrics, error) {
var openMetrics OpenMetrics
level.Debug(c.logger).Log("msg", "Fetching openMetrics")
c.logger.Debug("Fetching openMetrics")
resp, err := c.FetchHTTP(openMetricsEndpoint)
if err != nil {
if err.(*APIError).status == 404 {
Expand All @@ -23,7 +19,10 @@ func (c *Client) FetchOpenMetrics() (OpenMetrics, error) {
return openMetrics, err
}

level.Debug(c.logger).Log("msg", "OpenMetrics from Artifactory", "body", string(resp.Body))
c.logger.Debug(
"OpenMetrics from Artifactory",
"body", string(resp.Body),
)

openMetrics.NodeId = resp.NodeId
openMetrics.PromMetrics = string(resp.Body)
Expand Down
10 changes: 4 additions & 6 deletions artifactory/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package artifactory
import (
"encoding/json"
"fmt"

"github.com/go-kit/log/level"
)

const replicationEndpoint = "replications"
Expand Down Expand Up @@ -38,7 +36,7 @@ type ReplicationStatus struct {
// FetchReplications makes the API call to replication endpoint and returns []Replication
func (c *Client) FetchReplications() (Replications, error) {
var replications Replications
level.Debug(c.logger).Log("msg", "Fetching replications stats")
c.logger.Debug("Fetching replications stats")
resp, err := c.FetchHTTP(replicationEndpoint)
if err != nil {
if err.(*APIError).status == 404 {
Expand All @@ -49,15 +47,15 @@ func (c *Client) FetchReplications() (Replications, error) {
replications.NodeId = resp.NodeId

if err := json.Unmarshal(resp.Body, &replications.Replications); err != nil {
level.Error(c.logger).Log("msg", "There was an issue when try to unmarshal replication respond")
c.logger.Error("There was an issue when try to unmarshal replication respond")
return replications, &UnmarshalError{
message: err.Error(),
endpoint: replicationEndpoint,
}
}

if c.optionalMetrics.ReplicationStatus {
level.Debug(c.logger).Log("msg", "Fetching replications status")
c.logger.Debug("Fetching replications status")
for i, replication := range replications.Replications {
var status ReplicationStatus
if replication.Enabled {
Expand All @@ -66,7 +64,7 @@ func (c *Client) FetchReplications() (Replications, error) {
return replications, err
}
if err := json.Unmarshal(statusResp.Body, &status); err != nil {
level.Error(c.logger).Log("msg", "There was an issue when try to unmarshal replication status respond")
c.logger.Error("There was an issue when try to unmarshal replication status respond")
return replications, &UnmarshalError{
message: err.Error(),
endpoint: fmt.Sprintf("%s/%s", replicationStatusEndpoint, replication.RepoKey),
Expand Down
10 changes: 4 additions & 6 deletions artifactory/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package artifactory

import (
"encoding/json"

"github.com/go-kit/log/level"
)

const (
Expand All @@ -24,14 +22,14 @@ type Users struct {
// FetchUsers makes the API call to users endpoint and returns []User
func (c *Client) FetchUsers() (Users, error) {
var users Users
level.Debug(c.logger).Log("msg", "Fetching users stats")
c.logger.Debug("Fetching users stats")
resp, err := c.FetchHTTP(usersEndpoint)
if err != nil {
return users, err
}
users.NodeId = resp.NodeId
if err := json.Unmarshal(resp.Body, &users.Users); err != nil {
level.Error(c.logger).Log("msg", "There was an issue when try to unmarshal users respond")
c.logger.Error("There was an issue when try to unmarshal users respond")
return users, &UnmarshalError{
message: err.Error(),
endpoint: usersEndpoint,
Expand All @@ -53,14 +51,14 @@ type Groups struct {
// FetchGroups makes the API call to groups endpoint and returns []Group
func (c *Client) FetchGroups() (Groups, error) {
var groups Groups
level.Debug(c.logger).Log("msg", "Fetching groups stats")
c.logger.Debug("Fetching groups stats")
resp, err := c.FetchHTTP(groupsEndpoint)
if err != nil {
return groups, err
}
groups.NodeId = resp.NodeId
if err := json.Unmarshal(resp.Body, &groups.Groups); err != nil {
level.Error(c.logger).Log("msg", "There was an issue when try to unmarshal groups respond")
c.logger.Error("There was an issue when try to unmarshal groups respond")
return groups, &UnmarshalError{
message: err.Error(),
endpoint: groupsEndpoint,
Expand Down
6 changes: 2 additions & 4 deletions artifactory/storageinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package artifactory

import (
"encoding/json"

"github.com/go-kit/log/level"
)

const (
Expand Down Expand Up @@ -43,14 +41,14 @@ type StorageInfo struct {
// FetchStorageInfo makes the API call to storageinfo endpoint and returns StorageInfo
func (c *Client) FetchStorageInfo() (StorageInfo, error) {
var storageInfo StorageInfo
level.Debug(c.logger).Log("msg", "Fetching storage info stats")
c.logger.Debug("Fetching storage info stats")
resp, err := c.FetchHTTP(storageInfoEndpoint)
if err != nil {
return storageInfo, err
}
storageInfo.NodeId = resp.NodeId
if err := json.Unmarshal(resp.Body, &storageInfo); err != nil {
level.Error(c.logger).Log("msg", "There was an issue when try to unmarshal storageInfo respond")
c.logger.Error("There was an issue when try to unmarshal storageInfo respond")
return storageInfo, &UnmarshalError{
message: err.Error(),
endpoint: storageInfoEndpoint,
Expand Down
14 changes: 6 additions & 8 deletions artifactory/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package artifactory

import (
"encoding/json"

"github.com/go-kit/log/level"
)

const (
Expand All @@ -20,15 +18,15 @@ type HealthStatus struct {
// FetchHealth returns true if the ping endpoint returns "OK"
func (c *Client) FetchHealth() (HealthStatus, error) {
health := HealthStatus{Healthy: false}
level.Debug(c.logger).Log("msg", "Fetching health stats")
c.logger.Debug("Fetching health stats")
resp, err := c.FetchHTTP(pingEndpoint)
if err != nil {
return health, err
}
health.NodeId = resp.NodeId
bodyString := string(resp.Body)
if bodyString == "OK" {
level.Debug(c.logger).Log("msg", "System ping returned OK")
c.logger.Debug("System ping returned OK")
health.Healthy = true
return health, nil
}
Expand All @@ -47,14 +45,14 @@ type BuildInfo struct {
// FetchBuildInfo makes the API call to version endpoint and returns BuildInfo
func (c *Client) FetchBuildInfo() (BuildInfo, error) {
var buildInfo BuildInfo
level.Debug(c.logger).Log("msg", "Fetching build stats")
c.logger.Debug("Fetching build stats")
resp, err := c.FetchHTTP(versionEndpoint)
if err != nil {
return buildInfo, err
}
buildInfo.NodeId = resp.NodeId
if err := json.Unmarshal(resp.Body, &buildInfo); err != nil {
level.Error(c.logger).Log("msg", "There was an issue when try to unmarshal buildInfo respond")
c.logger.Error("There was an issue when try to unmarshal buildInfo respond")
return buildInfo, &UnmarshalError{
message: err.Error(),
endpoint: versionEndpoint,
Expand All @@ -74,14 +72,14 @@ type LicenseInfo struct {
// FetchLicense makes the API call to license endpoint and returns LicenseInfo
func (c *Client) FetchLicense() (LicenseInfo, error) {
var licenseInfo LicenseInfo
level.Debug(c.logger).Log("msg", "Fetching license stats")
c.logger.Debug("Fetching license stats")
resp, err := c.FetchHTTP(licenseEndpoint)
if err != nil {
return licenseInfo, err
}
licenseInfo.NodeId = resp.NodeId
if err := json.Unmarshal(resp.Body, &licenseInfo); err != nil {
level.Error(c.logger).Log("msg", "There was an issue when try to unmarshal licenseInfo respond")
c.logger.Error("There was an issue when try to unmarshal licenseInfo respond")
return licenseInfo, &UnmarshalError{
message: err.Error(),
endpoint: licenseEndpoint,
Expand Down
Loading