Skip to content

Commit

Permalink
Remove federation repo status (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
peimanja committed Feb 7, 2023
1 parent 93c498b commit cea35d2
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 99 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ Some metrics are not available with Artifactory OSS license. The exporter return
| artifactory_system_version | Version and revision of Artifactory as labels. | `version`, `revision` | ✅ |
| artifactory_federation_mirror_lag | Federation mirror lag in milliseconds. | `name`, `remote_url`, `remote_name` | |
| artifactory_federation_unavailable_mirror | Unsynchronized federated mirror status. | `status`, `name`, `remote_url`, `remote_name` | |
| artifactory_federation_repo_status | Synchronization status of the Federation for a repository | `status`, `name`, `remote_url`, `remote_name` | |

* Common labels:
* `node_id`: Artifactory node ID that the metric is scraped from.
Expand All @@ -200,7 +199,7 @@ Some metrics are expensive to compute and are disabled by default. To enable the
Supported optional metrics:

* `replication_status` - Extracts status of replication for each repository which has replication enabled. Enabling this will add the `status` label to `artifactory_replication_enabled` metric.
* `federation_status` - Extracts repo federation metrics. Enabling this will add three new metrics: `artifactory_federation_mirror_lag`, `artifactory_federation_mirror_status` and `artifactory_federation_unavailable_mirror`. Please note that these metrics are only available in Artifactory Enterprise Plus and version 7.18.3 and above.
* `federation_status` - Extracts federation metrics. Enabling this will add two new metrics: `artifactory_federation_mirror_lag`, and `artifactory_federation_unavailable_mirror`. Please note that these metrics are only available in Artifactory Enterprise Plus and version 7.18.3 and above.

### Grafana Dashboard

Expand Down
53 changes: 0 additions & 53 deletions artifactory/federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package artifactory

import (
"encoding/json"
"fmt"

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

const federationMirrorsLagEndpoint = "federation/status/mirrorsLag"
const federationUnavailableMirrorsEndpoint = "federation/status/unavailableMirrors"
const federationRepoStatusEndpoint = "federation/status/repo"

// IsFederationEnabled checks one of the federation endpoints to see if federation is enabled
func (c *Client) IsFederationEnabled() bool {
Expand Down Expand Up @@ -93,54 +91,3 @@ func (c *Client) FetchUnavailableMirrors() (UnavailableMirrors, error) {

return unavailableMirrors, nil
}

// FederatedRepoStatus represents single element of API respond from federation/status/repo/<repoKey> endpoint
// We don't need all the fields but we'll leave them here for future use
type FederatedRepoStatus struct {
LocalKey string `json:"localKey"`
BinariesTasksInfo struct {
InProgressTasks int `json:"inProgressTasks"`
FailingTasks int `json:"failingTasks"`
} `json:"binariesTasksInfo"`
MirrorEventsStatusInfo []struct {
RemoteUrl string `json:"remoteUrl"`
RemoteRepoKey string `json:"remoteRepoKey"`
Status string `json:"status"`
CreateEvents int `json:"createEvents"`
UpdateEvents int `json:"updateEvents"`
DeleteEvents int `json:"deleteEvents"`
PropsEvents int `json:"propsEvents"`
ErrorEvents int `json:"errorEvents"`
LagInMS int `json:"lagInMS"`
} `json:"mirrorEventsStatusInfo"`
FederatedArtifactStatus struct {
CountFullyReplicateArtifacts int `json:"countFullyReplicateArtifacts"`
CountArtificiallyReplicatedArtifacts int `json:"countArtificiallyReplicatedArtifacts"`
} `json:"federatedArtifactStatus"`
NodeId string
}

// FetchFederatedRepoStatus makes the API call to federation/status/repo/<repoKey> endpoint and returns FederatedRepoStatus
func (c *Client) FetchFederatedRepoStatus(repoKey string) (FederatedRepoStatus, error) {
var federatedRepoStatus FederatedRepoStatus
level.Debug(c.logger).Log("msg", "Fetching federated repo status")
resp, err := c.FetchHTTP(fmt.Sprintf("%s/%s", federationRepoStatusEndpoint, repoKey))
if err != nil {
if err.(*APIError).status == 404 {
return federatedRepoStatus, nil
}
return federatedRepoStatus, err
}

federatedRepoStatus.NodeId = resp.NodeId

if err := json.Unmarshal(resp.Body, &federatedRepoStatus); err != nil {
level.Error(c.logger).Log("msg", "There was an issue when try to unmarshal federated repo status respond")
return federatedRepoStatus, &UnmarshalError{
message: err.Error(),
endpoint: fmt.Sprintf("%s/%s", federationRepoStatusEndpoint, repoKey),
}
}

return federatedRepoStatus, nil
}
3 changes: 0 additions & 3 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ var (
federationMetrics = metrics{
"mirrorLag": newMetric("mirror_lag", "federation", "Federation mirror lag in milliseconds.", federationLabelNames),
"unavailableMirror": newMetric("unavailable_mirror", "federation", "Unsynchronized federated mirror status", append([]string{"status"}, federationLabelNames...)),
"repoStatus": newMetric("repo_status", "federation", "Synchronization status of the Federation for a repository.", append([]string{"status"}, federationLabelNames...)),
}
)

Expand Down Expand Up @@ -185,8 +184,6 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) (up float64) {
if e.optionalMetrics.FederationStatus && e.client.IsFederationEnabled() {
e.exportFederationMirrorLags(ch)
e.exportFederationUnavailableMirrors(ch)
// Get Federation Repo Status
e.exportFederationRepoStatus(repoSummaryList, ch)
}

return 1
Expand Down
41 changes: 0 additions & 41 deletions collector/federation.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package collector

import (
"strings"

"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -50,42 +48,3 @@ func (e *Exporter) exportFederationUnavailableMirrors(ch chan<- prometheus.Metri

return nil
}

func (e *Exporter) getFederatedRepos(repoSummary []repoSummary) []string {
var federatedRepos []string
for _, repo := range repoSummary {
if repo.Type == strings.ToLower(FederationRepoType) {
federatedRepos = append(federatedRepos, repo.Name)
}
}
return federatedRepos
}

func (e *Exporter) exportFederationRepoStatus(repoSummary []repoSummary, ch chan<- prometheus.Metric) error {
repoList := e.getFederatedRepos(repoSummary)
if len(repoList) == 0 {
level.Debug(e.logger).Log("msg", "No federated repos found")
return nil
}

for _, repo := range repoList {
// Fetch Federation Repo Status
federationRepoStatus, err := e.client.FetchFederatedRepoStatus(repo)
if err != nil {
e.totalAPIErrors.Inc()
return err
}

// Check if the respond is not empty (depends on the Artifactory version)
if federationRepoStatus.LocalKey == "" {
level.Debug(e.logger).Log("msg", "No federation repo status found", "repo", repo)
return nil
}

for _, mirrorEventsStatusInfo := range federationRepoStatus.MirrorEventsStatusInfo {
level.Debug(e.logger).Log("msg", "Registering metric", "metric", "federationRepoStatus", "status", mirrorEventsStatusInfo.Status, "repo", repo, "remote_url", mirrorEventsStatusInfo.RemoteUrl, "remote_name", mirrorEventsStatusInfo.RemoteRepoKey)
ch <- prometheus.MustNewConstMetric(federationMetrics["repoStatus"], prometheus.GaugeValue, 1, strings.ToLower(mirrorEventsStatusInfo.Status), repo, strings.ToLower(mirrorEventsStatusInfo.RemoteUrl), mirrorEventsStatusInfo.RemoteRepoKey, federationRepoStatus.NodeId)
}
}
return nil
}

0 comments on commit cea35d2

Please sign in to comment.