FEATURE: add #set alias for #observe

approved

#1

FEATURE: add #set alias for #observe

This makes it a bit easier to migrate from the prometheus gem

diff --git a/lib/prometheus_exporter/metric/gauge.rb b/lib/prometheus_exporter/metric/gauge.rb
index b26ddcf..ec55778 100644
--- a/lib/prometheus_exporter/metric/gauge.rb
+++ b/lib/prometheus_exporter/metric/gauge.rb
@@ -30,6 +30,8 @@ module PrometheusExporter::Metric
       end
     end
 
+    alias_method :set, :observe
+
     def increment(labels = {}, value = 1)
       @data[labels] ||= 0
       @data[labels] += value
diff --git a/test/metric/gauge_test.rb b/test/metric/gauge_test.rb
index 71cca1a..b56c797 100644
--- a/test/metric/gauge_test.rb
+++ b/test/metric/gauge_test.rb
@@ -77,6 +77,20 @@ module PrometheusExporter::Metric
       assert_equal(gauge.to_prometheus_text, text)
     end
 
+    it "can use the set on alias" do
+
+      gauge.set(10)
+      gauge.set(11)
+
+      text = <<~TEXT
+        # HELP a_gauge my amazing gauge
+        # TYPE a_gauge gauge
+        a_gauge 11
+      TEXT
+
+      assert_equal(gauge.to_prometheus_text, text)
+    end
+
     it "can correctly reset on change with labels" do
       gauge.observe(1, sam: "ham")
       gauge.observe(2, sam: "ham")

GitHub sha: 041e39f5


Approved #2