metrics.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package metrics
  13. import (
  14. "github.com/prometheus/client_golang/prometheus"
  15. "sigs.k8s.io/controller-runtime/pkg/metrics"
  16. "github.com/external-secrets/external-secrets/pkg/constants"
  17. )
  18. const (
  19. ExternalSecretSubsystem = "externalsecret"
  20. providerAPICalls = "provider_api_calls_count"
  21. )
  22. var (
  23. syncCallsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
  24. Subsystem: ExternalSecretSubsystem,
  25. Name: providerAPICalls,
  26. Help: "Number of API calls towards the secret provider",
  27. }, []string{"provider", "call", "status"})
  28. )
  29. func ObserveAPICall(provider, call string, err error) {
  30. syncCallsTotal.WithLabelValues(provider, call, deriveStatus(err)).Inc()
  31. }
  32. func deriveStatus(err error) string {
  33. if err != nil {
  34. return constants.StatusError
  35. }
  36. return constants.StatusSuccess
  37. }
  38. func init() {
  39. metrics.Registry.MustRegister(syncCallsTotal)
  40. }