fix(emqx_opentelemetry): use converter to convert legacy metrics config
HOCON converter is cleaner and safer option, that will also work for configurations defined in emqx.conf. Previously used `upgrade_raw_conf/1` is currently not supported in hocon_cli (used in bin/emqx). Fixes: EMQX-11643
This commit is contained in:
parent
f36b842d94
commit
423b8b4274
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_conf, [
|
{application, emqx_conf, [
|
||||||
{description, "EMQX configuration management"},
|
{description, "EMQX configuration management"},
|
||||||
{vsn, "0.1.32"},
|
{vsn, "0.1.33"},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{mod, {emqx_conf_app, []}},
|
{mod, {emqx_conf_app, []}},
|
||||||
{applications, [kernel, stdlib, emqx_ctl]},
|
{applications, [kernel, stdlib, emqx_ctl]},
|
||||||
|
|
|
@ -77,8 +77,7 @@
|
||||||
|
|
||||||
%% Callback to upgrade config after loaded from config file but before validation.
|
%% Callback to upgrade config after loaded from config file but before validation.
|
||||||
upgrade_raw_conf(RawConf) ->
|
upgrade_raw_conf(RawConf) ->
|
||||||
RawConf1 = emqx_connector_schema:transform_bridges_v1_to_connectors_and_bridges_v2(RawConf),
|
emqx_connector_schema:transform_bridges_v1_to_connectors_and_bridges_v2(RawConf).
|
||||||
emqx_otel_schema:upgrade_legacy_metrics(RawConf1).
|
|
||||||
|
|
||||||
namespace() -> emqx.
|
namespace() -> emqx.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_opentelemetry, [
|
{application, emqx_opentelemetry, [
|
||||||
{description, "OpenTelemetry for EMQX Broker"},
|
{description, "OpenTelemetry for EMQX Broker"},
|
||||||
{vsn, "0.2.1"},
|
{vsn, "0.2.2"},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{mod, {emqx_otel_app, []}},
|
{mod, {emqx_otel_app, []}},
|
||||||
{applications, [
|
{applications, [
|
||||||
|
|
|
@ -24,40 +24,15 @@
|
||||||
desc/1
|
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.
|
namespace() -> opentelemetry.
|
||||||
|
|
||||||
roots() -> ["opentelemetry"].
|
roots() ->
|
||||||
|
[
|
||||||
|
{"opentelemetry",
|
||||||
|
?HOCON(?R_REF("opentelemetry"), #{
|
||||||
|
converter => fun legacy_metrics_converter/2
|
||||||
|
})}
|
||||||
|
].
|
||||||
|
|
||||||
fields("opentelemetry") ->
|
fields("opentelemetry") ->
|
||||||
[
|
[
|
||||||
|
@ -259,3 +234,27 @@ desc("otel_metrics") -> ?DESC(otel_metrics);
|
||||||
desc("otel_traces") -> ?DESC(otel_traces);
|
desc("otel_traces") -> ?DESC(otel_traces);
|
||||||
desc("trace_filter") -> ?DESC(trace_filter);
|
desc("trace_filter") -> ?DESC(trace_filter);
|
||||||
desc(_) -> undefined.
|
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("common_test/include/ct.hrl").
|
||||||
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||||
|
|
||||||
%% Backward compatibility suite for `upgrade_raw_conf/1`,
|
%% Backward compatibility suite for legacy metrics converter
|
||||||
%% expected callback is `emqx_otel_schema:upgrade_legacy_metrics/1`
|
|
||||||
|
|
||||||
-define(OLD_CONF_ENABLED, <<
|
-define(OLD_CONF_ENABLED, <<
|
||||||
"\n"
|
"\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