Merge pull request #12234 from SergeTupchiy/EMQX-11643-fix-otel-conf-incompatibility
fix(emqx_opentelemetry): use converter to convert legacy metrics config
This commit is contained in:
commit
2d209ec576
|
@ -1,6 +1,6 @@
|
|||
{application, emqx_conf, [
|
||||
{description, "EMQX configuration management"},
|
||||
{vsn, "0.1.32"},
|
||||
{vsn, "0.1.33"},
|
||||
{registered, []},
|
||||
{mod, {emqx_conf_app, []}},
|
||||
{applications, [kernel, stdlib, emqx_ctl]},
|
||||
|
|
|
@ -77,8 +77,7 @@
|
|||
|
||||
%% Callback to upgrade config after loaded from config file but before validation.
|
||||
upgrade_raw_conf(RawConf) ->
|
||||
RawConf1 = emqx_connector_schema:transform_bridges_v1_to_connectors_and_bridges_v2(RawConf),
|
||||
emqx_otel_schema:upgrade_legacy_metrics(RawConf1).
|
||||
emqx_connector_schema:transform_bridges_v1_to_connectors_and_bridges_v2(RawConf).
|
||||
|
||||
namespace() -> emqx.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{application, emqx_opentelemetry, [
|
||||
{description, "OpenTelemetry for EMQX Broker"},
|
||||
{vsn, "0.2.1"},
|
||||
{vsn, "0.2.2"},
|
||||
{registered, []},
|
||||
{mod, {emqx_otel_app, []}},
|
||||
{applications, [
|
||||
|
|
|
@ -24,40 +24,15 @@
|
|||
desc/1
|
||||
]).
|
||||
|
||||
-export([upgrade_legacy_metrics/1]).
|
||||
|
||||
%% Compatibility with the previous schema that defined only metric fields
|
||||
upgrade_legacy_metrics(RawConf) ->
|
||||
case RawConf of
|
||||
#{<<"opentelemetry">> := Otel} ->
|
||||
Otel1 =
|
||||
case maps:take(<<"enable">>, Otel) of
|
||||
{MetricsEnable, OtelConf} ->
|
||||
emqx_utils_maps:deep_put(
|
||||
[<<"metrics">>, <<"enable">>], OtelConf, MetricsEnable
|
||||
);
|
||||
error ->
|
||||
Otel
|
||||
end,
|
||||
Otel2 =
|
||||
case Otel1 of
|
||||
#{<<"exporter">> := #{<<"interval">> := Interval} = Exporter} ->
|
||||
emqx_utils_maps:deep_put(
|
||||
[<<"metrics">>, <<"interval">>],
|
||||
Otel1#{<<"exporter">> => maps:remove(<<"interval">>, Exporter)},
|
||||
Interval
|
||||
);
|
||||
_ ->
|
||||
Otel1
|
||||
end,
|
||||
RawConf#{<<"opentelemetry">> => Otel2};
|
||||
_ ->
|
||||
RawConf
|
||||
end.
|
||||
|
||||
namespace() -> opentelemetry.
|
||||
|
||||
roots() -> ["opentelemetry"].
|
||||
roots() ->
|
||||
[
|
||||
{"opentelemetry",
|
||||
?HOCON(?R_REF("opentelemetry"), #{
|
||||
converter => fun legacy_metrics_converter/2
|
||||
})}
|
||||
].
|
||||
|
||||
fields("opentelemetry") ->
|
||||
[
|
||||
|
@ -259,3 +234,27 @@ desc("otel_metrics") -> ?DESC(otel_metrics);
|
|||
desc("otel_traces") -> ?DESC(otel_traces);
|
||||
desc("trace_filter") -> ?DESC(trace_filter);
|
||||
desc(_) -> undefined.
|
||||
|
||||
%% Compatibility with the previous schema that defined only metrics fields
|
||||
legacy_metrics_converter(OtelConf, _Opts) when is_map(OtelConf) ->
|
||||
Otel1 =
|
||||
case maps:take(<<"enable">>, OtelConf) of
|
||||
{MetricsEnable, OtelConf1} ->
|
||||
emqx_utils_maps:deep_put(
|
||||
[<<"metrics">>, <<"enable">>], OtelConf1, MetricsEnable
|
||||
);
|
||||
error ->
|
||||
OtelConf
|
||||
end,
|
||||
case Otel1 of
|
||||
#{<<"exporter">> := #{<<"interval">> := Interval} = Exporter} ->
|
||||
emqx_utils_maps:deep_put(
|
||||
[<<"metrics">>, <<"interval">>],
|
||||
Otel1#{<<"exporter">> => maps:remove(<<"interval">>, Exporter)},
|
||||
Interval
|
||||
);
|
||||
_ ->
|
||||
Otel1
|
||||
end;
|
||||
legacy_metrics_converter(Conf, _Opts) ->
|
||||
Conf.
|
||||
|
|
|
@ -22,8 +22,7 @@
|
|||
-include_lib("common_test/include/ct.hrl").
|
||||
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||
|
||||
%% Backward compatibility suite for `upgrade_raw_conf/1`,
|
||||
%% expected callback is `emqx_otel_schema:upgrade_legacy_metrics/1`
|
||||
%% Backward compatibility suite for legacy metrics converter
|
||||
|
||||
-define(OLD_CONF_ENABLED, <<
|
||||
"\n"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix old (prior to EMQX 5.4.0) Open Telemetry configuration incompatibility when the config is defined in emqx.conf.
|
Loading…
Reference in New Issue