Add bin and edit workflow
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s

This commit is contained in:
2026-09-16 13:11:16 -06:00
parent c8ac4fcae5
commit 4cee170d66
17576 changed files with 895740 additions and 2 deletions
@@ -0,0 +1,64 @@
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2023-2024, by Samuel Williams.
require_relative "../metric"
module Metrics
module Backend
module Capture
class Metric < Metrics::Metric
def initialize(...)
super
@values = []
@tags = Set.new
@sample_rates = []
end
attr :values
attr :tags
attr :sample_rates
def emit(value, tags: nil, sample_rate: 1.0)
@values << value
@tags.merge(tags) if tags
@sample_rates << sample_rate
end
def as_json
{
name: @name,
type: @type,
description: @description,
unit: @unit,
values: @values,
tags: @tags.to_a.sort,
sample_rates: @sample_rates.sort.uniq
}
end
def to_json(...)
as_json.to_json(...)
end
end
def self.metrics
@metrics ||= []
end
module Interface
def metric(name, type, description: nil, unit: nil, &block)
metric = Metric.new(name, type, description, unit)
Capture.metrics << metric
return metric
end
end
end
Interface = Capture::Interface
end
end
@@ -0,0 +1,37 @@
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2021-2024, by Samuel Williams.
require_relative "../metric"
require "console"
module Metrics
module Backend
module Console
class Metric < Metrics::Metric
def emit(value, tags: nil, sample_rate: 1.0)
::Console.logger.info(self, @name, value, tags)
end
end
module Interface
def metric(name, type, description: nil, unit: nil, &block)
return Metric.new(name, type, description, unit)
end
# def metric_call_counter(name, description: nil, tags: nil)
# metric = self.metric(...)
#
# self.define_method(name) do
# metric.emit(1)
# super
# end
# end
end
end
Interface = Console::Interface
end
end
@@ -0,0 +1,67 @@
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2021-2024, by Samuel Williams.
require_relative "../metric"
module Metrics
module Backend
module Test
VALID_METRIC_NAME = /\A[a-z0-9\-_\.]{1,128}\Z/i
VALID_TAG = /\A[a-z][a-z0-9\-_\.:\\]{0,127}\Z/i
class Metric < Metrics::Metric
def emit(value, tags: nil, sample_rate: 1.0)
unless value.is_a?(Numeric)
raise ArgumentError, "Value must be numeric!"
end
tags&.each do |tag|
raise ArgumentError, "Invalid tag (must be String): #{tag.inspect}!" unless tag.is_a?(String)
# We should let the underlying backend handle any tag limitations, e.g. converting invalid characters to underscores, etc.
#
# unless tag =~ VALID_TAG
# raise ArgumentError, "Invalid tag (must match #{VALID_TAG}): #{tag.inspect}!"
# end
end
end
end
module Interface
def metric(name, type, description: nil, unit: nil, &block)
unless name.is_a?(String)
raise ArgumentError, "Invalid name (must be String): #{name.inspect}!"
end
unless name =~ VALID_METRIC_NAME
raise ArgumentError, "Invalid name (must match #{VALID_METRIC_NAME}): #{name.inspect}!"
end
unless type.is_a?(Symbol)
raise ArgumentError, "Invalid type (must be Symbol): #{type.inspect}!"
end
# Description is optional but must be string if given:
if description
unless description.is_a?(String)
raise ArgumentError, "Invalid description (must be String): #{description.inspect}!"
end
end
# Unit is optional but must be string if given:
if unit
unless unit.is_a?(String)
raise ArgumentError, "Invalid unit (must be String): #{unit.inspect}!"
end
end
return Metric.new(name, type, description, unit)
end
end
end
Interface = Test::Interface
end
end