diff --git a/README.md b/README.md index 0ee16c0..07d3577 100755 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/artifactory/federation.go b/artifactory/federation.go index f1454ea..127e5a1 100644 --- a/artifactory/federation.go +++ b/artifactory/federation.go @@ -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 { @@ -93,54 +91,3 @@ func (c *Client) FetchUnavailableMirrors() (UnavailableMirrors, error) { return unavailableMirrors, nil } - -// FederatedRepoStatus represents single element of API respond from federation/status/repo/ 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/ 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 -} diff --git a/collector/collector.go b/collector/collector.go index fc13197..a065e8d 100755 --- a/collector/collector.go +++ b/collector/collector.go @@ -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...)), } ) @@ -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 diff --git a/collector/federation.go b/collector/federation.go index 5dba1e9..510a676 100644 --- a/collector/federation.go +++ b/collector/federation.go @@ -1,8 +1,6 @@ package collector import ( - "strings" - "github.com/go-kit/kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -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 -}