-module(themis@internal@metric@counter). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([init_record/2, increment_by/3, increment/2, delete_record/2, print/2, new_name/1, new/2]). -export_type([counter/0, counter_error/0]). -type counter() :: any(). -type counter_error() :: record_already_exists | record_not_found | {name_error, themis@internal@metric:metric_error()}. -file("/git/Themis/src/themis/internal/metric/counter.gleam", 32). -spec init_record( themis@internal@metric:metric(counter(), themis@number:number_(), nil), themis@internal@label:label_set() ) -> themis@internal@metric:metric(counter(), themis@number:number_(), nil). init_record(From, Labels) -> erlang:setelement( 3, From, begin _pipe = erlang:element(3, From), gleam@dict:insert(_pipe, Labels, {int, 0}) end ). -file("/git/Themis/src/themis/internal/metric/counter.gleam", 46). -spec increment_by( themis@internal@metric:metric(counter(), themis@number:number_(), nil), themis@internal@label:label_set(), themis@number:number_() ) -> themis@internal@metric:metric(counter(), themis@number:number_(), nil). increment_by(From, Labels, By) -> New_val = begin _pipe = gleam_stdlib:map_get(erlang:element(3, From), Labels), _pipe@1 = gleam@result:unwrap(_pipe, themis@number:integer(0)), themis@number:add(_pipe@1, By) end, erlang:setelement( 3, From, begin _pipe@2 = erlang:element(3, From), gleam@dict:insert(_pipe@2, Labels, New_val) end ). -file("/git/Themis/src/themis/internal/metric/counter.gleam", 39). -spec increment( themis@internal@metric:metric(counter(), themis@number:number_(), nil), themis@internal@label:label_set() ) -> themis@internal@metric:metric(counter(), themis@number:number_(), nil). increment(From, Labels) -> increment_by(From, Labels, {int, 1}). -file("/git/Themis/src/themis/internal/metric/counter.gleam", 58). -spec delete_record( themis@internal@metric:metric(counter(), themis@number:number_(), nil), themis@internal@label:label_set() ) -> themis@internal@metric:metric(counter(), themis@number:number_(), nil). delete_record(From, Labels) -> erlang:setelement( 3, From, gleam@dict:delete(erlang:element(3, From), Labels) ). -file("/git/Themis/src/themis/internal/metric/counter.gleam", 65). -spec print( themis@internal@metric:metric(counter(), themis@number:number_(), nil), themis@internal@metric:metric_name() ) -> binary(). print(Metric, Name) -> Name@1 = themis@internal@metric:name_to_string(Name), Help = <<<<<<"# HELP "/utf8, Name@1/binary>>/binary, " "/utf8>>/binary, (erlang:element(2, Metric))/binary>>, Type_ = <<<<"# TYPE "/utf8, Name@1/binary>>/binary, " counter"/utf8>>, _pipe = (gleam@dict:fold( erlang:element(3, Metric), [<<<<<>/binary, Type_/binary>>/binary, "\n"/utf8>>], fun(Current, Labels, Value) -> [<<<<<<<>/binary, " "/utf8>>/binary, (themis@number:print(Value))/binary>>/binary, "\n"/utf8>> | Current] end )), _pipe@1 = lists:reverse(_pipe), _pipe@2 = gleam_stdlib:identity(_pipe@1), unicode:characters_to_binary(_pipe@2). -file("/git/Themis/src/themis/internal/metric/counter.gleam", 86). -spec new_name(binary()) -> {ok, themis@internal@metric:metric_name()} | {error, themis@internal@metric:metric_error()}. new_name(Name) -> _pipe = (<>), themis@internal@metric:new_name(_pipe, [<<"counter"/utf8>>]). -file("/git/Themis/src/themis/internal/metric/counter.gleam", 21). -spec new(binary(), binary()) -> {ok, {themis@internal@metric:metric_name(), themis@internal@metric:metric(counter(), themis@number:number_(), nil)}} | {error, themis@internal@metric:metric_error()}. new(Name, Description) -> R = begin _pipe = Name, new_name(_pipe) end, gleam@result:map( R, fun(Name@1) -> {Name@1, {metric, Description, maps:new(), nil}} end ).