Merge pull request #10134 from sstrigler/release-e5.0.2-alpha.1
Release e5.0.2 alpha.1
This commit is contained in:
commit
bad952a114
|
@ -5,5 +5,6 @@ PGSQL_TAG=13
|
|||
LDAP_TAG=2.4.50
|
||||
INFLUXDB_TAG=2.5.0
|
||||
TDENGINE_TAG=3.0.2.4
|
||||
DYNAMO_TAG=1.21.0
|
||||
|
||||
TARGET=emqx/emqx
|
||||
|
|
|
@ -0,0 +1,678 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
NOTE: User and query level settings are set up in "users.xml" file.
|
||||
If you have accidentially specified user-level settings here, server won't start.
|
||||
You can either move the settings to the right place inside "users.xml" file
|
||||
or add <skip_check_for_incorrect_settings>1</skip_check_for_incorrect_settings> here.
|
||||
-->
|
||||
<yandex>
|
||||
<logger>
|
||||
<!-- Possible levels: https://github.com/pocoproject/poco/blob/poco-1.9.4-release/Foundation/include/Poco/Logger.h#L105 -->
|
||||
<level>trace</level>
|
||||
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
|
||||
<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
|
||||
<size>1000M</size>
|
||||
<count>10</count>
|
||||
<!-- <console>1</console> --> <!-- Default behavior is autodetection (log to console if not daemon mode and is tty) -->
|
||||
|
||||
<!-- Per level overrides (legacy):
|
||||
|
||||
For example to suppress logging of the ConfigReloader you can use:
|
||||
NOTE: levels.logger is reserved, see below.
|
||||
-->
|
||||
<!--
|
||||
<levels>
|
||||
<ConfigReloader>none</ConfigReloader>
|
||||
</levels>
|
||||
-->
|
||||
|
||||
<!-- Per level overrides:
|
||||
|
||||
For example to suppress logging of the RBAC for default user you can use:
|
||||
(But please note that the logger name maybe changed from version to version, even after minor upgrade)
|
||||
-->
|
||||
<!--
|
||||
<levels>
|
||||
<logger>
|
||||
<name>ContextAccess (default)</name>
|
||||
<level>none</level>
|
||||
</logger>
|
||||
<logger>
|
||||
<name>DatabaseOrdinary (test)</name>
|
||||
<level>none</level>
|
||||
</logger>
|
||||
</levels>
|
||||
-->
|
||||
</logger>
|
||||
|
||||
<send_crash_reports>
|
||||
<!-- Changing <enabled> to true allows sending crash reports to -->
|
||||
<!-- the ClickHouse core developers team via Sentry https://sentry.io -->
|
||||
<!-- Doing so at least in pre-production environments is highly appreciated -->
|
||||
<enabled>false</enabled>
|
||||
<!-- Change <anonymize> to true if you don't feel comfortable attaching the server hostname to the crash report -->
|
||||
<anonymize>false</anonymize>
|
||||
<!-- Default endpoint should be changed to different Sentry DSN only if you have -->
|
||||
<!-- some in-house engineers or hired consultants who're going to debug ClickHouse issues for you -->
|
||||
<endpoint>https://6f33034cfe684dd7a3ab9875e57b1c8d@o388870.ingest.sentry.io/5226277</endpoint>
|
||||
</send_crash_reports>
|
||||
|
||||
<!--display_name>production</display_name--> <!-- It is the name that will be shown in the client -->
|
||||
<http_port>8123</http_port>
|
||||
<tcp_port>9000</tcp_port>
|
||||
<mysql_port>9004</mysql_port>
|
||||
<!-- For HTTPS and SSL over native protocol. -->
|
||||
<!--
|
||||
<https_port>8443</https_port>
|
||||
<tcp_port_secure>9440</tcp_port_secure>
|
||||
-->
|
||||
<!-- Used with https_port and tcp_port_secure. Full ssl options list: https://github.com/ClickHouse-Extras/poco/blob/master/NetSSL_OpenSSL/include/Poco/Net/SSLManager.h#L71 -->
|
||||
<openSSL>
|
||||
<server> <!-- Used for https server AND secure tcp port -->
|
||||
<!-- openssl req -subj "/CN=localhost" -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout /etc/clickhouse-server/server.key -out /etc/clickhouse-server/server.crt -->
|
||||
<certificateFile>/etc/clickhouse-server/server.crt</certificateFile>
|
||||
<privateKeyFile>/etc/clickhouse-server/server.key</privateKeyFile>
|
||||
<!-- openssl dhparam -out /etc/clickhouse-server/dhparam.pem 4096 -->
|
||||
<dhParamsFile>/etc/clickhouse-server/dhparam.pem</dhParamsFile>
|
||||
<verificationMode>none</verificationMode>
|
||||
<loadDefaultCAFile>true</loadDefaultCAFile>
|
||||
<cacheSessions>true</cacheSessions>
|
||||
<disableProtocols>sslv2,sslv3</disableProtocols>
|
||||
<preferServerCiphers>true</preferServerCiphers>
|
||||
</server>
|
||||
|
||||
<client> <!-- Used for connecting to https dictionary source and secured Zookeeper communication -->
|
||||
<loadDefaultCAFile>true</loadDefaultCAFile>
|
||||
<cacheSessions>true</cacheSessions>
|
||||
<disableProtocols>sslv2,sslv3</disableProtocols>
|
||||
<preferServerCiphers>true</preferServerCiphers>
|
||||
<!-- Use for self-signed: <verificationMode>none</verificationMode> -->
|
||||
<invalidCertificateHandler>
|
||||
<!-- Use for self-signed: <name>AcceptCertificateHandler</name> -->
|
||||
<name>RejectCertificateHandler</name>
|
||||
</invalidCertificateHandler>
|
||||
</client>
|
||||
</openSSL>
|
||||
|
||||
<!-- Default root page on http[s] server. For example load UI from https://tabix.io/ when opening http://localhost:8123 -->
|
||||
<!--
|
||||
<http_server_default_response><![CDATA[<html ng-app="SMI2"><head><base href="http://ui.tabix.io/"></head><body><div ui-view="" class="content-ui"></div><script src="http://loader.tabix.io/master.js"></script></body></html>]]></http_server_default_response>
|
||||
-->
|
||||
|
||||
<!-- Port for communication between replicas. Used for data exchange. -->
|
||||
<interserver_http_port>9009</interserver_http_port>
|
||||
|
||||
<!-- Hostname that is used by other replicas to request this server.
|
||||
If not specified, than it is determined analoguous to 'hostname -f' command.
|
||||
This setting could be used to switch replication to another network interface.
|
||||
-->
|
||||
<!--
|
||||
<interserver_http_host>example.yandex.ru</interserver_http_host>
|
||||
-->
|
||||
|
||||
<!-- Listen specified host. use :: (wildcard IPv6 address), if you want to accept connections both with IPv4 and IPv6 from everywhere. -->
|
||||
<!-- <listen_host>::</listen_host> -->
|
||||
<!-- Same for hosts with disabled ipv6: -->
|
||||
<!-- <listen_host>0.0.0.0</listen_host> -->
|
||||
|
||||
<!-- Default values - try listen localhost on ipv4 and ipv6: -->
|
||||
<!--
|
||||
<listen_host>::1</listen_host>
|
||||
<listen_host>127.0.0.1</listen_host>
|
||||
-->
|
||||
<!-- Don't exit if ipv6 or ipv4 unavailable, but listen_host with this protocol specified -->
|
||||
<!-- <listen_try>0</listen_try> -->
|
||||
|
||||
<!-- Allow listen on same address:port -->
|
||||
<!-- <listen_reuse_port>0</listen_reuse_port> -->
|
||||
|
||||
<!-- <listen_backlog>64</listen_backlog> -->
|
||||
|
||||
<max_connections>4096</max_connections>
|
||||
<keep_alive_timeout>3</keep_alive_timeout>
|
||||
|
||||
<!-- Maximum number of concurrent queries. -->
|
||||
<max_concurrent_queries>100</max_concurrent_queries>
|
||||
|
||||
<!-- Maximum memory usage (resident set size) for server process.
|
||||
Zero value or unset means default. Default is "max_server_memory_usage_to_ram_ratio" of available physical RAM.
|
||||
If the value is larger than "max_server_memory_usage_to_ram_ratio" of available physical RAM, it will be cut down.
|
||||
|
||||
The constraint is checked on query execution time.
|
||||
If a query tries to allocate memory and the current memory usage plus allocation is greater
|
||||
than specified threshold, exception will be thrown.
|
||||
|
||||
It is not practical to set this constraint to small values like just a few gigabytes,
|
||||
because memory allocator will keep this amount of memory in caches and the server will deny service of queries.
|
||||
-->
|
||||
<max_server_memory_usage>0</max_server_memory_usage>
|
||||
|
||||
<!-- Maximum number of threads in the Global thread pool.
|
||||
This will default to a maximum of 10000 threads if not specified.
|
||||
This setting will be useful in scenarios where there are a large number
|
||||
of distributed queries that are running concurrently but are idling most
|
||||
of the time, in which case a higher number of threads might be required.
|
||||
-->
|
||||
|
||||
<max_thread_pool_size>10000</max_thread_pool_size>
|
||||
|
||||
<!-- On memory constrained environments you may have to set this to value larger than 1.
|
||||
-->
|
||||
<max_server_memory_usage_to_ram_ratio>10</max_server_memory_usage_to_ram_ratio>
|
||||
|
||||
<!-- Simple server-wide memory profiler. Collect a stack trace at every peak allocation step (in bytes).
|
||||
Data will be stored in system.trace_log table with query_id = empty string.
|
||||
Zero means disabled.
|
||||
-->
|
||||
<total_memory_profiler_step>4194304</total_memory_profiler_step>
|
||||
|
||||
<!-- Collect random allocations and deallocations and write them into system.trace_log with 'MemorySample' trace_type.
|
||||
The probability is for every alloc/free regardless to the size of the allocation.
|
||||
Note that sampling happens only when the amount of untracked memory exceeds the untracked memory limit,
|
||||
which is 4 MiB by default but can be lowered if 'total_memory_profiler_step' is lowered.
|
||||
You may want to set 'total_memory_profiler_step' to 1 for extra fine grained sampling.
|
||||
-->
|
||||
<total_memory_tracker_sample_probability>0</total_memory_tracker_sample_probability>
|
||||
|
||||
<!-- Set limit on number of open files (default: maximum). This setting makes sense on Mac OS X because getrlimit() fails to retrieve
|
||||
correct maximum value. -->
|
||||
<!-- <max_open_files>262144</max_open_files> -->
|
||||
|
||||
<!-- Size of cache of uncompressed blocks of data, used in tables of MergeTree family.
|
||||
In bytes. Cache is single for server. Memory is allocated only on demand.
|
||||
Cache is used when 'use_uncompressed_cache' user setting turned on (off by default).
|
||||
Uncompressed cache is advantageous only for very short queries and in rare cases.
|
||||
-->
|
||||
<uncompressed_cache_size>8589934592</uncompressed_cache_size>
|
||||
|
||||
<!-- Approximate size of mark cache, used in tables of MergeTree family.
|
||||
In bytes. Cache is single for server. Memory is allocated only on demand.
|
||||
You should not lower this value.
|
||||
-->
|
||||
<mark_cache_size>5368709120</mark_cache_size>
|
||||
|
||||
|
||||
<!-- Path to data directory, with trailing slash. -->
|
||||
<path>/var/lib/clickhouse/</path>
|
||||
|
||||
<!-- Path to temporary data for processing hard queries. -->
|
||||
<tmp_path>/var/lib/clickhouse/tmp/</tmp_path>
|
||||
|
||||
<!-- Policy from the <storage_configuration> for the temporary files.
|
||||
If not set <tmp_path> is used, otherwise <tmp_path> is ignored.
|
||||
|
||||
Notes:
|
||||
- move_factor is ignored
|
||||
- keep_free_space_bytes is ignored
|
||||
- max_data_part_size_bytes is ignored
|
||||
- you must have exactly one volume in that policy
|
||||
-->
|
||||
<!-- <tmp_policy>tmp</tmp_policy> -->
|
||||
|
||||
<!-- Directory with user provided files that are accessible by 'file' table function. -->
|
||||
<user_files_path>/var/lib/clickhouse/user_files/</user_files_path>
|
||||
|
||||
<!-- Path to folder where users and roles created by SQL commands are stored. -->
|
||||
<access_control_path>/var/lib/clickhouse/access/</access_control_path>
|
||||
|
||||
<!-- Path to configuration file with users, access rights, profiles of settings, quotas. -->
|
||||
<users_config>/etc/clickhouse-server/users.xml</users_config>
|
||||
|
||||
<!-- Default profile of settings. -->
|
||||
<default_profile>default</default_profile>
|
||||
|
||||
<!-- System profile of settings. This settings are used by internal processes (Buffer storage, Distibuted DDL worker and so on). -->
|
||||
<!-- <system_profile>default</system_profile> -->
|
||||
|
||||
<!-- Default database. -->
|
||||
<default_database>default</default_database>
|
||||
|
||||
<!-- Server time zone could be set here.
|
||||
|
||||
Time zone is used when converting between String and DateTime types,
|
||||
when printing DateTime in text formats and parsing DateTime from text,
|
||||
it is used in date and time related functions, if specific time zone was not passed as an argument.
|
||||
|
||||
Time zone is specified as identifier from IANA time zone database, like UTC or Africa/Abidjan.
|
||||
If not specified, system time zone at server startup is used.
|
||||
|
||||
Please note, that server could display time zone alias instead of specified name.
|
||||
Example: W-SU is an alias for Europe/Moscow and Zulu is an alias for UTC.
|
||||
-->
|
||||
<!-- <timezone>Europe/Moscow</timezone> -->
|
||||
|
||||
<!-- You can specify umask here (see "man umask"). Server will apply it on startup.
|
||||
Number is always parsed as octal. Default umask is 027 (other users cannot read logs, data files, etc; group can only read).
|
||||
-->
|
||||
<!-- <umask>022</umask> -->
|
||||
|
||||
<!-- Perform mlockall after startup to lower first queries latency
|
||||
and to prevent clickhouse executable from being paged out under high IO load.
|
||||
Enabling this option is recommended but will lead to increased startup time for up to a few seconds.
|
||||
-->
|
||||
<mlock_executable>true</mlock_executable>
|
||||
|
||||
<!-- Configuration of clusters that could be used in Distributed tables.
|
||||
https://clickhouse.tech/docs/en/operations/table_engines/distributed/
|
||||
-->
|
||||
<remote_servers incl="clickhouse_remote_servers" >
|
||||
<!-- Test only shard config for testing distributed storage -->
|
||||
<test_shard_localhost>
|
||||
<shard>
|
||||
<!-- Optional. Whether to write data to just one of the replicas. Default: false (write data to all replicas). -->
|
||||
<!-- <internal_replication>false</internal_replication> -->
|
||||
<!-- Optional. Shard weight when writing data. Default: 1. -->
|
||||
<!-- <weight>1</weight> -->
|
||||
<replica>
|
||||
<host>localhost</host>
|
||||
<port>9000</port>
|
||||
<!-- Optional. Priority of the replica for load_balancing. Default: 1 (less value has more priority). -->
|
||||
<!-- <priority>1</priority> -->
|
||||
</replica>
|
||||
</shard>
|
||||
</test_shard_localhost>
|
||||
<test_cluster_two_shards_localhost>
|
||||
<shard>
|
||||
<replica>
|
||||
<host>localhost</host>
|
||||
<port>9000</port>
|
||||
</replica>
|
||||
</shard>
|
||||
<shard>
|
||||
<replica>
|
||||
<host>localhost</host>
|
||||
<port>9000</port>
|
||||
</replica>
|
||||
</shard>
|
||||
</test_cluster_two_shards_localhost>
|
||||
<test_cluster_two_shards>
|
||||
<shard>
|
||||
<replica>
|
||||
<host>127.0.0.1</host>
|
||||
<port>9000</port>
|
||||
</replica>
|
||||
</shard>
|
||||
<shard>
|
||||
<replica>
|
||||
<host>127.0.0.2</host>
|
||||
<port>9000</port>
|
||||
</replica>
|
||||
</shard>
|
||||
</test_cluster_two_shards>
|
||||
<test_shard_localhost_secure>
|
||||
<shard>
|
||||
<replica>
|
||||
<host>localhost</host>
|
||||
<port>9440</port>
|
||||
<secure>1</secure>
|
||||
</replica>
|
||||
</shard>
|
||||
</test_shard_localhost_secure>
|
||||
<test_unavailable_shard>
|
||||
<shard>
|
||||
<replica>
|
||||
<host>localhost</host>
|
||||
<port>9000</port>
|
||||
</replica>
|
||||
</shard>
|
||||
<shard>
|
||||
<replica>
|
||||
<host>localhost</host>
|
||||
<port>1</port>
|
||||
</replica>
|
||||
</shard>
|
||||
</test_unavailable_shard>
|
||||
</remote_servers>
|
||||
|
||||
<!-- The list of hosts allowed to use in URL-related storage engines and table functions.
|
||||
If this section is not present in configuration, all hosts are allowed.
|
||||
-->
|
||||
<remote_url_allow_hosts>
|
||||
<!-- Host should be specified exactly as in URL. The name is checked before DNS resolution.
|
||||
Example: "yandex.ru", "yandex.ru." and "www.yandex.ru" are different hosts.
|
||||
If port is explicitly specified in URL, the host:port is checked as a whole.
|
||||
If host specified here without port, any port with this host allowed.
|
||||
"yandex.ru" -> "yandex.ru:443", "yandex.ru:80" etc. is allowed, but "yandex.ru:80" -> only "yandex.ru:80" is allowed.
|
||||
If the host is specified as IP address, it is checked as specified in URL. Example: "[2a02:6b8:a::a]".
|
||||
If there are redirects and support for redirects is enabled, every redirect (the Location field) is checked.
|
||||
-->
|
||||
|
||||
<!-- Regular expression can be specified. RE2 engine is used for regexps.
|
||||
Regexps are not aligned: don't forget to add ^ and $. Also don't forget to escape dot (.) metacharacter
|
||||
(forgetting to do so is a common source of error).
|
||||
-->
|
||||
</remote_url_allow_hosts>
|
||||
|
||||
<!-- If element has 'incl' attribute, then for it's value will be used corresponding substitution from another file.
|
||||
By default, path to file with substitutions is /etc/metrika.xml. It could be changed in config in 'include_from' element.
|
||||
Values for substitutions are specified in /yandex/name_of_substitution elements in that file.
|
||||
-->
|
||||
|
||||
<!-- ZooKeeper is used to store metadata about replicas, when using Replicated tables.
|
||||
Optional. If you don't use replicated tables, you could omit that.
|
||||
|
||||
See https://clickhouse.yandex/docs/en/table_engines/replication/
|
||||
-->
|
||||
|
||||
<zookeeper incl="zookeeper-servers" optional="true" />
|
||||
|
||||
<!-- Substitutions for parameters of replicated tables.
|
||||
Optional. If you don't use replicated tables, you could omit that.
|
||||
|
||||
See https://clickhouse.yandex/docs/en/table_engines/replication/#creating-replicated-tables
|
||||
-->
|
||||
<macros incl="macros" optional="true" />
|
||||
|
||||
|
||||
<!-- Reloading interval for embedded dictionaries, in seconds. Default: 3600. -->
|
||||
<builtin_dictionaries_reload_interval>3600</builtin_dictionaries_reload_interval>
|
||||
|
||||
|
||||
<!-- Maximum session timeout, in seconds. Default: 3600. -->
|
||||
<max_session_timeout>3600</max_session_timeout>
|
||||
|
||||
<!-- Default session timeout, in seconds. Default: 60. -->
|
||||
<default_session_timeout>60</default_session_timeout>
|
||||
|
||||
<!-- Sending data to Graphite for monitoring. Several sections can be defined. -->
|
||||
<!--
|
||||
interval - send every X second
|
||||
root_path - prefix for keys
|
||||
hostname_in_path - append hostname to root_path (default = true)
|
||||
metrics - send data from table system.metrics
|
||||
events - send data from table system.events
|
||||
asynchronous_metrics - send data from table system.asynchronous_metrics
|
||||
-->
|
||||
<!--
|
||||
<graphite>
|
||||
<host>localhost</host>
|
||||
<port>42000</port>
|
||||
<timeout>0.1</timeout>
|
||||
<interval>60</interval>
|
||||
<root_path>one_min</root_path>
|
||||
<hostname_in_path>true</hostname_in_path>
|
||||
|
||||
<metrics>true</metrics>
|
||||
<events>true</events>
|
||||
<events_cumulative>false</events_cumulative>
|
||||
<asynchronous_metrics>true</asynchronous_metrics>
|
||||
</graphite>
|
||||
<graphite>
|
||||
<host>localhost</host>
|
||||
<port>42000</port>
|
||||
<timeout>0.1</timeout>
|
||||
<interval>1</interval>
|
||||
<root_path>one_sec</root_path>
|
||||
|
||||
<metrics>true</metrics>
|
||||
<events>true</events>
|
||||
<events_cumulative>false</events_cumulative>
|
||||
<asynchronous_metrics>false</asynchronous_metrics>
|
||||
</graphite>
|
||||
-->
|
||||
|
||||
<!-- Serve endpoint fot Prometheus monitoring. -->
|
||||
<!--
|
||||
endpoint - mertics path (relative to root, statring with "/")
|
||||
port - port to setup server. If not defined or 0 than http_port used
|
||||
metrics - send data from table system.metrics
|
||||
events - send data from table system.events
|
||||
asynchronous_metrics - send data from table system.asynchronous_metrics
|
||||
status_info - send data from different component from CH, ex: Dictionaries status
|
||||
-->
|
||||
<!--
|
||||
<prometheus>
|
||||
<endpoint>/metrics</endpoint>
|
||||
<port>9363</port>
|
||||
|
||||
<metrics>true</metrics>
|
||||
<events>true</events>
|
||||
<asynchronous_metrics>true</asynchronous_metrics>
|
||||
<status_info>true</status_info>
|
||||
</prometheus>
|
||||
-->
|
||||
|
||||
<!-- Query log. Used only for queries with setting log_queries = 1. -->
|
||||
<query_log>
|
||||
<!-- What table to insert data. If table is not exist, it will be created.
|
||||
When query log structure is changed after system update,
|
||||
then old table will be renamed and new table will be created automatically.
|
||||
-->
|
||||
<database>system</database>
|
||||
<table>query_log</table>
|
||||
<!--
|
||||
PARTITION BY expr https://clickhouse.yandex/docs/en/table_engines/custom_partitioning_key/
|
||||
Example:
|
||||
event_date
|
||||
toMonday(event_date)
|
||||
toYYYYMM(event_date)
|
||||
toStartOfHour(event_time)
|
||||
-->
|
||||
<partition_by>toYYYYMM(event_date)</partition_by>
|
||||
|
||||
<!-- Instead of partition_by, you can provide full engine expression (starting with ENGINE = ) with parameters,
|
||||
Example: <engine>ENGINE = MergeTree PARTITION BY toYYYYMM(event_date) ORDER BY (event_date, event_time) SETTINGS index_granularity = 1024</engine>
|
||||
-->
|
||||
|
||||
<!-- Interval of flushing data. -->
|
||||
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
|
||||
</query_log>
|
||||
|
||||
<!-- Trace log. Stores stack traces collected by query profilers.
|
||||
See query_profiler_real_time_period_ns and query_profiler_cpu_time_period_ns settings. -->
|
||||
<trace_log>
|
||||
<database>system</database>
|
||||
<table>trace_log</table>
|
||||
|
||||
<partition_by>toYYYYMM(event_date)</partition_by>
|
||||
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
|
||||
</trace_log>
|
||||
|
||||
<!-- Query thread log. Has information about all threads participated in query execution.
|
||||
Used only for queries with setting log_query_threads = 1. -->
|
||||
<query_thread_log>
|
||||
<database>system</database>
|
||||
<table>query_thread_log</table>
|
||||
<partition_by>toYYYYMM(event_date)</partition_by>
|
||||
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
|
||||
</query_thread_log>
|
||||
|
||||
<!-- Uncomment if use part log.
|
||||
Part log contains information about all actions with parts in MergeTree tables (creation, deletion, merges, downloads).
|
||||
<part_log>
|
||||
<database>system</database>
|
||||
<table>part_log</table>
|
||||
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
|
||||
</part_log>
|
||||
-->
|
||||
|
||||
<!-- Uncomment to write text log into table.
|
||||
Text log contains all information from usual server log but stores it in structured and efficient way.
|
||||
The level of the messages that goes to the table can be limited (<level>), if not specified all messages will go to the table.
|
||||
<text_log>
|
||||
<database>system</database>
|
||||
<table>text_log</table>
|
||||
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
|
||||
<level></level>
|
||||
</text_log>
|
||||
-->
|
||||
|
||||
<!-- Metric log contains rows with current values of ProfileEvents, CurrentMetrics collected with "collect_interval_milliseconds" interval. -->
|
||||
<metric_log>
|
||||
<database>system</database>
|
||||
<table>metric_log</table>
|
||||
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
|
||||
<collect_interval_milliseconds>1000</collect_interval_milliseconds>
|
||||
</metric_log>
|
||||
|
||||
<!--
|
||||
Asynchronous metric log contains values of metrics from
|
||||
system.asynchronous_metrics.
|
||||
-->
|
||||
<asynchronous_metric_log>
|
||||
<database>system</database>
|
||||
<table>asynchronous_metric_log</table>
|
||||
<!--
|
||||
Asynchronous metrics are updated once a minute, so there is
|
||||
no need to flush more often.
|
||||
-->
|
||||
<flush_interval_milliseconds>60000</flush_interval_milliseconds>
|
||||
</asynchronous_metric_log>
|
||||
|
||||
<!-- Parameters for embedded dictionaries, used in Yandex.Metrica.
|
||||
See https://clickhouse.yandex/docs/en/dicts/internal_dicts/
|
||||
-->
|
||||
|
||||
<!-- Path to file with region hierarchy. -->
|
||||
<!-- <path_to_regions_hierarchy_file>/opt/geo/regions_hierarchy.txt</path_to_regions_hierarchy_file> -->
|
||||
|
||||
<!-- Path to directory with files containing names of regions -->
|
||||
<!-- <path_to_regions_names_files>/opt/geo/</path_to_regions_names_files> -->
|
||||
|
||||
|
||||
<!-- Configuration of external dictionaries. See:
|
||||
https://clickhouse.yandex/docs/en/dicts/external_dicts/
|
||||
-->
|
||||
<dictionaries_config>*_dictionary.xml</dictionaries_config>
|
||||
|
||||
<!-- Uncomment if you want data to be compressed 30-100% better.
|
||||
Don't do that if you just started using ClickHouse.
|
||||
-->
|
||||
<compression incl="clickhouse_compression">
|
||||
<!--
|
||||
<!- - Set of variants. Checked in order. Last matching case wins. If nothing matches, lz4 will be used. - ->
|
||||
<case>
|
||||
|
||||
<!- - Conditions. All must be satisfied. Some conditions may be omitted. - ->
|
||||
<min_part_size>10000000000</min_part_size> <!- - Min part size in bytes. - ->
|
||||
<min_part_size_ratio>0.01</min_part_size_ratio> <!- - Min size of part relative to whole table size. - ->
|
||||
|
||||
<!- - What compression method to use. - ->
|
||||
<method>zstd</method>
|
||||
</case>
|
||||
-->
|
||||
</compression>
|
||||
|
||||
<!-- Allow to execute distributed DDL queries (CREATE, DROP, ALTER, RENAME) on cluster.
|
||||
Works only if ZooKeeper is enabled. Comment it if such functionality isn't required. -->
|
||||
<distributed_ddl>
|
||||
<!-- Path in ZooKeeper to queue with DDL queries -->
|
||||
<path>/clickhouse/task_queue/ddl</path>
|
||||
|
||||
<!-- Settings from this profile will be used to execute DDL queries -->
|
||||
<!-- <profile>default</profile> -->
|
||||
</distributed_ddl>
|
||||
|
||||
<!-- Settings to fine tune MergeTree tables. See documentation in source code, in MergeTreeSettings.h -->
|
||||
<!--
|
||||
<merge_tree>
|
||||
<max_suspicious_broken_parts>5</max_suspicious_broken_parts>
|
||||
</merge_tree>
|
||||
-->
|
||||
|
||||
<!-- Protection from accidental DROP.
|
||||
If size of a MergeTree table is greater than max_table_size_to_drop (in bytes) than table could not be dropped with any DROP query.
|
||||
If you want do delete one table and don't want to change clickhouse-server config, you could create special file <clickhouse-path>/flags/force_drop_table and make DROP once.
|
||||
By default max_table_size_to_drop is 50GB; max_table_size_to_drop=0 allows to DROP any tables.
|
||||
The same for max_partition_size_to_drop.
|
||||
Uncomment to disable protection.
|
||||
-->
|
||||
<!-- <max_table_size_to_drop>0</max_table_size_to_drop> -->
|
||||
<!-- <max_partition_size_to_drop>0</max_partition_size_to_drop> -->
|
||||
|
||||
<!-- Example of parameters for GraphiteMergeTree table engine -->
|
||||
<graphite_rollup_example>
|
||||
<pattern>
|
||||
<regexp>click_cost</regexp>
|
||||
<function>any</function>
|
||||
<retention>
|
||||
<age>0</age>
|
||||
<precision>3600</precision>
|
||||
</retention>
|
||||
<retention>
|
||||
<age>86400</age>
|
||||
<precision>60</precision>
|
||||
</retention>
|
||||
</pattern>
|
||||
<default>
|
||||
<function>max</function>
|
||||
<retention>
|
||||
<age>0</age>
|
||||
<precision>60</precision>
|
||||
</retention>
|
||||
<retention>
|
||||
<age>3600</age>
|
||||
<precision>300</precision>
|
||||
</retention>
|
||||
<retention>
|
||||
<age>86400</age>
|
||||
<precision>3600</precision>
|
||||
</retention>
|
||||
</default>
|
||||
</graphite_rollup_example>
|
||||
|
||||
<!-- Directory in <clickhouse-path> containing schema files for various input formats.
|
||||
The directory will be created if it doesn't exist.
|
||||
-->
|
||||
<format_schema_path>/var/lib/clickhouse/format_schemas/</format_schema_path>
|
||||
|
||||
<!-- Uncomment to use query masking rules.
|
||||
name - name for the rule (optional)
|
||||
regexp - RE2 compatible regular expression (mandatory)
|
||||
replace - substitution string for sensitive data (optional, by default - six asterisks)
|
||||
<query_masking_rules>
|
||||
<rule>
|
||||
<name>hide SSN</name>
|
||||
<regexp>\b\d{3}-\d{2}-\d{4}\b</regexp>
|
||||
<replace>000-00-0000</replace>
|
||||
</rule>
|
||||
</query_masking_rules>
|
||||
-->
|
||||
|
||||
<!-- Uncomment to use custom http handlers.
|
||||
rules are checked from top to bottom, first match runs the handler
|
||||
url - to match request URL, you can use 'regex:' prefix to use regex match(optional)
|
||||
methods - to match request method, you can use commas to separate multiple method matches(optional)
|
||||
headers - to match request headers, match each child element(child element name is header name), you can use 'regex:' prefix to use regex match(optional)
|
||||
handler is request handler
|
||||
type - supported types: static, dynamic_query_handler, predefined_query_handler
|
||||
query - use with predefined_query_handler type, executes query when the handler is called
|
||||
query_param_name - use with dynamic_query_handler type, extracts and executes the value corresponding to the <query_param_name> value in HTTP request params
|
||||
status - use with static type, response status code
|
||||
content_type - use with static type, response content-type
|
||||
response_content - use with static type, Response content sent to client, when using the prefix 'file://' or 'config://', find the content from the file or configuration send to client.
|
||||
|
||||
<http_handlers>
|
||||
<rule>
|
||||
<url>/</url>
|
||||
<methods>POST,GET</methods>
|
||||
<headers><pragma>no-cache</pragma></headers>
|
||||
<handler>
|
||||
<type>dynamic_query_handler</type>
|
||||
<query_param_name>query</query_param_name>
|
||||
</handler>
|
||||
</rule>
|
||||
|
||||
<rule>
|
||||
<url>/predefined_query</url>
|
||||
<methods>POST,GET</methods>
|
||||
<handler>
|
||||
<type>predefined_query_handler</type>
|
||||
<query>SELECT * FROM system.settings</query>
|
||||
</handler>
|
||||
</rule>
|
||||
|
||||
<rule>
|
||||
<handler>
|
||||
<type>static</type>
|
||||
<status>200</status>
|
||||
<content_type>text/plain; charset=UTF-8</content_type>
|
||||
<response_content>config://http_server_default_response</response_content>
|
||||
</handler>
|
||||
</rule>
|
||||
</http_handlers>
|
||||
-->
|
||||
|
||||
<!-- Uncomment to disable ClickHouse internal DNS caching. -->
|
||||
<!-- <disable_internal_dns_cache>1</disable_internal_dns_cache> -->
|
||||
</yandex>
|
|
@ -0,0 +1,110 @@
|
|||
<?xml version="1.0"?>
|
||||
<yandex>
|
||||
<!-- Profiles of settings. -->
|
||||
<profiles>
|
||||
<!-- Default settings. -->
|
||||
<default>
|
||||
<!-- Maximum memory usage for processing single query, in bytes. -->
|
||||
<max_memory_usage>10000000000</max_memory_usage>
|
||||
|
||||
<!-- Use cache of uncompressed blocks of data. Meaningful only for processing many of very short queries. -->
|
||||
<use_uncompressed_cache>0</use_uncompressed_cache>
|
||||
|
||||
<!-- How to choose between replicas during distributed query processing.
|
||||
random - choose random replica from set of replicas with minimum number of errors
|
||||
nearest_hostname - from set of replicas with minimum number of errors, choose replica
|
||||
with minimum number of different symbols between replica's hostname and local hostname
|
||||
(Hamming distance).
|
||||
in_order - first live replica is chosen in specified order.
|
||||
first_or_random - if first replica one has higher number of errors, pick a random one from replicas with minimum number of errors.
|
||||
-->
|
||||
<load_balancing>random</load_balancing>
|
||||
</default>
|
||||
|
||||
<!-- Profile that allows only read queries. -->
|
||||
<readonly>
|
||||
<readonly>1</readonly>
|
||||
</readonly>
|
||||
</profiles>
|
||||
|
||||
<!-- Users and ACL. -->
|
||||
<users>
|
||||
<!-- If user name was not specified, 'default' user is used. -->
|
||||
<default>
|
||||
<!-- Password could be specified in plaintext or in SHA256 (in hex format).
|
||||
|
||||
If you want to specify password in plaintext (not recommended), place it in 'password' element.
|
||||
Example: <password>qwerty</password>.
|
||||
Password could be empty.
|
||||
|
||||
If you want to specify SHA256, place it in 'password_sha256_hex' element.
|
||||
Example: <password_sha256_hex>65e84be33532fb784c48129675f9eff3a682b27168c0ea744b2cf58ee02337c5</password_sha256_hex>
|
||||
Restrictions of SHA256: impossibility to connect to ClickHouse using MySQL JS client (as of July 2019).
|
||||
|
||||
If you want to specify double SHA1, place it in 'password_double_sha1_hex' element.
|
||||
Example: <password_double_sha1_hex>e395796d6546b1b65db9d665cd43f0e858dd4303</password_double_sha1_hex>
|
||||
|
||||
How to generate decent password:
|
||||
Execute: PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
|
||||
In first line will be password and in second - corresponding SHA256.
|
||||
|
||||
How to generate double SHA1:
|
||||
Execute: PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha1sum | tr -d '-' | xxd -r -p | sha1sum | tr -d '-'
|
||||
In first line will be password and in second - corresponding double SHA1.
|
||||
-->
|
||||
<password>public</password>
|
||||
|
||||
<!-- List of networks with open access.
|
||||
|
||||
To open access from everywhere, specify:
|
||||
<ip>::/0</ip>
|
||||
|
||||
To open access only from localhost, specify:
|
||||
<ip>::1</ip>
|
||||
<ip>127.0.0.1</ip>
|
||||
|
||||
Each element of list has one of the following forms:
|
||||
<ip> IP-address or network mask. Examples: 213.180.204.3 or 10.0.0.1/8 or 10.0.0.1/255.255.255.0
|
||||
2a02:6b8::3 or 2a02:6b8::3/64 or 2a02:6b8::3/ffff:ffff:ffff:ffff::.
|
||||
<host> Hostname. Example: server01.yandex.ru.
|
||||
To check access, DNS query is performed, and all received addresses compared to peer address.
|
||||
<host_regexp> Regular expression for host names. Example, ^server\d\d-\d\d-\d\.yandex\.ru$
|
||||
To check access, DNS PTR query is performed for peer address and then regexp is applied.
|
||||
Then, for result of PTR query, another DNS query is performed and all received addresses compared to peer address.
|
||||
Strongly recommended that regexp is ends with $
|
||||
All results of DNS requests are cached till server restart.
|
||||
-->
|
||||
<networks incl="networks" replace="replace">
|
||||
<ip>::/0</ip>
|
||||
</networks>
|
||||
|
||||
<!-- Settings profile for user. -->
|
||||
<profile>default</profile>
|
||||
|
||||
<!-- Quota for user. -->
|
||||
<quota>default</quota>
|
||||
|
||||
<!-- User can create other users and grant rights to them. -->
|
||||
<!-- <access_management>1</access_management> -->
|
||||
</default>
|
||||
</users>
|
||||
|
||||
<!-- Quotas. -->
|
||||
<quotas>
|
||||
<!-- Name of quota. -->
|
||||
<default>
|
||||
<!-- Limits for time interval. You could specify many intervals with different limits. -->
|
||||
<interval>
|
||||
<!-- Length of interval. -->
|
||||
<duration>3600</duration>
|
||||
|
||||
<!-- No limits. Just calculate resource usage for time interval. -->
|
||||
<queries>0</queries>
|
||||
<errors>0</errors>
|
||||
<result_rows>0</result_rows>
|
||||
<read_rows>0</read_rows>
|
||||
<execution_time>0</execution_time>
|
||||
</interval>
|
||||
</default>
|
||||
</quotas>
|
||||
</yandex>
|
|
@ -0,0 +1,16 @@
|
|||
version: '3.9'
|
||||
|
||||
services:
|
||||
clickhouse:
|
||||
container_name: clickhouse
|
||||
image: clickhouse/clickhouse-server:23.1.2.9-alpine
|
||||
restart: always
|
||||
volumes:
|
||||
- ./clickhouse/users.xml:/etc/clickhouse-server/users.xml
|
||||
- ./clickhouse/config.xml:/etc/clickhouse-server/config.d/config.xml
|
||||
expose:
|
||||
- "8123"
|
||||
ports:
|
||||
- "8123:8123"
|
||||
networks:
|
||||
- emqx_bridge
|
|
@ -0,0 +1,15 @@
|
|||
version: '3.9'
|
||||
|
||||
services:
|
||||
dynamodb-local:
|
||||
container_name: dynamo
|
||||
image: amazon/dynamodb-local:${DYNAMO_TAG}
|
||||
restart: always
|
||||
ports:
|
||||
- "8000:8000"
|
||||
environment:
|
||||
AWS_ACCESS_KEY_ID: root
|
||||
AWS_SECRET_ACCESS_KEY: public
|
||||
AWS_DEFAULT_REGION: us-west-2
|
||||
networks:
|
||||
- emqx_bridge
|
|
@ -13,10 +13,12 @@ services:
|
|||
networks:
|
||||
- emqx_bridge
|
||||
command:
|
||||
--bind-address "::"
|
||||
--character-set-server=utf8mb4
|
||||
--collation-server=utf8mb4_general_ci
|
||||
--explicit_defaults_for_timestamp=true
|
||||
--lower_case_table_names=1
|
||||
--max_allowed_packet=128M
|
||||
--skip-symbolic-links
|
||||
- --bind-address=0.0.0.0
|
||||
- --character-set-server=utf8mb4
|
||||
- --collation-server=utf8mb4_general_ci
|
||||
- --lower-case-table-names=1
|
||||
- --max-allowed-packet=128M
|
||||
# Severely limit maximum number of prepared statements the server must permit
|
||||
# so that we hit potential resource exhaustion earlier in tests.
|
||||
- --max-prepared-stmt-count=64
|
||||
- --skip-symbolic-links
|
||||
|
|
|
@ -23,9 +23,11 @@ services:
|
|||
- --port=3306
|
||||
- --character-set-server=utf8mb4
|
||||
- --collation-server=utf8mb4_general_ci
|
||||
- --explicit_defaults_for_timestamp=true
|
||||
- --lower_case_table_names=1
|
||||
- --max_allowed_packet=128M
|
||||
- --lower-case-table-names=1
|
||||
- --max-allowed-packet=128M
|
||||
# Severely limit maximum number of prepared statements the server must permit
|
||||
# so that we hit potential resource exhaustion earlier in tests.
|
||||
- --max-prepared-stmt-count=64
|
||||
- --ssl-ca=/etc/certs/ca-cert.pem
|
||||
- --ssl-cert=/etc/certs/server-cert.pem
|
||||
- --ssl-key=/etc/certs/server-key.pem
|
||||
|
|
|
@ -18,6 +18,7 @@ services:
|
|||
- 15432:5432
|
||||
- 15433:5433
|
||||
- 16041:6041
|
||||
- 18000:8000
|
||||
command:
|
||||
- "-host=0.0.0.0"
|
||||
- "-config=/config/toxiproxy.json"
|
||||
|
|
|
@ -47,5 +47,11 @@
|
|||
"listen": "0.0.0.0:6041",
|
||||
"upstream": "tdengine:6041",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "dynamo",
|
||||
"listen": "0.0.0.0:8000",
|
||||
"upstream": "dynamo:8000",
|
||||
"enabled": true
|
||||
}
|
||||
]
|
||||
|
|
|
@ -23,9 +23,9 @@ on:
|
|||
|
||||
jobs:
|
||||
prepare:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-22.04
|
||||
# prepare source with any OTP version, no need for a matrix
|
||||
container: "ghcr.io/emqx/emqx-builder/5.0-28:1.13.4-24.3.4.2-2-ubuntu20.04"
|
||||
container: "ghcr.io/emqx/emqx-builder/5.0-29:1.13.4-24.3.4.2-2-ubuntu22.04"
|
||||
|
||||
outputs:
|
||||
PROFILE: ${{ steps.get_profile.outputs.PROFILE }}
|
||||
|
@ -105,7 +105,7 @@ jobs:
|
|||
path: source.zip
|
||||
|
||||
docker:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-22.04
|
||||
needs: prepare
|
||||
|
||||
strategy:
|
||||
|
@ -121,7 +121,7 @@ jobs:
|
|||
# NOTE: 'otp' and 'elixir' are to configure emqx-builder image
|
||||
# only support latest otp and elixir, not a matrix
|
||||
builder:
|
||||
- 5.0-28 # update to latest
|
||||
- 5.0-29 # update to latest
|
||||
otp:
|
||||
- 24.3.4.2-2 # switch to 25 once ready to release 5.1
|
||||
elixir:
|
||||
|
|
|
@ -22,8 +22,9 @@ on:
|
|||
|
||||
jobs:
|
||||
prepare:
|
||||
runs-on: ubuntu-20.04
|
||||
container: ghcr.io/emqx/emqx-builder/5.0-28:1.13.4-24.3.4.2-2-ubuntu20.04
|
||||
runs-on: ubuntu-22.04
|
||||
if: (github.repository_owner == 'emqx' && github.event_name == 'schedule') || github.event_name != 'schedule'
|
||||
container: ghcr.io/emqx/emqx-builder/5.0-29:1.13.4-24.3.4.2-2-ubuntu22.04
|
||||
outputs:
|
||||
BUILD_PROFILE: ${{ steps.get_profile.outputs.BUILD_PROFILE }}
|
||||
IS_EXACT_TAG: ${{ steps.get_profile.outputs.IS_EXACT_TAG }}
|
||||
|
@ -153,6 +154,7 @@ jobs:
|
|||
- 24.3.4.2-2
|
||||
os:
|
||||
- macos-11
|
||||
- macos-12
|
||||
- macos-12-arm64
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
|
@ -211,28 +213,35 @@ jobs:
|
|||
- ubuntu18.04
|
||||
- debian11
|
||||
- debian10
|
||||
- raspbian10
|
||||
- raspbian9
|
||||
- el9
|
||||
- el8
|
||||
- el7
|
||||
- amzn2
|
||||
build_machine:
|
||||
- aws-arm64
|
||||
- ubuntu-20.04
|
||||
- ubuntu-22.04
|
||||
builder:
|
||||
- 5.0-28
|
||||
- 5.0-29
|
||||
elixir:
|
||||
- 1.13.4
|
||||
exclude:
|
||||
- arch: arm64
|
||||
build_machine: ubuntu-20.04
|
||||
build_machine: ubuntu-22.04
|
||||
- arch: amd64
|
||||
build_machine: aws-arm64
|
||||
- arch: amd64
|
||||
os: raspbian9
|
||||
- arch: amd64
|
||||
os: raspbian10
|
||||
include:
|
||||
- profile: emqx
|
||||
otp: 25.1.2-2
|
||||
arch: amd64
|
||||
os: ubuntu22.04
|
||||
build_machine: ubuntu-22.04
|
||||
builder: 5.0-28
|
||||
builder: 5.0-29
|
||||
elixir: 1.13.4
|
||||
release_with: elixir
|
||||
- profile: emqx
|
||||
|
@ -240,7 +249,7 @@ jobs:
|
|||
arch: amd64
|
||||
os: amzn2
|
||||
build_machine: ubuntu-22.04
|
||||
builder: 5.0-28
|
||||
builder: 5.0-29
|
||||
elixir: 1.13.4
|
||||
release_with: elixir
|
||||
|
||||
|
@ -306,7 +315,7 @@ jobs:
|
|||
{"text": "Scheduled run of ${{ github.workflow }}@${{ matrix.os }} failed: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}
|
||||
|
||||
publish_artifacts:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-22.04
|
||||
needs: [prepare, mac, linux]
|
||||
if: needs.prepare.outputs.IS_EXACT_TAG && github.event_name != 'schedule'
|
||||
strategy:
|
||||
|
@ -369,15 +378,19 @@ jobs:
|
|||
push "debian/buster" "packages/$PROFILE/$PROFILE-$VERSION-debian10-arm64.deb"
|
||||
push "debian/bullseye" "packages/$PROFILE/$PROFILE-$VERSION-debian11-amd64.deb"
|
||||
push "debian/bullseye" "packages/$PROFILE/$PROFILE-$VERSION-debian11-arm64.deb"
|
||||
push "raspbian/stretch" "packages/$PROFILE/$PROFILE-$VERSION-raspbian9-arm64.deb"
|
||||
push "raspbian/buster" "packages/$PROFILE/$PROFILE-$VERSION-raspbian10-arm64.deb"
|
||||
push "ubuntu/bionic" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu18.04-amd64.deb"
|
||||
push "ubuntu/bionic" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu18.04-arm64.deb"
|
||||
push "ubuntu/focal" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu20.04-amd64.deb"
|
||||
push "ubuntu/focal" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu20.04-arm64.deb"
|
||||
push "ubuntu/jammy" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu22.04-amd64.deb"
|
||||
push "ubuntu/jammy" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu22.04-arm64.deb"
|
||||
push "el/6" "packages/$PROFILE/$PROFILE-$VERSION-amzn2-amd64.rpm"
|
||||
push "el/6" "packages/$PROFILE/$PROFILE-$VERSION-amzn2-arm64.rpm"
|
||||
push "el/7" "packages/$PROFILE/$PROFILE-$VERSION-el7-amd64.rpm"
|
||||
push "el/7" "packages/$PROFILE/$PROFILE-$VERSION-el7-arm64.rpm"
|
||||
push "el/8" "packages/$PROFILE/$PROFILE-$VERSION-el8-amd64.rpm"
|
||||
push "el/8" "packages/$PROFILE/$PROFILE-$VERSION-el8-arm64.rpm"
|
||||
push "el/6" "packages/$PROFILE/$PROFILE-$VERSION-amzn2-amd64.rpm"
|
||||
push "el/6" "packages/$PROFILE/$PROFILE-$VERSION-amzn2-arm64.rpm"
|
||||
push "el/9" "packages/$PROFILE/$PROFILE-$VERSION-el9-amd64.rpm"
|
||||
push "el/9" "packages/$PROFILE/$PROFILE-$VERSION-el9-arm64.rpm"
|
||||
|
|
|
@ -30,15 +30,14 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
profile:
|
||||
- ["emqx", "24.3.4.2-2", "el7"]
|
||||
- ["emqx", "24.3.4.2-2", "ubuntu20.04"]
|
||||
- ["emqx", "25.1.2-2", "ubuntu22.04"]
|
||||
- ["emqx-enterprise", "24.3.4.2-2", "ubuntu20.04"]
|
||||
- ["emqx-enterprise", "25.1.2-2", "ubuntu22.04"]
|
||||
- ["emqx", "24.3.4.2-2", "el7", "erlang"]
|
||||
- ["emqx", "25.1.2-2", "ubuntu22.04", "elixir"]
|
||||
- ["emqx-enterprise", "24.3.4.2-2", "amzn2", "erlang"]
|
||||
- ["emqx-enterprise", "25.1.2-2", "ubuntu20.04", "erlang"]
|
||||
builder:
|
||||
- 5.0-28
|
||||
- 5.0-29
|
||||
elixir:
|
||||
- 1.13.4
|
||||
- '1.13.4'
|
||||
|
||||
container: "ghcr.io/emqx/emqx-builder/${{ matrix.builder }}:${{ matrix.elixir }}-${{ matrix.profile[1] }}-${{ matrix.profile[2] }}"
|
||||
|
||||
|
@ -55,18 +54,22 @@ jobs:
|
|||
run: |
|
||||
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||
- name: build and test tgz package
|
||||
if: matrix.profile[3] == 'erlang'
|
||||
run: |
|
||||
make ${EMQX_NAME}-tgz
|
||||
./scripts/pkg-tests.sh ${EMQX_NAME}-tgz
|
||||
- name: build and test deb/rpm packages
|
||||
if: matrix.profile[3] == 'erlang'
|
||||
run: |
|
||||
make ${EMQX_NAME}-pkg
|
||||
./scripts/pkg-tests.sh ${EMQX_NAME}-pkg
|
||||
- name: build and test tgz package (Elixir)
|
||||
if: matrix.profile[3] == 'elixir'
|
||||
run: |
|
||||
make ${EMQX_NAME}-elixir-tgz
|
||||
./scripts/pkg-tests.sh ${EMQX_NAME}-elixir-tgz
|
||||
- name: build and test deb/rpm packages (Elixir)
|
||||
if: matrix.profile[3] == 'elixir'
|
||||
run: |
|
||||
make ${EMQX_NAME}-elixir-pkg
|
||||
./scripts/pkg-tests.sh ${EMQX_NAME}-elixir-pkg
|
||||
|
@ -79,7 +82,7 @@ jobs:
|
|||
name: "${{ matrix.profile[0] }}_schema_dump"
|
||||
path: |
|
||||
scripts/spellcheck
|
||||
_build/${{ matrix.profile[0] }}/lib/emqx_dashboard/priv/www/static/schema.json
|
||||
_build/docgen/${{ matrix.profile[0] }}/schema.json
|
||||
|
||||
windows:
|
||||
runs-on: windows-2019
|
||||
|
@ -215,4 +218,4 @@ jobs:
|
|||
path: /tmp/
|
||||
- name: Run spellcheck
|
||||
run: |
|
||||
bash /tmp/scripts/spellcheck/spellcheck.sh /tmp/_build/${{ matrix.profile }}/lib/emqx_dashboard/priv/www/static/schema.json
|
||||
bash /tmp/scripts/spellcheck/spellcheck.sh /tmp/_build/docgen/${{ matrix.profile }}/schema.json
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
name: Check Rebar Dependencies
|
||||
|
||||
on: [pull_request, push]
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
check_deps_integrity:
|
||||
runs-on: ubuntu-20.04
|
||||
container: ghcr.io/emqx/emqx-builder/5.0-28:1.13.4-25.1.2-2-ubuntu20.04
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/emqx/emqx-builder/5.0-29:1.13.4-25.1.2-2-ubuntu22.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
|
|
@ -4,8 +4,8 @@ on: [pull_request]
|
|||
|
||||
jobs:
|
||||
code_style_check:
|
||||
runs-on: ubuntu-20.04
|
||||
container: "ghcr.io/emqx/emqx-builder/5.0-28:1.13.4-25.1.2-2-ubuntu20.04"
|
||||
runs-on: ubuntu-22.04
|
||||
container: "ghcr.io/emqx/emqx-builder/5.0-29:1.13.4-25.1.2-2-ubuntu22.04"
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
name: Check Elixir Release Applications
|
||||
|
||||
on: [pull_request, push]
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
elixir_apps_check:
|
||||
runs-on: ubuntu-latest
|
||||
# just use the latest builder
|
||||
container: "ghcr.io/emqx/emqx-builder/5.0-28:1.13.4-25.1.2-2-ubuntu20.04"
|
||||
container: "ghcr.io/emqx/emqx-builder/5.0-29:1.13.4-25.1.2-2-ubuntu22.04"
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
name: Elixir Dependency Version Check
|
||||
|
||||
on: [pull_request, push]
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
elixir_deps_check:
|
||||
runs-on: ubuntu-20.04
|
||||
container: ghcr.io/emqx/emqx-builder/5.0-28:1.13.4-25.1.2-2-ubuntu20.04
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/emqx/emqx-builder/5.0-29:1.13.4-25.1.2-2-ubuntu22.04
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
|
|
|
@ -17,7 +17,7 @@ jobs:
|
|||
profile:
|
||||
- emqx
|
||||
- emqx-enterprise
|
||||
container: ghcr.io/emqx/emqx-builder/5.0-28:1.13.4-25.1.2-2-ubuntu20.04
|
||||
container: ghcr.io/emqx/emqx-builder/5.0-29:1.13.4-25.1.2-2-ubuntu22.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
|
|
@ -12,7 +12,7 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
builder:
|
||||
- 5.0-28
|
||||
- 5.0-29
|
||||
otp:
|
||||
- 24.3.4.2-2
|
||||
- 25.1.2-2
|
||||
|
@ -22,16 +22,16 @@ jobs:
|
|||
elixir:
|
||||
- 1.13.4
|
||||
os:
|
||||
- ubuntu20.04
|
||||
- ubuntu22.04
|
||||
arch:
|
||||
- amd64
|
||||
runs-on:
|
||||
- aws-amd64
|
||||
- ubuntu-20.04
|
||||
- ubuntu-22.04
|
||||
use-self-hosted:
|
||||
- ${{ github.repository_owner == 'emqx' }}
|
||||
exclude:
|
||||
- runs-on: ubuntu-20.04
|
||||
- runs-on: ubuntu-22.04
|
||||
use-self-hosted: true
|
||||
- runs-on: aws-amd64
|
||||
use-self-hosted: false
|
||||
|
|
|
@ -7,16 +7,17 @@ concurrency:
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- '**'
|
||||
- master
|
||||
- 'ci/**'
|
||||
tags:
|
||||
- v*
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
prepare:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
# prepare source with any OTP version, no need for a matrix
|
||||
container: ghcr.io/emqx/emqx-builder/5.0-28:1.13.4-24.3.4.2-2-debian11
|
||||
container: ghcr.io/emqx/emqx-builder/5.0-29:1.13.4-24.3.4.2-2-debian11
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
@ -33,7 +34,7 @@ jobs:
|
|||
path: source.zip
|
||||
|
||||
docker_test:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-22.04
|
||||
needs: prepare
|
||||
|
||||
strategy:
|
||||
|
@ -49,7 +50,7 @@ jobs:
|
|||
os:
|
||||
- ["debian11", "debian:11-slim"]
|
||||
builder:
|
||||
- 5.0-28
|
||||
- 5.0-29
|
||||
otp:
|
||||
- 24.3.4.2-2
|
||||
elixir:
|
||||
|
@ -107,7 +108,7 @@ jobs:
|
|||
docker exec node1.emqx.io node_dump
|
||||
|
||||
helm_test:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-22.04
|
||||
needs: prepare
|
||||
|
||||
strategy:
|
||||
|
@ -122,7 +123,7 @@ jobs:
|
|||
os:
|
||||
- ["debian11", "debian:11-slim"]
|
||||
builder:
|
||||
- 5.0-28
|
||||
- 5.0-29
|
||||
otp:
|
||||
- 24.3.4.2-2
|
||||
elixir:
|
||||
|
|
|
@ -14,8 +14,8 @@ concurrency:
|
|||
|
||||
jobs:
|
||||
relup_test_plan:
|
||||
runs-on: ubuntu-20.04
|
||||
container: "ghcr.io/emqx/emqx-builder/5.0-28:1.13.4-24.3.4.2-2-ubuntu20.04"
|
||||
runs-on: ubuntu-22.04
|
||||
container: "ghcr.io/emqx/emqx-builder/5.0-29:1.13.4-24.3.4.2-2-ubuntu22.04"
|
||||
outputs:
|
||||
CUR_EE_VSN: ${{ steps.find-versions.outputs.CUR_EE_VSN }}
|
||||
OLD_VERSIONS: ${{ steps.find-versions.outputs.OLD_VERSIONS }}
|
||||
|
|
|
@ -7,225 +7,226 @@ concurrency:
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- '**'
|
||||
- master
|
||||
- 'ci/**'
|
||||
tags:
|
||||
- v*
|
||||
- e*
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build-matrix:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
prepare: ${{ steps.matrix.outputs.prepare }}
|
||||
host: ${{ steps.matrix.outputs.host }}
|
||||
docker: ${{ steps.matrix.outputs.docker }}
|
||||
runs-on: ${{ steps.runner.outputs.runs-on }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build matrix
|
||||
id: matrix
|
||||
run: |
|
||||
APPS="$(./scripts/find-apps.sh --ci)"
|
||||
MATRIX="$(echo "${APPS}" | jq -c '
|
||||
[
|
||||
(.[] | select(.profile == "emqx") | . + {
|
||||
builder: "5.0-28",
|
||||
otp: "25.1.2-2",
|
||||
elixir: "1.13.4"
|
||||
}),
|
||||
(.[] | select(.profile == "emqx-enterprise") | . + {
|
||||
builder: "5.0-28",
|
||||
otp: ["24.3.4.2-2", "25.1.2-2"][],
|
||||
elixir: "1.13.4"
|
||||
})
|
||||
]
|
||||
')"
|
||||
echo "${MATRIX}" | jq
|
||||
MATRIX_PREPARE="$(echo "${MATRIX}" | jq -c 'map({profile, builder, otp, elixir}) | unique')"
|
||||
MATRIX_HOST="$(echo "${MATRIX}" | jq -c 'map(select(.runner == "host"))')"
|
||||
MATRIX_DOCKER="$(echo "${MATRIX}" | jq -c 'map(select(.runner == "docker"))')"
|
||||
echo "prepare=${MATRIX_PREPARE}" | tee -a $GITHUB_OUTPUT
|
||||
echo "host=${MATRIX_HOST}" | tee -a $GITHUB_OUTPUT
|
||||
echo "docker=${MATRIX_DOCKER}" | tee -a $GITHUB_OUTPUT
|
||||
- name: Choose runner host
|
||||
id: runner
|
||||
run: |
|
||||
RUNS_ON="ubuntu-20.04"
|
||||
${{ github.repository_owner == 'emqx' }} && RUNS_ON="aws-amd64"
|
||||
echo "runs-on=${RUNS_ON}" | tee -a $GITHUB_OUTPUT
|
||||
build-matrix:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
prepare: ${{ steps.matrix.outputs.prepare }}
|
||||
host: ${{ steps.matrix.outputs.host }}
|
||||
docker: ${{ steps.matrix.outputs.docker }}
|
||||
runs-on: ${{ steps.runner.outputs.runs-on }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build matrix
|
||||
id: matrix
|
||||
run: |
|
||||
APPS="$(./scripts/find-apps.sh --ci)"
|
||||
MATRIX="$(echo "${APPS}" | jq -c '
|
||||
[
|
||||
(.[] | select(.profile == "emqx") | . + {
|
||||
builder: "5.0-29",
|
||||
otp: "25.1.2-2",
|
||||
elixir: "1.13.4"
|
||||
}),
|
||||
(.[] | select(.profile == "emqx-enterprise") | . + {
|
||||
builder: "5.0-29",
|
||||
otp: ["24.3.4.2-2", "25.1.2-2"][],
|
||||
elixir: "1.13.4"
|
||||
})
|
||||
]
|
||||
')"
|
||||
echo "${MATRIX}" | jq
|
||||
MATRIX_PREPARE="$(echo "${MATRIX}" | jq -c 'map({profile, builder, otp, elixir}) | unique')"
|
||||
MATRIX_HOST="$(echo "${MATRIX}" | jq -c 'map(select(.runner == "host"))')"
|
||||
MATRIX_DOCKER="$(echo "${MATRIX}" | jq -c 'map(select(.runner == "docker"))')"
|
||||
echo "prepare=${MATRIX_PREPARE}" | tee -a $GITHUB_OUTPUT
|
||||
echo "host=${MATRIX_HOST}" | tee -a $GITHUB_OUTPUT
|
||||
echo "docker=${MATRIX_DOCKER}" | tee -a $GITHUB_OUTPUT
|
||||
- name: Choose runner host
|
||||
id: runner
|
||||
run: |
|
||||
RUNS_ON="ubuntu-22.04"
|
||||
${{ github.repository_owner == 'emqx' }} && RUNS_ON="aws-amd64"
|
||||
echo "runs-on=${RUNS_ON}" | tee -a $GITHUB_OUTPUT
|
||||
|
||||
prepare:
|
||||
runs-on: ${{ needs.build-matrix.outputs.runs-on }}
|
||||
needs: [build-matrix]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include: ${{ fromJson(needs.build-matrix.outputs.prepare) }}
|
||||
container: "ghcr.io/emqx/emqx-builder/${{ matrix.builder }}:${{ matrix.elixir }}-${{ matrix.otp }}-ubuntu20.04"
|
||||
steps:
|
||||
- uses: AutoModality/action-clean@v1
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
path: source
|
||||
- name: get_all_deps
|
||||
working-directory: source
|
||||
env:
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
#DIAGNOSTIC: 1
|
||||
run: |
|
||||
make ensure-rebar3
|
||||
# fetch all deps and compile
|
||||
make ${{ matrix.profile }}
|
||||
make static_checks
|
||||
make test-compile
|
||||
cd ..
|
||||
zip -ryq source.zip source/* source/.[^.]*
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: source-${{ matrix.profile }}-${{ matrix.otp }}
|
||||
path: source.zip
|
||||
prepare:
|
||||
runs-on: ${{ needs.build-matrix.outputs.runs-on }}
|
||||
needs: [build-matrix]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include: ${{ fromJson(needs.build-matrix.outputs.prepare) }}
|
||||
container: "ghcr.io/emqx/emqx-builder/${{ matrix.builder }}:${{ matrix.elixir }}-${{ matrix.otp }}-ubuntu20.04"
|
||||
steps:
|
||||
- uses: AutoModality/action-clean@v1
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
path: source
|
||||
- name: get_all_deps
|
||||
working-directory: source
|
||||
env:
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
#DIAGNOSTIC: 1
|
||||
run: |
|
||||
make ensure-rebar3
|
||||
# fetch all deps and compile
|
||||
make ${{ matrix.profile }}
|
||||
make static_checks
|
||||
make test-compile
|
||||
cd ..
|
||||
zip -ryq source.zip source/* source/.[^.]*
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: source-${{ matrix.profile }}-${{ matrix.otp }}
|
||||
path: source.zip
|
||||
|
||||
eunit_and_proper:
|
||||
needs:
|
||||
- build-matrix
|
||||
- prepare
|
||||
runs-on: ${{ needs.build-matrix.outputs.runs-on }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include: ${{ fromJson(needs.build-matrix.outputs.prepare) }}
|
||||
eunit_and_proper:
|
||||
needs:
|
||||
- build-matrix
|
||||
- prepare
|
||||
runs-on: ${{ needs.build-matrix.outputs.runs-on }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include: ${{ fromJson(needs.build-matrix.outputs.prepare) }}
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
container: "ghcr.io/emqx/emqx-builder/${{ matrix.builder }}:${{ matrix.elixir }}-${{ matrix.otp }}-ubuntu20.04"
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
container: "ghcr.io/emqx/emqx-builder/${{ matrix.builder }}:${{ matrix.elixir }}-${{ matrix.otp }}-ubuntu20.04"
|
||||
|
||||
steps:
|
||||
- uses: AutoModality/action-clean@v1
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: source-${{ matrix.profile }}-${{ matrix.otp }}
|
||||
path: .
|
||||
- name: unzip source code
|
||||
run: unzip -o -q source.zip
|
||||
# produces eunit.coverdata
|
||||
- name: eunit
|
||||
env:
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
CT_COVER_EXPORT_PREFIX: ${{ matrix.profile }}-${{ matrix.otp }}
|
||||
working-directory: source
|
||||
run: make eunit
|
||||
steps:
|
||||
- uses: AutoModality/action-clean@v1
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: source-${{ matrix.profile }}-${{ matrix.otp }}
|
||||
path: .
|
||||
- name: unzip source code
|
||||
run: unzip -o -q source.zip
|
||||
# produces eunit.coverdata
|
||||
- name: eunit
|
||||
env:
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
CT_COVER_EXPORT_PREFIX: ${{ matrix.profile }}-${{ matrix.otp }}
|
||||
working-directory: source
|
||||
run: make eunit
|
||||
|
||||
# produces proper.coverdata
|
||||
- name: proper
|
||||
env:
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
CT_COVER_EXPORT_PREFIX: ${{ matrix.profile }}-${{ matrix.otp }}
|
||||
working-directory: source
|
||||
run: make proper
|
||||
# produces proper.coverdata
|
||||
- name: proper
|
||||
env:
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
CT_COVER_EXPORT_PREFIX: ${{ matrix.profile }}-${{ matrix.otp }}
|
||||
working-directory: source
|
||||
run: make proper
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: coverdata
|
||||
path: source/_build/test/cover
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: coverdata
|
||||
path: source/_build/test/cover
|
||||
|
||||
ct_docker:
|
||||
needs:
|
||||
- build-matrix
|
||||
- prepare
|
||||
runs-on: ${{ needs.build-matrix.outputs.runs-on }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include: ${{ fromJson(needs.build-matrix.outputs.docker) }}
|
||||
ct_docker:
|
||||
needs:
|
||||
- build-matrix
|
||||
- prepare
|
||||
runs-on: ${{ needs.build-matrix.outputs.runs-on }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include: ${{ fromJson(needs.build-matrix.outputs.docker) }}
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
steps:
|
||||
- uses: AutoModality/action-clean@v1
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: source-${{ matrix.profile }}-${{ matrix.otp }}
|
||||
path: .
|
||||
- name: unzip source code
|
||||
run: unzip -q source.zip
|
||||
- name: run tests
|
||||
working-directory: source
|
||||
env:
|
||||
DOCKER_CT_RUNNER_IMAGE: "ghcr.io/emqx/emqx-builder/${{ matrix.builder }}:${{ matrix.elixir }}-${{ matrix.otp }}-ubuntu20.04"
|
||||
MONGO_TAG: "5"
|
||||
MYSQL_TAG: "8"
|
||||
PGSQL_TAG: "13"
|
||||
REDIS_TAG: "7.0"
|
||||
INFLUXDB_TAG: "2.5.0"
|
||||
TDENGINE_TAG: "3.0.2.4"
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
CT_COVER_EXPORT_PREFIX: ${{ matrix.profile }}-${{ matrix.otp }}
|
||||
run: ./scripts/ct/run.sh --ci --app ${{ matrix.app }}
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: coverdata
|
||||
path: source/_build/test/cover
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: failure()
|
||||
with:
|
||||
name: logs-${{ matrix.profile }}-${{ matrix.prefix }}-${{ matrix.otp }}
|
||||
path: source/_build/test/logs
|
||||
steps:
|
||||
- uses: AutoModality/action-clean@v1
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: source-${{ matrix.profile }}-${{ matrix.otp }}
|
||||
path: .
|
||||
- name: unzip source code
|
||||
run: unzip -q source.zip
|
||||
- name: run tests
|
||||
working-directory: source
|
||||
env:
|
||||
DOCKER_CT_RUNNER_IMAGE: "ghcr.io/emqx/emqx-builder/${{ matrix.builder }}:${{ matrix.elixir }}-${{ matrix.otp }}-ubuntu20.04"
|
||||
MONGO_TAG: "5"
|
||||
MYSQL_TAG: "8"
|
||||
PGSQL_TAG: "13"
|
||||
REDIS_TAG: "7.0"
|
||||
INFLUXDB_TAG: "2.5.0"
|
||||
TDENGINE_TAG: "3.0.2.4"
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
CT_COVER_EXPORT_PREFIX: ${{ matrix.profile }}-${{ matrix.otp }}
|
||||
run: ./scripts/ct/run.sh --ci --app ${{ matrix.app }}
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: coverdata
|
||||
path: source/_build/test/cover
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: failure()
|
||||
with:
|
||||
name: logs-${{ matrix.profile }}-${{ matrix.prefix }}-${{ matrix.otp }}
|
||||
path: source/_build/test/logs
|
||||
|
||||
ct:
|
||||
needs:
|
||||
- build-matrix
|
||||
- prepare
|
||||
runs-on: ${{ needs.build-matrix.outputs.runs-on }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include: ${{ fromJson(needs.build-matrix.outputs.host) }}
|
||||
ct:
|
||||
needs:
|
||||
- build-matrix
|
||||
- prepare
|
||||
runs-on: ${{ needs.build-matrix.outputs.runs-on }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include: ${{ fromJson(needs.build-matrix.outputs.host) }}
|
||||
|
||||
container: "ghcr.io/emqx/emqx-builder/${{ matrix.builder }}:${{ matrix.elixir }}-${{ matrix.otp }}-ubuntu20.04"
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
container: "ghcr.io/emqx/emqx-builder/${{ matrix.builder }}:${{ matrix.elixir }}-${{ matrix.otp }}-ubuntu20.04"
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
steps:
|
||||
- uses: AutoModality/action-clean@v1
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: source-${{ matrix.profile }}-${{ matrix.otp }}
|
||||
path: .
|
||||
- name: unzip source code
|
||||
run: unzip -q source.zip
|
||||
steps:
|
||||
- uses: AutoModality/action-clean@v1
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: source-${{ matrix.profile }}-${{ matrix.otp }}
|
||||
path: .
|
||||
- name: unzip source code
|
||||
run: unzip -q source.zip
|
||||
|
||||
# produces $PROFILE-<app-name>.coverdata
|
||||
- name: run common test
|
||||
working-directory: source
|
||||
env:
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
CT_COVER_EXPORT_PREFIX: ${{ matrix.profile }}-${{ matrix.otp }}
|
||||
run: |
|
||||
make "${{ matrix.app }}-ct"
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: coverdata
|
||||
path: source/_build/test/cover
|
||||
if-no-files-found: warn # do not fail if no coverdata found
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: failure()
|
||||
with:
|
||||
name: logs-${{ matrix.profile }}-${{ matrix.prefix }}-${{ matrix.otp }}
|
||||
path: source/_build/test/logs
|
||||
# produces $PROFILE-<app-name>.coverdata
|
||||
- name: run common test
|
||||
working-directory: source
|
||||
env:
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
CT_COVER_EXPORT_PREFIX: ${{ matrix.profile }}-${{ matrix.otp }}
|
||||
run: |
|
||||
make "${{ matrix.app }}-ct"
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: coverdata
|
||||
path: source/_build/test/cover
|
||||
if-no-files-found: warn # do not fail if no coverdata found
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: failure()
|
||||
with:
|
||||
name: logs-${{ matrix.profile }}-${{ matrix.prefix }}-${{ matrix.otp }}
|
||||
path: source/_build/test/logs
|
||||
|
||||
make_cover:
|
||||
needs:
|
||||
- eunit_and_proper
|
||||
- ct
|
||||
- ct_docker
|
||||
runs-on: ubuntu-20.04
|
||||
container: "ghcr.io/emqx/emqx-builder/5.0-28:1.13.4-24.3.4.2-2-ubuntu20.04"
|
||||
steps:
|
||||
make_cover:
|
||||
needs:
|
||||
- eunit_and_proper
|
||||
- ct
|
||||
- ct_docker
|
||||
runs-on: ubuntu-22.04
|
||||
container: "ghcr.io/emqx/emqx-builder/5.0-29:1.13.4-24.3.4.2-2-ubuntu22.04"
|
||||
steps:
|
||||
- uses: AutoModality/action-clean@v1
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
|
@ -258,15 +259,15 @@ jobs:
|
|||
if: failure()
|
||||
run: cat rebar3.crashdump
|
||||
|
||||
# do this in a separate job
|
||||
upload_coverdata:
|
||||
needs: make_cover
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Coveralls Finished
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
curl -v -k https://coveralls.io/webhook \
|
||||
--header "Content-Type: application/json" \
|
||||
--data "{\"repo_name\":\"$GITHUB_REPOSITORY\",\"repo_token\":\"$GITHUB_TOKEN\",\"payload\":{\"build_num\":$GITHUB_RUN_ID,\"status\":\"done\"}}" || true
|
||||
# do this in a separate job
|
||||
upload_coverdata:
|
||||
needs: make_cover
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Coveralls Finished
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
curl -v -k https://coveralls.io/webhook \
|
||||
--header "Content-Type: application/json" \
|
||||
--data "{\"repo_name\":\"$GITHUB_REPOSITORY\",\"repo_token\":\"$GITHUB_TOKEN\",\"payload\":{\"build_num\":$GITHUB_RUN_ID,\"status\":\"done\"}}" || true
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
name: Shellcheck
|
||||
|
||||
on: [pull_request, push]
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
shellcheck:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v3
|
||||
|
|
|
@ -11,6 +11,7 @@ on:
|
|||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository_owner == 'emqx'
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: none
|
||||
|
|
|
@ -1070,14 +1070,20 @@ Supported configurations are the following:
|
|||
en: """Dispatch strategy for shared subscription.
|
||||
- `random`: dispatch the message to a random selected subscriber
|
||||
- `round_robin`: select the subscribers in a round-robin manner
|
||||
- `round_robin_per_group`: select the subscribers in round-robin fashion within each shared subscriber group
|
||||
- `local`: select random local subscriber otherwise select random cluster-wide
|
||||
- `sticky`: always use the last selected subscriber to dispatch, until the subscriber disconnects.
|
||||
- `hash`: select the subscribers by the hash of `clientIds`"""
|
||||
- `hash_clientid`: select the subscribers by hashing the `clientIds`
|
||||
- `hash_topic`: select the subscribers by hashing the source topic"""
|
||||
|
||||
zh: """共享订阅消息派发策略。
|
||||
- `random`:随机挑选一个共享订阅者派发;
|
||||
- `round_robin`:使用 round-robin 策略派发;
|
||||
- `round_robin_per_group`: 在共享组内循环选择下一个成员;
|
||||
- `local`: 选择随机的本地成员,否则选择随机的集群范围内成员;
|
||||
- `sticky`:总是使用上次选中的订阅者派发,直到它断开连接;
|
||||
- `hash`:使用发送者的 Client ID 进行 Hash 来选择订阅者。"""
|
||||
- `hash_clientid`:使用发送者的 Client ID 进行 Hash 来选择订阅者;
|
||||
- `hash_topic`: 使用源主题进行 Hash 来选择订阅者。"""
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
-define(EMQX_RELEASE_CE, "5.0.20").
|
||||
|
||||
%% Enterprise edition
|
||||
-define(EMQX_RELEASE_EE, "5.0.1").
|
||||
-define(EMQX_RELEASE_EE, "5.0.2-alpha.1").
|
||||
|
||||
%% the HTTP API version
|
||||
-define(EMQX_API_VERSION, "5.0").
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
{jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}},
|
||||
{cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.9.0"}}},
|
||||
{esockd, {git, "https://github.com/emqx/esockd", {tag, "5.9.4"}}},
|
||||
{ekka, {git, "https://github.com/emqx/ekka", {tag, "0.14.3"}}},
|
||||
{ekka, {git, "https://github.com/emqx/ekka", {tag, "0.14.4"}}},
|
||||
{gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.8.1"}}},
|
||||
{hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.36.0"}}},
|
||||
{pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}},
|
||||
|
|
BIN
apps/emqx/rebar3
BIN
apps/emqx/rebar3
Binary file not shown.
|
@ -3,7 +3,7 @@
|
|||
{id, "emqx"},
|
||||
{description, "EMQX Core"},
|
||||
% strict semver, bump manually!
|
||||
{vsn, "5.0.19"},
|
||||
{vsn, "5.0.20"},
|
||||
{modules, []},
|
||||
{registered, []},
|
||||
{applications, [
|
||||
|
|
|
@ -224,6 +224,8 @@ set_session(Session, Channel = #channel{conninfo = ConnInfo, clientinfo = Client
|
|||
Channel#channel{session = Session1}.
|
||||
|
||||
-spec stats(channel()) -> emqx_types:stats().
|
||||
stats(#channel{session = undefined}) ->
|
||||
emqx_pd:get_counters(?CHANNEL_METRICS);
|
||||
stats(#channel{session = Session}) ->
|
||||
lists:append(emqx_session:stats(Session), emqx_pd:get_counters(?CHANNEL_METRICS)).
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||
|
@ -67,7 +68,8 @@
|
|||
%% Test/debug interface
|
||||
-export([
|
||||
all_channels/0,
|
||||
all_client_ids/0
|
||||
all_client_ids/0,
|
||||
get_session_confs/2
|
||||
]).
|
||||
|
||||
%% gen_server callbacks
|
||||
|
@ -296,9 +298,9 @@ open_session(false, ClientInfo = #{clientid := ClientId}, ConnInfo) ->
|
|||
register_channel(ClientId, Self, ConnInfo),
|
||||
|
||||
{ok, #{
|
||||
session => Session1,
|
||||
session => clean_session(Session1),
|
||||
present => true,
|
||||
pendings => Pendings
|
||||
pendings => clean_pendings(Pendings)
|
||||
}};
|
||||
{living, ConnMod, ChanPid, Session} ->
|
||||
ok = emqx_session:resume(ClientInfo, Session),
|
||||
|
@ -315,9 +317,9 @@ open_session(false, ClientInfo = #{clientid := ClientId}, ConnInfo) ->
|
|||
),
|
||||
register_channel(ClientId, Self, ConnInfo),
|
||||
{ok, #{
|
||||
session => Session1,
|
||||
session => clean_session(Session1),
|
||||
present => true,
|
||||
pendings => Pendings
|
||||
pendings => clean_pendings(Pendings)
|
||||
}};
|
||||
{error, _} ->
|
||||
CreateSess()
|
||||
|
@ -355,6 +357,7 @@ get_session_confs(#{zone := Zone, clientid := ClientId}, #{
|
|||
max_inflight => MaxInflight,
|
||||
retry_interval => get_mqtt_conf(Zone, retry_interval),
|
||||
await_rel_timeout => get_mqtt_conf(Zone, await_rel_timeout),
|
||||
max_awaiting_rel => get_mqtt_conf(Zone, max_awaiting_rel),
|
||||
mqueue => mqueue_confs(Zone),
|
||||
%% TODO: Add conf for allowing/disallowing persistent sessions.
|
||||
%% Note that the connection info is already enriched to have
|
||||
|
@ -730,3 +733,14 @@ get_connected_client_count() ->
|
|||
undefined -> 0;
|
||||
Size -> Size
|
||||
end.
|
||||
|
||||
clean_session(Session) ->
|
||||
emqx_session:filter_queue(fun is_banned_msg/1, Session).
|
||||
|
||||
clean_pendings(Pendings) ->
|
||||
lists:filter(fun is_banned_msg/1, Pendings).
|
||||
|
||||
is_banned_msg(#message{from = ClientId}) ->
|
||||
[] =:= emqx_banned:look_up({clientid, ClientId});
|
||||
is_banned_msg({deliver, _Topic, Msg}) ->
|
||||
is_banned_msg(Msg).
|
||||
|
|
|
@ -67,7 +67,8 @@
|
|||
out/1,
|
||||
stats/1,
|
||||
dropped/1,
|
||||
to_list/1
|
||||
to_list/1,
|
||||
filter/2
|
||||
]).
|
||||
|
||||
-define(NO_PRIORITY_TABLE, disabled).
|
||||
|
@ -158,6 +159,19 @@ max_len(#mqueue{max_len = MaxLen}) -> MaxLen.
|
|||
to_list(MQ) ->
|
||||
to_list(MQ, []).
|
||||
|
||||
-spec filter(fun((any()) -> boolean()), mqueue()) -> mqueue().
|
||||
filter(_Pred, #mqueue{len = 0} = MQ) ->
|
||||
MQ;
|
||||
filter(Pred, #mqueue{q = Q, len = Len, dropped = Droppend} = MQ) ->
|
||||
Q2 = ?PQUEUE:filter(Pred, Q),
|
||||
case ?PQUEUE:len(Q2) of
|
||||
Len ->
|
||||
MQ;
|
||||
Len2 ->
|
||||
Diff = Len - Len2,
|
||||
MQ#mqueue{q = Q2, len = Len2, dropped = Droppend + Diff}
|
||||
end.
|
||||
|
||||
to_list(MQ, Acc) ->
|
||||
case out(MQ) of
|
||||
{empty, _MQ} ->
|
||||
|
|
|
@ -2608,7 +2608,7 @@ non_empty_string(_) -> {error, invalid_string}.
|
|||
servers_sc(Meta0, ParseOpts) ->
|
||||
%% if this filed has a default value
|
||||
%% then it is not NOT required
|
||||
%% NOTE: maps:is_key is not the solution beause #{default => undefined} is legit
|
||||
%% NOTE: maps:is_key is not the solution because #{default => undefined} is legit
|
||||
HasDefault = (maps:get(default, Meta0, undefined) =/= undefined),
|
||||
Required = maps:get(required, Meta0, not HasDefault),
|
||||
Meta = #{
|
||||
|
@ -2661,17 +2661,18 @@ normalize_host_port_str(Str) ->
|
|||
%% NOTE: Validator is called after converter.
|
||||
servers_validator(Opts, Required) ->
|
||||
fun(Str0) ->
|
||||
Str = str(Str0),
|
||||
case Str =:= "" orelse Str =:= "undefined" of
|
||||
true when Required ->
|
||||
%% it's a required field
|
||||
%% but value is set to an empty string (from environment override)
|
||||
%% or when the filed is not set in config file
|
||||
case str(Str0) of
|
||||
"" ->
|
||||
%% Empty string is not allowed even if the field is not required
|
||||
%% we should remove field from config if it's empty
|
||||
throw("cannot_be_empty");
|
||||
"undefined" when Required ->
|
||||
%% when the filed is not set in config file
|
||||
%% NOTE: assuming nobody is going to name their server "undefined"
|
||||
throw("cannot_be_empty");
|
||||
true ->
|
||||
"undefined" ->
|
||||
ok;
|
||||
_ ->
|
||||
Str ->
|
||||
%% it's valid as long as it can be parsed
|
||||
_ = parse_servers(Str, Opts),
|
||||
ok
|
||||
|
@ -2816,20 +2817,17 @@ is_port_number(Port) ->
|
|||
end.
|
||||
|
||||
parse_port(Port) ->
|
||||
try
|
||||
P = list_to_integer(string:strip(Port)),
|
||||
true = (P > 0),
|
||||
true = (P =< 65535),
|
||||
P
|
||||
catch
|
||||
_:_ ->
|
||||
throw("bad_port_number")
|
||||
case string:to_integer(string:strip(Port)) of
|
||||
{P, ""} when P < 0 -> throw("port_number_must_be_positive");
|
||||
{P, ""} when P > 65535 -> throw("port_number_too_large");
|
||||
{P, ""} -> P;
|
||||
_ -> throw("bad_port_number")
|
||||
end.
|
||||
|
||||
quic_feature_toggle(Desc) ->
|
||||
sc(
|
||||
%% true, false are for user facing
|
||||
%% 0, 1 are for internal represtation
|
||||
%% 0, 1 are for internal representation
|
||||
typerefl:alias("boolean", typerefl:union([true, false, 0, 1])),
|
||||
#{
|
||||
desc => Desc,
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
deliver/3,
|
||||
enqueue/3,
|
||||
dequeue/2,
|
||||
filter_queue/2,
|
||||
ignore_local/4,
|
||||
retry/2,
|
||||
terminate/3
|
||||
|
@ -200,7 +201,7 @@
|
|||
|
||||
-spec init(options()) -> session().
|
||||
init(Opts) ->
|
||||
MaxInflight = maps:get(max_inflight, Opts, 1),
|
||||
MaxInflight = maps:get(max_inflight, Opts),
|
||||
QueueOpts = maps:merge(
|
||||
#{
|
||||
max_len => 1000,
|
||||
|
@ -211,17 +212,17 @@ init(Opts) ->
|
|||
#session{
|
||||
id = emqx_guid:gen(),
|
||||
clientid = maps:get(clientid, Opts, <<>>),
|
||||
is_persistent = maps:get(is_persistent, Opts, false),
|
||||
max_subscriptions = maps:get(max_subscriptions, Opts, infinity),
|
||||
is_persistent = maps:get(is_persistent, Opts),
|
||||
max_subscriptions = maps:get(max_subscriptions, Opts),
|
||||
subscriptions = #{},
|
||||
upgrade_qos = maps:get(upgrade_qos, Opts, false),
|
||||
upgrade_qos = maps:get(upgrade_qos, Opts),
|
||||
inflight = emqx_inflight:new(MaxInflight),
|
||||
mqueue = emqx_mqueue:init(QueueOpts),
|
||||
next_pkt_id = 1,
|
||||
retry_interval = maps:get(retry_interval, Opts, 30000),
|
||||
retry_interval = maps:get(retry_interval, Opts),
|
||||
awaiting_rel = #{},
|
||||
max_awaiting_rel = maps:get(max_awaiting_rel, Opts, 100),
|
||||
await_rel_timeout = maps:get(await_rel_timeout, Opts, 300000),
|
||||
max_awaiting_rel = maps:get(max_awaiting_rel, Opts),
|
||||
await_rel_timeout = maps:get(await_rel_timeout, Opts),
|
||||
created_at = erlang:system_time(millisecond)
|
||||
}.
|
||||
|
||||
|
@ -529,6 +530,9 @@ dequeue(ClientInfo, Cnt, Msgs, Q) ->
|
|||
end
|
||||
end.
|
||||
|
||||
filter_queue(Pred, #session{mqueue = Q} = Session) ->
|
||||
Session#session{mqueue = emqx_mqueue:filter(Pred, Q)}.
|
||||
|
||||
acc_cnt(#message{qos = ?QOS_0}, Cnt) -> Cnt;
|
||||
acc_cnt(_Msg, Cnt) -> Cnt - 1.
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ handle_info({timeout, TRef, heartbeat}, State = #state{heartbeat = TRef}) ->
|
|||
handle_info({timeout, TRef, tick}, State = #state{ticker = TRef, sysdescr = Descr}) ->
|
||||
publish_any(version, version()),
|
||||
publish_any(sysdescr, Descr),
|
||||
publish_any(brokers, mria_mnesia:running_nodes()),
|
||||
publish_any(brokers, mria:running_nodes()),
|
||||
publish_any(stats, emqx_stats:getstats()),
|
||||
publish_any(metrics, emqx_metrics:all()),
|
||||
{noreply, tick(State), hibernate};
|
||||
|
|
|
@ -303,7 +303,7 @@ resume(ClientInfo = #{clientid := ClientID}, ConnInfo, Session) ->
|
|||
%% 3. Notify writers that we are resuming.
|
||||
%% They will buffer new messages.
|
||||
?tp(ps_notify_writers, #{sid => SessionID}),
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
NodeMarkers = resume_begin(Nodes, SessionID),
|
||||
?tp(ps_node_markers, #{sid => SessionID, markers => NodeMarkers}),
|
||||
|
||||
|
|
|
@ -141,3 +141,73 @@ t_kick(_) ->
|
|||
snabbkaffe:stop(),
|
||||
emqx_banned:delete(Who),
|
||||
?assertEqual(1, length(?of_kind(kick_session_due_to_banned, Trace))).
|
||||
|
||||
t_session_taken(_) ->
|
||||
erlang:process_flag(trap_exit, true),
|
||||
Topic = <<"t/banned">>,
|
||||
ClientId2 = <<"t_session_taken">>,
|
||||
MsgNum = 3,
|
||||
Connect = fun() ->
|
||||
{ok, C} = emqtt:start_link([
|
||||
{clientid, <<"client1">>},
|
||||
{proto_ver, v5},
|
||||
{clean_start, false},
|
||||
{properties, #{'Session-Expiry-Interval' => 120}}
|
||||
]),
|
||||
{ok, _} = emqtt:connect(C),
|
||||
{ok, _, [0]} = emqtt:subscribe(C, Topic, []),
|
||||
C
|
||||
end,
|
||||
|
||||
Publish = fun() ->
|
||||
lists:foreach(
|
||||
fun(_) ->
|
||||
Msg = emqx_message:make(ClientId2, Topic, <<"payload">>),
|
||||
emqx_broker:safe_publish(Msg)
|
||||
end,
|
||||
lists:seq(1, MsgNum)
|
||||
)
|
||||
end,
|
||||
|
||||
C1 = Connect(),
|
||||
ok = emqtt:disconnect(C1),
|
||||
|
||||
Publish(),
|
||||
|
||||
C2 = Connect(),
|
||||
?assertEqual(MsgNum, length(receive_messages(MsgNum + 1))),
|
||||
ok = emqtt:disconnect(C2),
|
||||
|
||||
Publish(),
|
||||
|
||||
Now = erlang:system_time(second),
|
||||
Who = {clientid, ClientId2},
|
||||
emqx_banned:create(#{
|
||||
who => Who,
|
||||
by => <<"test">>,
|
||||
reason => <<"test">>,
|
||||
at => Now,
|
||||
until => Now + 120
|
||||
}),
|
||||
|
||||
C3 = Connect(),
|
||||
?assertEqual(0, length(receive_messages(MsgNum + 1))),
|
||||
emqx_banned:delete(Who),
|
||||
{ok, #{}, [0]} = emqtt:unsubscribe(C3, Topic),
|
||||
ok = emqtt:disconnect(C3).
|
||||
|
||||
receive_messages(Count) ->
|
||||
receive_messages(Count, []).
|
||||
receive_messages(0, Msgs) ->
|
||||
Msgs;
|
||||
receive_messages(Count, Msgs) ->
|
||||
receive
|
||||
{publish, Msg} ->
|
||||
ct:log("Msg: ~p ~n", [Msg]),
|
||||
receive_messages(Count - 1, [Msg | Msgs]);
|
||||
Other ->
|
||||
ct:log("Other Msg: ~p~n", [Other]),
|
||||
receive_messages(Count, Msgs)
|
||||
after 1200 ->
|
||||
Msgs
|
||||
end.
|
||||
|
|
|
@ -1236,11 +1236,17 @@ connpkt(Props) ->
|
|||
|
||||
session() -> session(#{}).
|
||||
session(InitFields) when is_map(InitFields) ->
|
||||
Conf = emqx_cm:get_session_confs(
|
||||
#{zone => default, clientid => <<"fake-test">>}, #{
|
||||
receive_maximum => 0, expiry_interval => 0
|
||||
}
|
||||
),
|
||||
Session = emqx_session:init(Conf),
|
||||
maps:fold(
|
||||
fun(Field, Value, Session) ->
|
||||
emqx_session:set_field(Field, Value, Session)
|
||||
fun(Field, Value, SessionAcc) ->
|
||||
emqx_session:set_field(Field, Value, SessionAcc)
|
||||
end,
|
||||
emqx_session:init(#{max_inflight => 0}),
|
||||
Session,
|
||||
InitFields
|
||||
).
|
||||
|
||||
|
|
|
@ -673,7 +673,10 @@ channel(InitFields) ->
|
|||
peercert => undefined,
|
||||
mountpoint => undefined
|
||||
},
|
||||
Session = emqx_session:init(#{max_inflight => 0}),
|
||||
Conf = emqx_cm:get_session_confs(ClientInfo, #{
|
||||
receive_maximum => 0, expiry_interval => 1000
|
||||
}),
|
||||
Session = emqx_session:init(Conf),
|
||||
maps:fold(
|
||||
fun(Field, Value, Channel) ->
|
||||
emqx_channel:set_field(Field, Value, Channel)
|
||||
|
|
|
@ -455,10 +455,11 @@ servers_validator_test() ->
|
|||
NotRequired = emqx_schema:servers_validator(#{}, false),
|
||||
?assertThrow("cannot_be_empty", Required("")),
|
||||
?assertThrow("cannot_be_empty", Required(<<>>)),
|
||||
?assertThrow("cannot_be_empty", NotRequired("")),
|
||||
?assertThrow("cannot_be_empty", NotRequired(<<>>)),
|
||||
?assertThrow("cannot_be_empty", Required(undefined)),
|
||||
?assertEqual(ok, NotRequired("")),
|
||||
?assertEqual(ok, NotRequired(<<>>)),
|
||||
?assertEqual(ok, NotRequired(undefined)),
|
||||
?assertEqual(ok, NotRequired("undefined")),
|
||||
ok.
|
||||
|
||||
converter_invalid_input_test() ->
|
||||
|
|
|
@ -63,7 +63,12 @@ end_per_testcase(_TestCase, Config) ->
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
t_session_init(_) ->
|
||||
Session = emqx_session:init(#{max_inflight => 64}),
|
||||
Conf = emqx_cm:get_session_confs(
|
||||
#{zone => default, clientid => <<"fake-test">>}, #{
|
||||
receive_maximum => 64, expiry_interval => 0
|
||||
}
|
||||
),
|
||||
Session = emqx_session:init(Conf),
|
||||
?assertEqual(#{}, emqx_session:info(subscriptions, Session)),
|
||||
?assertEqual(0, emqx_session:info(subscriptions_cnt, Session)),
|
||||
?assertEqual(infinity, emqx_session:info(subscriptions_max, Session)),
|
||||
|
@ -459,11 +464,17 @@ mqueue(Opts) ->
|
|||
|
||||
session() -> session(#{}).
|
||||
session(InitFields) when is_map(InitFields) ->
|
||||
Conf = emqx_cm:get_session_confs(
|
||||
#{zone => default, clientid => <<"fake-test">>}, #{
|
||||
receive_maximum => 0, expiry_interval => 0
|
||||
}
|
||||
),
|
||||
Session = emqx_session:init(Conf),
|
||||
maps:fold(
|
||||
fun(Field, Value, Session) ->
|
||||
emqx_session:set_field(Field, Value, Session)
|
||||
fun(Field, Value, SessionAcc) ->
|
||||
emqx_session:set_field(Field, Value, SessionAcc)
|
||||
end,
|
||||
emqx_session:init(#{max_inflight => 0}),
|
||||
Session,
|
||||
InitFields
|
||||
).
|
||||
|
||||
|
|
|
@ -612,7 +612,10 @@ channel(InitFields) ->
|
|||
peercert => undefined,
|
||||
mountpoint => undefined
|
||||
},
|
||||
Session = emqx_session:init(#{max_inflight => 0}),
|
||||
Conf = emqx_cm:get_session_confs(ClientInfo, #{
|
||||
receive_maximum => 0, expiry_interval => 0
|
||||
}),
|
||||
Session = emqx_session:init(Conf),
|
||||
maps:fold(
|
||||
fun(Field, Value, Channel) ->
|
||||
emqx_channel:set_field(Field, Value, Channel)
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
emqx_metrics,
|
||||
emqx_stats,
|
||||
emqx_broker,
|
||||
mria_mnesia,
|
||||
mria,
|
||||
emqx_hooks,
|
||||
emqx_config_handler
|
||||
]).
|
||||
|
@ -109,8 +109,8 @@ do_mock(emqx_broker) ->
|
|||
);
|
||||
do_mock(emqx_stats) ->
|
||||
meck:expect(emqx_stats, getstats, fun() -> [0] end);
|
||||
do_mock(mria_mnesia) ->
|
||||
meck:expect(mria_mnesia, running_nodes, fun() -> [node()] end);
|
||||
do_mock(mria) ->
|
||||
meck:expect(mria, running_nodes, fun() -> [node()] end);
|
||||
do_mock(emqx_metrics) ->
|
||||
meck:expect(emqx_metrics, all, fun() -> [{hello, 3}] end);
|
||||
do_mock(emqx_hooks) ->
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
{application, emqx_authn, [
|
||||
{description, "EMQX Authentication"},
|
||||
{vsn, "0.1.14"},
|
||||
{vsn, "0.1.15"},
|
||||
{modules, []},
|
||||
{registered, [emqx_authn_sup, emqx_authn_registry]},
|
||||
{applications, [kernel, stdlib, emqx_resource, emqx_connector, ehttpc, epgsql, mysql, jose]},
|
||||
|
|
|
@ -881,7 +881,7 @@ lookup_from_local_node(ChainName, AuthenticatorID) ->
|
|||
end.
|
||||
|
||||
lookup_from_all_nodes(ChainName, AuthenticatorID) ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
LookupResult = emqx_authn_proto_v1:lookup_from_all_nodes(Nodes, ChainName, AuthenticatorID),
|
||||
case is_ok(LookupResult) of
|
||||
{ok, ResList} ->
|
||||
|
|
|
@ -168,7 +168,7 @@ authenticate(
|
|||
},
|
||||
State
|
||||
) ->
|
||||
case ensure_auth_method(AuthMethod, State) of
|
||||
case ensure_auth_method(AuthMethod, AuthData, State) of
|
||||
true ->
|
||||
case AuthCache of
|
||||
#{next_step := client_final} ->
|
||||
|
@ -304,11 +304,13 @@ run_fuzzy_filter(
|
|||
%% Internal functions
|
||||
%%------------------------------------------------------------------------------
|
||||
|
||||
ensure_auth_method(<<"SCRAM-SHA-256">>, #{algorithm := sha256}) ->
|
||||
ensure_auth_method(_AuthMethod, undefined, _State) ->
|
||||
false;
|
||||
ensure_auth_method(<<"SCRAM-SHA-256">>, _AuthData, #{algorithm := sha256}) ->
|
||||
true;
|
||||
ensure_auth_method(<<"SCRAM-SHA-512">>, #{algorithm := sha512}) ->
|
||||
ensure_auth_method(<<"SCRAM-SHA-512">>, _AuthData, #{algorithm := sha512}) ->
|
||||
true;
|
||||
ensure_auth_method(_, _) ->
|
||||
ensure_auth_method(_AuthMethod, _AuthData, _State) ->
|
||||
false.
|
||||
|
||||
check_client_first_message(Bin, _Cache, #{iteration_count := IterationCount} = State) ->
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
-compile(nowarn_export_all).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
|
||||
-include_lib("emqx/include/emqx_mqtt.hrl").
|
||||
-include("emqx_authn.hrl").
|
||||
|
@ -37,9 +38,11 @@ all() ->
|
|||
init_per_suite(Config) ->
|
||||
_ = application:load(emqx_conf),
|
||||
ok = emqx_common_test_helpers:start_apps([emqx_authn]),
|
||||
Config.
|
||||
IdleTimeout = emqx_config:get([mqtt, idle_timeout]),
|
||||
[{idle_timeout, IdleTimeout} | Config].
|
||||
|
||||
end_per_suite(_Config) ->
|
||||
end_per_suite(Config) ->
|
||||
ok = emqx_config:put([mqtt, idle_timeout], ?config(idle_timeout, Config)),
|
||||
ok = emqx_common_test_helpers:stop_apps([emqx_authn]).
|
||||
|
||||
init_per_testcase(_Case, Config) ->
|
||||
|
@ -99,6 +102,8 @@ t_authenticate(_Config) ->
|
|||
|
||||
init_auth(Username, Password, Algorithm),
|
||||
|
||||
ok = emqx_config:put([mqtt, idle_timeout], 500),
|
||||
|
||||
{ok, Pid} = emqx_authn_mqtt_test_client:start_link("127.0.0.1", 1883),
|
||||
|
||||
ClientFirstMessage = esasl_scram:client_first_message(Username),
|
||||
|
@ -115,6 +120,9 @@ t_authenticate(_Config) ->
|
|||
|
||||
ok = emqx_authn_mqtt_test_client:send(Pid, ConnectPacket),
|
||||
|
||||
%% Intentional sleep to trigger idle timeout for the connection not yet authenticated
|
||||
ok = ct:sleep(1000),
|
||||
|
||||
?AUTH_PACKET(
|
||||
?RC_CONTINUE_AUTHENTICATION,
|
||||
#{'Authentication-Data' := ServerFirstMessage}
|
||||
|
@ -150,6 +158,28 @@ t_authenticate(_Config) ->
|
|||
ServerFinalMessage, ClientCache#{algorithm => Algorithm}
|
||||
).
|
||||
|
||||
t_authenticate_bad_props(_Config) ->
|
||||
Algorithm = sha512,
|
||||
Username = <<"u">>,
|
||||
Password = <<"p">>,
|
||||
|
||||
init_auth(Username, Password, Algorithm),
|
||||
|
||||
{ok, Pid} = emqx_authn_mqtt_test_client:start_link("127.0.0.1", 1883),
|
||||
|
||||
ConnectPacket = ?CONNECT_PACKET(
|
||||
#mqtt_packet_connect{
|
||||
proto_ver = ?MQTT_PROTO_V5,
|
||||
properties = #{
|
||||
'Authentication-Method' => <<"SCRAM-SHA-512">>
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
ok = emqx_authn_mqtt_test_client:send(Pid, ConnectPacket),
|
||||
|
||||
?CONNACK_PACKET(?RC_NOT_AUTHORIZED) = receive_packet().
|
||||
|
||||
t_authenticate_bad_username(_Config) ->
|
||||
Algorithm = sha512,
|
||||
Username = <<"u">>,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
{application, emqx_authz, [
|
||||
{description, "An OTP application"},
|
||||
{vsn, "0.1.14"},
|
||||
{vsn, "0.1.15"},
|
||||
{registered, []},
|
||||
{mod, {emqx_authz_app, []}},
|
||||
{applications, [
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
-export([
|
||||
sources/2,
|
||||
source/2,
|
||||
move_source/2,
|
||||
source_move/2,
|
||||
aggregate_metrics/1
|
||||
]).
|
||||
|
||||
|
@ -164,7 +164,7 @@ schema("/authorization/sources/:type/status") ->
|
|||
};
|
||||
schema("/authorization/sources/:type/move") ->
|
||||
#{
|
||||
'operationId' => move_source,
|
||||
'operationId' => source_move,
|
||||
post =>
|
||||
#{
|
||||
description => ?DESC(authorization_sources_type_move_post),
|
||||
|
@ -230,8 +230,6 @@ sources(get, _) ->
|
|||
get_raw_sources()
|
||||
),
|
||||
{200, #{sources => Sources}};
|
||||
sources(post, #{body := #{<<"type">> := <<"file">>} = Body}) ->
|
||||
create_authz_file(Body);
|
||||
sources(post, #{body := Body}) ->
|
||||
update_config(?CMD_PREPEND, Body).
|
||||
|
||||
|
@ -240,75 +238,99 @@ source(Method, #{bindings := #{type := Type} = Bindings} = Req) when
|
|||
->
|
||||
source(Method, Req#{bindings => Bindings#{type => atom_to_binary(Type, utf8)}});
|
||||
source(get, #{bindings := #{type := Type}}) ->
|
||||
case get_raw_source(Type) of
|
||||
[] ->
|
||||
{404, #{code => <<"NOT_FOUND">>, message => <<"Not found: ", Type/binary>>}};
|
||||
[#{<<"type">> := <<"file">>, <<"enable">> := Enable, <<"path">> := Path}] ->
|
||||
case file:read_file(Path) of
|
||||
{ok, Rules} ->
|
||||
{200, #{
|
||||
type => file,
|
||||
enable => Enable,
|
||||
rules => Rules
|
||||
}};
|
||||
{error, Reason} ->
|
||||
{500, #{
|
||||
code => <<"INTERNAL_ERROR">>,
|
||||
message => bin(Reason)
|
||||
}}
|
||||
end;
|
||||
[Source] ->
|
||||
{200, Source}
|
||||
end;
|
||||
source(put, #{bindings := #{type := <<"file">>}, body := #{<<"type">> := <<"file">>} = Body}) ->
|
||||
update_authz_file(Body);
|
||||
source(put, #{bindings := #{type := Type}, body := Body}) ->
|
||||
update_config({?CMD_REPLACE, Type}, Body);
|
||||
with_source(
|
||||
Type,
|
||||
fun
|
||||
(#{<<"type">> := <<"file">>, <<"enable">> := Enable, <<"path">> := Path}) ->
|
||||
case file:read_file(Path) of
|
||||
{ok, Rules} ->
|
||||
{200, #{
|
||||
type => file,
|
||||
enable => Enable,
|
||||
rules => Rules
|
||||
}};
|
||||
{error, Reason} ->
|
||||
{500, #{
|
||||
code => <<"INTERNAL_ERROR">>,
|
||||
message => bin(Reason)
|
||||
}}
|
||||
end;
|
||||
(Source) ->
|
||||
{200, Source}
|
||||
end
|
||||
);
|
||||
source(put, #{bindings := #{type := Type}, body := #{<<"type">> := Type} = Body}) ->
|
||||
with_source(
|
||||
Type,
|
||||
fun(_) ->
|
||||
update_config({?CMD_REPLACE, Type}, Body)
|
||||
end
|
||||
);
|
||||
source(put, #{bindings := #{type := Type}, body := #{<<"type">> := _OtherType}}) ->
|
||||
with_source(
|
||||
Type,
|
||||
fun(_) ->
|
||||
{400, #{code => <<"BAD_REQUEST">>, message => <<"Type mismatch">>}}
|
||||
end
|
||||
);
|
||||
source(delete, #{bindings := #{type := Type}}) ->
|
||||
update_config({?CMD_DELETE, Type}, #{}).
|
||||
with_source(
|
||||
Type,
|
||||
fun(_) ->
|
||||
update_config({?CMD_DELETE, Type}, #{})
|
||||
end
|
||||
).
|
||||
|
||||
source_status(get, #{bindings := #{type := Type}}) ->
|
||||
lookup_from_all_nodes(Type).
|
||||
with_source(
|
||||
atom_to_binary(Type, utf8),
|
||||
fun(_) -> lookup_from_all_nodes(Type) end
|
||||
).
|
||||
|
||||
move_source(Method, #{bindings := #{type := Type} = Bindings} = Req) when
|
||||
source_move(Method, #{bindings := #{type := Type} = Bindings} = Req) when
|
||||
is_atom(Type)
|
||||
->
|
||||
move_source(Method, Req#{bindings => Bindings#{type => atom_to_binary(Type, utf8)}});
|
||||
move_source(post, #{bindings := #{type := Type}, body := #{<<"position">> := Position}}) ->
|
||||
case parse_position(Position) of
|
||||
{ok, NPosition} ->
|
||||
try emqx_authz:move(Type, NPosition) of
|
||||
{ok, _} ->
|
||||
{204};
|
||||
{error, {not_found_source, _Type}} ->
|
||||
{404, #{
|
||||
code => <<"NOT_FOUND">>,
|
||||
message => <<"source ", Type/binary, " not found">>
|
||||
}};
|
||||
{error, {emqx_conf_schema, _}} ->
|
||||
{400, #{
|
||||
code => <<"BAD_REQUEST">>,
|
||||
message => <<"BAD_SCHEMA">>
|
||||
}};
|
||||
source_move(Method, Req#{bindings => Bindings#{type => atom_to_binary(Type, utf8)}});
|
||||
source_move(post, #{bindings := #{type := Type}, body := #{<<"position">> := Position}}) ->
|
||||
with_source(
|
||||
Type,
|
||||
fun(_Source) ->
|
||||
case parse_position(Position) of
|
||||
{ok, NPosition} ->
|
||||
try emqx_authz:move(Type, NPosition) of
|
||||
{ok, _} ->
|
||||
{204};
|
||||
{error, {not_found_source, _Type}} ->
|
||||
{404, #{
|
||||
code => <<"NOT_FOUND">>,
|
||||
message => <<"source ", Type/binary, " not found">>
|
||||
}};
|
||||
{error, {emqx_conf_schema, _}} ->
|
||||
{400, #{
|
||||
code => <<"BAD_REQUEST">>,
|
||||
message => <<"BAD_SCHEMA">>
|
||||
}};
|
||||
{error, Reason} ->
|
||||
{400, #{
|
||||
code => <<"BAD_REQUEST">>,
|
||||
message => bin(Reason)
|
||||
}}
|
||||
catch
|
||||
error:{unknown_authz_source_type, Unknown} ->
|
||||
NUnknown = bin(Unknown),
|
||||
{400, #{
|
||||
code => <<"BAD_REQUEST">>,
|
||||
message => <<"Unknown authz Source Type: ", NUnknown/binary>>
|
||||
}}
|
||||
end;
|
||||
{error, Reason} ->
|
||||
{400, #{
|
||||
code => <<"BAD_REQUEST">>,
|
||||
message => bin(Reason)
|
||||
}}
|
||||
catch
|
||||
error:{unknown_authz_source_type, Unknown} ->
|
||||
NUnknown = bin(Unknown),
|
||||
{400, #{
|
||||
code => <<"BAD_REQUEST">>,
|
||||
message => <<"Unknown authz Source Type: ", NUnknown/binary>>
|
||||
}}
|
||||
end;
|
||||
{error, Reason} ->
|
||||
{400, #{
|
||||
code => <<"BAD_REQUEST">>,
|
||||
message => bin(Reason)
|
||||
}}
|
||||
end.
|
||||
end
|
||||
end
|
||||
).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Internal functions
|
||||
|
@ -334,7 +356,7 @@ lookup_from_local_node(Type) ->
|
|||
end.
|
||||
|
||||
lookup_from_all_nodes(Type) ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
case is_ok(emqx_authz_proto_v1:lookup_from_all_nodes(Nodes, Type)) of
|
||||
{ok, ResList} ->
|
||||
{StatusMap, MetricsMap, ResourceMetricsMap, ErrorMap} = make_result_map(ResList),
|
||||
|
@ -484,6 +506,15 @@ get_raw_source(Type) ->
|
|||
get_raw_sources()
|
||||
).
|
||||
|
||||
-spec with_source(binary(), fun((map()) -> term())) -> term().
|
||||
with_source(Type, ContF) ->
|
||||
case get_raw_source(Type) of
|
||||
[] ->
|
||||
{404, #{code => <<"NOT_FOUND">>, message => <<"Not found: ", Type/binary>>}};
|
||||
[Source] ->
|
||||
ContF(Source)
|
||||
end.
|
||||
|
||||
update_config(Cmd, Sources) ->
|
||||
case emqx_authz:update(Cmd, Sources) of
|
||||
{ok, _} ->
|
||||
|
@ -628,13 +659,3 @@ status_metrics_example() ->
|
|||
}
|
||||
}
|
||||
}.
|
||||
|
||||
create_authz_file(Body) ->
|
||||
do_update_authz_file(?CMD_PREPEND, Body).
|
||||
|
||||
update_authz_file(Body) ->
|
||||
do_update_authz_file({?CMD_REPLACE, <<"file">>}, Body).
|
||||
|
||||
do_update_authz_file(Cmd, Body) ->
|
||||
%% API update will placed in `authz` subdirectory inside EMQX's `data_dir`
|
||||
update_config(Cmd, Body).
|
||||
|
|
|
@ -240,7 +240,7 @@ http_common_fields() ->
|
|||
mongo_common_fields() ->
|
||||
[
|
||||
{collection,
|
||||
?HOCON(atom(), #{
|
||||
?HOCON(binary(), #{
|
||||
required => true,
|
||||
desc => ?DESC(collection)
|
||||
})},
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
-import(emqx_mgmt_api_test_util, [request/3, uri/1]).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
-include_lib("emqx/include/emqx_placeholder.hrl").
|
||||
|
||||
-define(MONGO_SINGLE_HOST, "mongo").
|
||||
|
@ -183,7 +182,7 @@ t_api(_) ->
|
|||
{ok, 404, ErrResult} = request(get, uri(["authorization", "sources", "http"]), []),
|
||||
?assertMatch(
|
||||
#{<<"code">> := <<"NOT_FOUND">>, <<"message">> := <<"Not found: http">>},
|
||||
jsx:decode(ErrResult)
|
||||
emqx_json:decode(ErrResult, [return_maps])
|
||||
),
|
||||
|
||||
[
|
||||
|
@ -215,7 +214,9 @@ t_api(_) ->
|
|||
?SOURCE1#{<<"enable">> := false}
|
||||
),
|
||||
{ok, 200, Result3} = request(get, uri(["authorization", "sources", "http"]), []),
|
||||
?assertMatch(#{<<"type">> := <<"http">>, <<"enable">> := false}, jsx:decode(Result3)),
|
||||
?assertMatch(
|
||||
#{<<"type">> := <<"http">>, <<"enable">> := false}, emqx_json:decode(Result3, [return_maps])
|
||||
),
|
||||
|
||||
Keyfile = emqx_common_test_helpers:app_path(
|
||||
emqx,
|
||||
|
@ -252,7 +253,7 @@ t_api(_) ->
|
|||
<<"total">> := 0,
|
||||
<<"nomatch">> := 0
|
||||
}
|
||||
} = jiffy:decode(Status4, [return_maps]),
|
||||
} = emqx_json:decode(Status4, [return_maps]),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"type">> := <<"mongodb">>,
|
||||
|
@ -264,7 +265,7 @@ t_api(_) ->
|
|||
<<"verify">> := <<"verify_none">>
|
||||
}
|
||||
},
|
||||
jsx:decode(Result4)
|
||||
emqx_json:decode(Result4, [return_maps])
|
||||
),
|
||||
|
||||
{ok, Cacert} = file:read_file(Cacertfile),
|
||||
|
@ -296,7 +297,7 @@ t_api(_) ->
|
|||
<<"verify">> := <<"verify_none">>
|
||||
}
|
||||
},
|
||||
jsx:decode(Result5)
|
||||
emqx_json:decode(Result5, [return_maps])
|
||||
),
|
||||
|
||||
{ok, 200, Status5_1} = request(get, uri(["authorization", "sources", "mongodb", "status"]), []),
|
||||
|
@ -307,7 +308,7 @@ t_api(_) ->
|
|||
<<"total">> := 0,
|
||||
<<"nomatch">> := 0
|
||||
}
|
||||
} = jiffy:decode(Status5_1, [return_maps]),
|
||||
} = emqx_json:decode(Status5_1, [return_maps]),
|
||||
|
||||
#{
|
||||
ssl := #{
|
||||
|
@ -332,6 +333,7 @@ t_api(_) ->
|
|||
uri(["authorization", "sources", "postgresql"]),
|
||||
?SOURCE4#{<<"server">> := <<"fake">>}
|
||||
),
|
||||
|
||||
{ok, 204, _} = request(
|
||||
put,
|
||||
uri(["authorization", "sources", "redis"]),
|
||||
|
@ -343,6 +345,19 @@ t_api(_) ->
|
|||
}
|
||||
),
|
||||
|
||||
{ok, 400, TypeMismatch} = request(
|
||||
put,
|
||||
uri(["authorization", "sources", "file"]),
|
||||
#{<<"type">> => <<"built_in_database">>, <<"enable">> => false}
|
||||
),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"code">> := <<"BAD_REQUEST">>,
|
||||
<<"message">> := <<"Type mismatch", _/binary>>
|
||||
},
|
||||
emqx_json:decode(TypeMismatch, [return_maps])
|
||||
),
|
||||
|
||||
lists:foreach(
|
||||
fun(#{<<"type">> := Type}) ->
|
||||
{ok, 204, _} = request(
|
||||
|
@ -357,6 +372,43 @@ t_api(_) ->
|
|||
?assertEqual([], get_sources(Result6)),
|
||||
?assertEqual([], emqx:get_config([authorization, sources])),
|
||||
|
||||
lists:foreach(
|
||||
fun(#{<<"type">> := Type}) ->
|
||||
{ok, 404, _} = request(
|
||||
get,
|
||||
uri(["authorization", "sources", binary_to_list(Type), "status"]),
|
||||
[]
|
||||
),
|
||||
{ok, 404, _} = request(
|
||||
post,
|
||||
uri(["authorization", "sources", binary_to_list(Type), "move"]),
|
||||
#{<<"position">> => <<"front">>}
|
||||
),
|
||||
{ok, 404, _} = request(
|
||||
get,
|
||||
uri(["authorization", "sources", binary_to_list(Type)]),
|
||||
[]
|
||||
),
|
||||
{ok, 404, _} = request(
|
||||
delete,
|
||||
uri(["authorization", "sources", binary_to_list(Type)]),
|
||||
[]
|
||||
)
|
||||
end,
|
||||
Sources
|
||||
),
|
||||
|
||||
{ok, 404, _TypeMismatch2} = request(
|
||||
put,
|
||||
uri(["authorization", "sources", "file"]),
|
||||
#{<<"type">> => <<"built_in_database">>, <<"enable">> => false}
|
||||
),
|
||||
{ok, 404, _} = request(
|
||||
put,
|
||||
uri(["authorization", "sources", "built_in_database"]),
|
||||
#{<<"type">> => <<"built_in_database">>, <<"enable">> => false}
|
||||
),
|
||||
|
||||
{ok, 204, _} = request(post, uri(["authorization", "sources"]), ?SOURCE6),
|
||||
|
||||
{ok, Client} = emqtt:start_link(
|
||||
|
@ -368,7 +420,6 @@ t_api(_) ->
|
|||
]
|
||||
),
|
||||
emqtt:connect(Client),
|
||||
timer:sleep(50),
|
||||
|
||||
emqtt:publish(
|
||||
Client,
|
||||
|
@ -378,17 +429,24 @@ t_api(_) ->
|
|||
[{qos, 1}]
|
||||
),
|
||||
|
||||
{ok, 200, Status5} = request(get, uri(["authorization", "sources", "file", "status"]), []),
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"allow">> := 1,
|
||||
<<"deny">> := 0,
|
||||
<<"total">> := 1,
|
||||
<<"nomatch">> := 0
|
||||
}
|
||||
} = jiffy:decode(Status5, [return_maps]),
|
||||
snabbkaffe:retry(
|
||||
10,
|
||||
3,
|
||||
fun() ->
|
||||
{ok, 200, Status5} = request(
|
||||
get, uri(["authorization", "sources", "file", "status"]), []
|
||||
),
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"allow">> := 1,
|
||||
<<"deny">> := 0,
|
||||
<<"total">> := 1,
|
||||
<<"nomatch">> := 0
|
||||
}
|
||||
} = emqx_json:decode(Status5, [return_maps])
|
||||
end
|
||||
),
|
||||
|
||||
timer:sleep(50),
|
||||
emqtt:publish(
|
||||
Client,
|
||||
<<"t2">>,
|
||||
|
@ -397,17 +455,24 @@ t_api(_) ->
|
|||
[{qos, 1}]
|
||||
),
|
||||
|
||||
{ok, 200, Status6} = request(get, uri(["authorization", "sources", "file", "status"]), []),
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"allow">> := 2,
|
||||
<<"deny">> := 0,
|
||||
<<"total">> := 2,
|
||||
<<"nomatch">> := 0
|
||||
}
|
||||
} = jiffy:decode(Status6, [return_maps]),
|
||||
snabbkaffe:retry(
|
||||
10,
|
||||
3,
|
||||
fun() ->
|
||||
{ok, 200, Status6} = request(
|
||||
get, uri(["authorization", "sources", "file", "status"]), []
|
||||
),
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"allow">> := 2,
|
||||
<<"deny">> := 0,
|
||||
<<"total">> := 2,
|
||||
<<"nomatch">> := 0
|
||||
}
|
||||
} = emqx_json:decode(Status6, [return_maps])
|
||||
end
|
||||
),
|
||||
|
||||
timer:sleep(50),
|
||||
emqtt:publish(
|
||||
Client,
|
||||
<<"t3">>,
|
||||
|
@ -416,20 +481,26 @@ t_api(_) ->
|
|||
[{qos, 1}]
|
||||
),
|
||||
|
||||
timer:sleep(50),
|
||||
{ok, 200, Status7} = request(get, uri(["authorization", "sources", "file", "status"]), []),
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"allow">> := 3,
|
||||
<<"deny">> := 0,
|
||||
<<"total">> := 3,
|
||||
<<"nomatch">> := 0
|
||||
}
|
||||
} = jiffy:decode(Status7, [return_maps]),
|
||||
|
||||
snabbkaffe:retry(
|
||||
10,
|
||||
3,
|
||||
fun() ->
|
||||
{ok, 200, Status7} = request(
|
||||
get, uri(["authorization", "sources", "file", "status"]), []
|
||||
),
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"allow">> := 3,
|
||||
<<"deny">> := 0,
|
||||
<<"total">> := 3,
|
||||
<<"nomatch">> := 0
|
||||
}
|
||||
} = emqx_json:decode(Status7, [return_maps])
|
||||
end
|
||||
),
|
||||
ok.
|
||||
|
||||
t_move_source(_) ->
|
||||
t_source_move(_) ->
|
||||
{ok, _} = emqx_authz:update(replace, [?SOURCE1, ?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5]),
|
||||
?assertMatch(
|
||||
[
|
||||
|
@ -550,7 +621,7 @@ t_aggregate_metrics(_) ->
|
|||
).
|
||||
|
||||
get_sources(Result) ->
|
||||
maps:get(<<"sources">>, jsx:decode(Result), []).
|
||||
maps:get(<<"sources">>, emqx_json:decode(Result, [return_maps])).
|
||||
|
||||
data_dir() -> emqx:data_dir().
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
{application, emqx_bridge, [
|
||||
{description, "EMQX bridges"},
|
||||
{vsn, "0.1.12"},
|
||||
{vsn, "0.1.13"},
|
||||
{registered, []},
|
||||
{mod, {emqx_bridge_app, []}},
|
||||
{applications, [
|
||||
|
|
|
@ -57,7 +57,13 @@
|
|||
T == influxdb_api_v2;
|
||||
T == redis_single;
|
||||
T == redis_sentinel;
|
||||
T == redis_cluster
|
||||
T == redis_cluster;
|
||||
T == clickhouse;
|
||||
T == pgsql;
|
||||
T == timescale;
|
||||
T == matrix;
|
||||
T == tdengine;
|
||||
T == dynamo
|
||||
).
|
||||
|
||||
load() ->
|
||||
|
|
|
@ -46,17 +46,28 @@
|
|||
|
||||
-export([lookup_from_local_node/2]).
|
||||
|
||||
-define(BAD_REQUEST(Reason), {400, error_msg('BAD_REQUEST', Reason)}).
|
||||
|
||||
-define(BRIDGE_NOT_ENABLED,
|
||||
?BAD_REQUEST(<<"Forbidden operation, bridge not enabled">>)
|
||||
).
|
||||
|
||||
-define(NOT_FOUND(Reason), {404, error_msg('NOT_FOUND', Reason)}).
|
||||
|
||||
-define(BRIDGE_NOT_FOUND(BridgeType, BridgeName),
|
||||
?NOT_FOUND(
|
||||
<<"Bridge lookup failed: bridge named '", BridgeName/binary, "' of type ",
|
||||
(atom_to_binary(BridgeType))/binary, " does not exist.">>
|
||||
)
|
||||
).
|
||||
|
||||
-define(TRY_PARSE_ID(ID, EXPR),
|
||||
try emqx_bridge_resource:parse_bridge_id(Id) of
|
||||
{BridgeType, BridgeName} ->
|
||||
EXPR
|
||||
catch
|
||||
throw:{invalid_bridge_id, Reason} ->
|
||||
{400,
|
||||
error_msg(
|
||||
'INVALID_ID',
|
||||
<<"Invalid bride ID, ", Reason/binary>>
|
||||
)}
|
||||
?NOT_FOUND(<<"Invalid bridge ID, ", Reason/binary>>)
|
||||
end
|
||||
).
|
||||
|
||||
|
@ -93,11 +104,11 @@ get_response_body_schema() ->
|
|||
param_path_operation_cluster() ->
|
||||
{operation,
|
||||
mk(
|
||||
enum([stop, restart]),
|
||||
enum([start, stop, restart]),
|
||||
#{
|
||||
in => path,
|
||||
required => true,
|
||||
example => <<"restart">>,
|
||||
example => <<"start">>,
|
||||
desc => ?DESC("desc_param_path_operation_cluster")
|
||||
}
|
||||
)}.
|
||||
|
@ -105,11 +116,11 @@ param_path_operation_cluster() ->
|
|||
param_path_operation_on_node() ->
|
||||
{operation,
|
||||
mk(
|
||||
enum([stop, restart]),
|
||||
enum([start, stop, restart]),
|
||||
#{
|
||||
in => path,
|
||||
required => true,
|
||||
example => <<"stop">>,
|
||||
example => <<"start">>,
|
||||
desc => ?DESC("desc_param_path_operation_on_node")
|
||||
}
|
||||
)}.
|
||||
|
@ -338,7 +349,7 @@ schema("/bridges/:id") ->
|
|||
responses => #{
|
||||
200 => get_response_body_schema(),
|
||||
404 => error_schema('NOT_FOUND', "Bridge not found"),
|
||||
400 => error_schema(['BAD_REQUEST', 'INVALID_ID'], "Update bridge failed")
|
||||
400 => error_schema('BAD_REQUEST', "Update bridge failed")
|
||||
}
|
||||
},
|
||||
delete => #{
|
||||
|
@ -348,9 +359,11 @@ schema("/bridges/:id") ->
|
|||
parameters => [param_path_id()],
|
||||
responses => #{
|
||||
204 => <<"Bridge deleted">>,
|
||||
400 => error_schema(['INVALID_ID'], "Update bridge failed"),
|
||||
400 => error_schema(
|
||||
'BAD_REQUEST',
|
||||
"Cannot delete bridge while active rules are defined for this bridge"
|
||||
),
|
||||
404 => error_schema('NOT_FOUND', "Bridge not found"),
|
||||
403 => error_schema('FORBIDDEN_REQUEST', "Forbidden operation"),
|
||||
503 => error_schema('SERVICE_UNAVAILABLE', "Service unavailable")
|
||||
}
|
||||
}
|
||||
|
@ -379,7 +392,7 @@ schema("/bridges/:id/metrics/reset") ->
|
|||
parameters => [param_path_id()],
|
||||
responses => #{
|
||||
204 => <<"Reset success">>,
|
||||
400 => error_schema(['BAD_REQUEST'], "RPC Call Failed")
|
||||
404 => error_schema('NOT_FOUND', "Bridge not found")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -395,7 +408,7 @@ schema("/bridges/:id/enable/:enable") ->
|
|||
responses =>
|
||||
#{
|
||||
204 => <<"Success">>,
|
||||
400 => error_schema('INVALID_ID', "Bad bridge ID"),
|
||||
404 => error_schema('NOT_FOUND', "Bridge not found or invalid operation"),
|
||||
503 => error_schema('SERVICE_UNAVAILABLE', "Service unavailable")
|
||||
}
|
||||
}
|
||||
|
@ -413,7 +426,10 @@ schema("/bridges/:id/:operation") ->
|
|||
],
|
||||
responses => #{
|
||||
204 => <<"Operation success">>,
|
||||
400 => error_schema('INVALID_ID', "Bad bridge ID"),
|
||||
400 => error_schema(
|
||||
'BAD_REQUEST', "Problem with configuration of external service"
|
||||
),
|
||||
404 => error_schema('NOT_FOUND', "Bridge not found or invalid operation"),
|
||||
501 => error_schema('NOT_IMPLEMENTED', "Not Implemented"),
|
||||
503 => error_schema('SERVICE_UNAVAILABLE', "Service unavailable")
|
||||
}
|
||||
|
@ -433,8 +449,11 @@ schema("/nodes/:node/bridges/:id/:operation") ->
|
|||
],
|
||||
responses => #{
|
||||
204 => <<"Operation success">>,
|
||||
400 => error_schema('INVALID_ID', "Bad bridge ID"),
|
||||
403 => error_schema('FORBIDDEN_REQUEST', "forbidden operation"),
|
||||
400 => error_schema(
|
||||
'BAD_REQUEST',
|
||||
"Problem with configuration of external service or bridge not enabled"
|
||||
),
|
||||
404 => error_schema('NOT_FOUND', "Bridge or node not found or invalid operation"),
|
||||
501 => error_schema('NOT_IMPLEMENTED', "Not Implemented"),
|
||||
503 => error_schema('SERVICE_UNAVAILABLE', "Service unavailable")
|
||||
}
|
||||
|
@ -459,21 +478,19 @@ schema("/bridges_probe") ->
|
|||
}.
|
||||
|
||||
'/bridges'(post, #{body := #{<<"type">> := BridgeType, <<"name">> := BridgeName} = Conf0}) ->
|
||||
Conf = filter_out_request_body(Conf0),
|
||||
case emqx_bridge:lookup(BridgeType, BridgeName) of
|
||||
{ok, _} ->
|
||||
{400, error_msg('ALREADY_EXISTS', <<"bridge already exists">>)};
|
||||
{error, not_found} ->
|
||||
case ensure_bridge_created(BridgeType, BridgeName, Conf) of
|
||||
ok -> lookup_from_all_nodes(BridgeType, BridgeName, 201);
|
||||
{error, Error} -> {400, Error}
|
||||
end
|
||||
Conf = filter_out_request_body(Conf0),
|
||||
{ok, _} = emqx_bridge:create(BridgeType, BridgeName, Conf),
|
||||
lookup_from_all_nodes(BridgeType, BridgeName, 201)
|
||||
end;
|
||||
'/bridges'(get, _Params) ->
|
||||
{200,
|
||||
zip_bridges([
|
||||
[format_resp(Data, Node) || Data <- emqx_bridge_proto_v1:list_bridges(Node)]
|
||||
|| Node <- mria_mnesia:running_nodes()
|
||||
|| Node <- mria:running_nodes()
|
||||
])}.
|
||||
|
||||
'/bridges/:id'(get, #{bindings := #{id := Id}}) ->
|
||||
|
@ -486,43 +503,38 @@ schema("/bridges_probe") ->
|
|||
{ok, _} ->
|
||||
RawConf = emqx:get_raw_config([bridges, BridgeType, BridgeName], #{}),
|
||||
Conf = deobfuscate(Conf1, RawConf),
|
||||
case ensure_bridge_created(BridgeType, BridgeName, Conf) of
|
||||
ok ->
|
||||
lookup_from_all_nodes(BridgeType, BridgeName, 200);
|
||||
{error, Error} ->
|
||||
{400, Error}
|
||||
end;
|
||||
{ok, _} = emqx_bridge:create(BridgeType, BridgeName, Conf),
|
||||
lookup_from_all_nodes(BridgeType, BridgeName, 200);
|
||||
{error, not_found} ->
|
||||
{404, error_msg('NOT_FOUND', <<"bridge not found">>)}
|
||||
?BRIDGE_NOT_FOUND(BridgeType, BridgeName)
|
||||
end
|
||||
);
|
||||
'/bridges/:id'(delete, #{bindings := #{id := Id}, query_string := Qs}) ->
|
||||
AlsoDeleteActs =
|
||||
case maps:get(<<"also_delete_dep_actions">>, Qs, <<"false">>) of
|
||||
<<"true">> -> true;
|
||||
true -> true;
|
||||
_ -> false
|
||||
end,
|
||||
?TRY_PARSE_ID(
|
||||
Id,
|
||||
case emqx_bridge:lookup(BridgeType, BridgeName) of
|
||||
{ok, _} ->
|
||||
AlsoDeleteActs =
|
||||
case maps:get(<<"also_delete_dep_actions">>, Qs, <<"false">>) of
|
||||
<<"true">> -> true;
|
||||
true -> true;
|
||||
_ -> false
|
||||
end,
|
||||
case emqx_bridge:check_deps_and_remove(BridgeType, BridgeName, AlsoDeleteActs) of
|
||||
{ok, _} ->
|
||||
204;
|
||||
{error, {rules_deps_on_this_bridge, RuleIds}} ->
|
||||
{403,
|
||||
error_msg(
|
||||
'FORBIDDEN_REQUEST',
|
||||
{<<"There're some rules dependent on this bridge">>, RuleIds}
|
||||
)};
|
||||
?BAD_REQUEST(
|
||||
{<<"Cannot delete bridge while active rules are defined for this bridge">>,
|
||||
RuleIds}
|
||||
);
|
||||
{error, timeout} ->
|
||||
{503, error_msg('SERVICE_UNAVAILABLE', <<"request timeout">>)};
|
||||
{error, Reason} ->
|
||||
{500, error_msg('INTERNAL_ERROR', Reason)}
|
||||
end;
|
||||
{error, not_found} ->
|
||||
{404, error_msg('NOT_FOUND', <<"Bridge not found">>)}
|
||||
?BRIDGE_NOT_FOUND(BridgeType, BridgeName)
|
||||
end
|
||||
).
|
||||
|
||||
|
@ -532,13 +544,11 @@ schema("/bridges_probe") ->
|
|||
'/bridges/:id/metrics/reset'(put, #{bindings := #{id := Id}}) ->
|
||||
?TRY_PARSE_ID(
|
||||
Id,
|
||||
case
|
||||
emqx_bridge_resource:reset_metrics(
|
||||
begin
|
||||
ok = emqx_bridge_resource:reset_metrics(
|
||||
emqx_bridge_resource:resource_id(BridgeType, BridgeName)
|
||||
)
|
||||
of
|
||||
ok -> {204};
|
||||
Reason -> {400, error_msg('BAD_REQUEST', Reason)}
|
||||
),
|
||||
{204}
|
||||
end
|
||||
).
|
||||
|
||||
|
@ -549,9 +559,9 @@ schema("/bridges_probe") ->
|
|||
Params1 = maybe_deobfuscate_bridge_probe(Params),
|
||||
case emqx_bridge_resource:create_dry_run(ConnType, maps:remove(<<"type">>, Params1)) of
|
||||
ok ->
|
||||
{204};
|
||||
{error, Error} ->
|
||||
{400, error_msg('TEST_FAILED', Error)}
|
||||
204;
|
||||
{error, Reason} when not is_tuple(Reason); element(1, Reason) =/= 'exit' ->
|
||||
{400, error_msg('TEST_FAILED', to_hr_reason(Reason))}
|
||||
end;
|
||||
BadRequest ->
|
||||
BadRequest
|
||||
|
@ -578,14 +588,14 @@ lookup_from_all_nodes_metrics(BridgeType, BridgeName, SuccCode) ->
|
|||
do_lookup_from_all_nodes(BridgeType, BridgeName, SuccCode, FormatFun).
|
||||
|
||||
do_lookup_from_all_nodes(BridgeType, BridgeName, SuccCode, FormatFun) ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
case is_ok(emqx_bridge_proto_v1:lookup_from_all_nodes(Nodes, BridgeType, BridgeName)) of
|
||||
{ok, [{ok, _} | _] = Results} ->
|
||||
{SuccCode, FormatFun([R || {ok, R} <- Results])};
|
||||
{ok, [{error, not_found} | _]} ->
|
||||
{404, error_msg('NOT_FOUND', <<"not_found">>)};
|
||||
{error, ErrL} ->
|
||||
{500, error_msg('INTERNAL_ERROR', ErrL)}
|
||||
?BRIDGE_NOT_FOUND(BridgeType, BridgeName);
|
||||
{error, Reason} ->
|
||||
{500, error_msg('INTERNAL_ERROR', Reason)}
|
||||
end.
|
||||
|
||||
lookup_from_local_node(BridgeType, BridgeName) ->
|
||||
|
@ -599,13 +609,13 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
|||
Id,
|
||||
case enable_func(Enable) of
|
||||
invalid ->
|
||||
{400, error_msg('BAD_REQUEST', <<"invalid operation">>)};
|
||||
?NOT_FOUND(<<"Invalid operation">>);
|
||||
OperFunc ->
|
||||
case emqx_bridge:disable_enable(OperFunc, BridgeType, BridgeName) of
|
||||
{ok, _} ->
|
||||
{204};
|
||||
204;
|
||||
{error, {pre_config_update, _, bridge_not_found}} ->
|
||||
{404, error_msg('NOT_FOUND', <<"bridge not found">>)};
|
||||
?BRIDGE_NOT_FOUND(BridgeType, BridgeName);
|
||||
{error, {_, _, timeout}} ->
|
||||
{503, error_msg('SERVICE_UNAVAILABLE', <<"request timeout">>)};
|
||||
{error, timeout} ->
|
||||
|
@ -624,10 +634,18 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
|||
Id,
|
||||
case operation_to_all_func(Op) of
|
||||
invalid ->
|
||||
{400, error_msg('BAD_REQUEST', <<"invalid operation">>)};
|
||||
?NOT_FOUND(<<"Invalid operation: ", Op/binary>>);
|
||||
OperFunc ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
call_operation(all, OperFunc, [Nodes, BridgeType, BridgeName])
|
||||
try is_enabled_bridge(BridgeType, BridgeName) of
|
||||
false ->
|
||||
?BRIDGE_NOT_ENABLED;
|
||||
true ->
|
||||
Nodes = mria:running_nodes(),
|
||||
call_operation(all, OperFunc, [Nodes, BridgeType, BridgeName])
|
||||
catch
|
||||
throw:not_found ->
|
||||
?BRIDGE_NOT_FOUND(BridgeType, BridgeName)
|
||||
end
|
||||
end
|
||||
).
|
||||
|
||||
|
@ -639,16 +657,11 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
|||
Id,
|
||||
case node_operation_func(Op) of
|
||||
invalid ->
|
||||
{400, error_msg('BAD_REQUEST', <<"invalid operation">>)};
|
||||
?NOT_FOUND(<<"Invalid operation: ", Op/binary>>);
|
||||
OperFunc ->
|
||||
ConfMap = emqx:get_config([bridges, BridgeType, BridgeName]),
|
||||
case maps:get(enable, ConfMap, false) of
|
||||
try is_enabled_bridge(BridgeType, BridgeName) of
|
||||
false ->
|
||||
{403,
|
||||
error_msg(
|
||||
'FORBIDDEN_REQUEST',
|
||||
<<"forbidden operation: bridge disabled">>
|
||||
)};
|
||||
?BRIDGE_NOT_ENABLED;
|
||||
true ->
|
||||
case emqx_misc:safe_to_existing_atom(Node, utf8) of
|
||||
{ok, TargetNode} ->
|
||||
|
@ -656,12 +669,24 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
|||
TargetNode, BridgeType, BridgeName
|
||||
]);
|
||||
{error, _} ->
|
||||
{400, error_msg('INVALID_NODE', <<"invalid node">>)}
|
||||
?NOT_FOUND(<<"Invalid node name: ", Node/binary>>)
|
||||
end
|
||||
catch
|
||||
throw:not_found ->
|
||||
?BRIDGE_NOT_FOUND(BridgeType, BridgeName)
|
||||
end
|
||||
end
|
||||
).
|
||||
|
||||
is_enabled_bridge(BridgeType, BridgeName) ->
|
||||
try emqx:get_config([bridges, BridgeType, BridgeName]) of
|
||||
ConfMap ->
|
||||
maps:get(enable, ConfMap, false)
|
||||
catch
|
||||
error:{config_not_found, _} ->
|
||||
throw(not_found)
|
||||
end.
|
||||
|
||||
node_operation_func(<<"restart">>) -> restart_bridge_to_node;
|
||||
node_operation_func(<<"start">>) -> start_bridge_to_node;
|
||||
node_operation_func(<<"stop">>) -> stop_bridge_to_node;
|
||||
|
@ -676,12 +701,6 @@ enable_func(<<"true">>) -> enable;
|
|||
enable_func(<<"false">>) -> disable;
|
||||
enable_func(_) -> invalid.
|
||||
|
||||
ensure_bridge_created(BridgeType, BridgeName, Conf) ->
|
||||
case emqx_bridge:create(BridgeType, BridgeName, Conf) of
|
||||
{ok, _} -> ok;
|
||||
{error, Reason} -> {error, error_msg('BAD_REQUEST', Reason)}
|
||||
end.
|
||||
|
||||
zip_bridges([BridgesFirstNode | _] = BridgesAllNodes) ->
|
||||
lists:foldl(
|
||||
fun(#{type := Type, name := Name}, Acc) ->
|
||||
|
@ -892,7 +911,7 @@ is_ok(ResL) ->
|
|||
)
|
||||
of
|
||||
[] -> {ok, [Res || {ok, Res} <- ResL]};
|
||||
ErrL -> {error, ErrL}
|
||||
ErrL -> hd(ErrL)
|
||||
end.
|
||||
|
||||
filter_out_request_body(Conf) ->
|
||||
|
@ -918,12 +937,10 @@ bin(S) when is_atom(S) ->
|
|||
bin(S) when is_binary(S) ->
|
||||
S.
|
||||
|
||||
call_operation(NodeOrAll, OperFunc, Args) ->
|
||||
call_operation(NodeOrAll, OperFunc, Args = [_Nodes, BridgeType, BridgeName]) ->
|
||||
case is_ok(do_bpapi_call(NodeOrAll, OperFunc, Args)) of
|
||||
ok ->
|
||||
{204};
|
||||
{ok, _} ->
|
||||
{204};
|
||||
Ok when Ok =:= ok; is_tuple(Ok), element(1, Ok) =:= ok ->
|
||||
204;
|
||||
{error, not_implemented} ->
|
||||
%% Should only happen if we call `start` on a node that is
|
||||
%% still on an older bpapi version that doesn't support it.
|
||||
|
@ -941,8 +958,12 @@ call_operation(NodeOrAll, OperFunc, Args) ->
|
|||
)
|
||||
)
|
||||
)};
|
||||
{error, Reason} ->
|
||||
{500, error_msg('INTERNAL_ERROR', Reason)}
|
||||
{error, not_found} ->
|
||||
?BRIDGE_NOT_FOUND(BridgeType, BridgeName);
|
||||
{error, {node_not_found, Node}} ->
|
||||
?NOT_FOUND(<<"Node not found: ", (atom_to_binary(Node))/binary>>);
|
||||
{error, Reason} when not is_tuple(Reason); element(1, Reason) =/= 'exit' ->
|
||||
?BAD_REQUEST(to_hr_reason(Reason))
|
||||
end.
|
||||
|
||||
maybe_try_restart(all, start_bridges_to_all_nodes, Args) ->
|
||||
|
@ -950,14 +971,19 @@ maybe_try_restart(all, start_bridges_to_all_nodes, Args) ->
|
|||
maybe_try_restart(Node, start_bridge_to_node, Args) ->
|
||||
call_operation(Node, restart_bridge_to_node, Args);
|
||||
maybe_try_restart(_, _, _) ->
|
||||
{501}.
|
||||
501.
|
||||
|
||||
do_bpapi_call(all, Call, Args) ->
|
||||
maybe_unwrap(
|
||||
do_bpapi_call_vsn(emqx_bpapi:supported_version(emqx_bridge), Call, Args)
|
||||
);
|
||||
do_bpapi_call(Node, Call, Args) ->
|
||||
do_bpapi_call_vsn(emqx_bpapi:supported_version(Node, emqx_bridge), Call, Args).
|
||||
case lists:member(Node, mria:running_nodes()) of
|
||||
true ->
|
||||
do_bpapi_call_vsn(emqx_bpapi:supported_version(Node, emqx_bridge), Call, Args);
|
||||
false ->
|
||||
{error, {node_not_found, Node}}
|
||||
end.
|
||||
|
||||
do_bpapi_call_vsn(SupportedVersion, Call, Args) ->
|
||||
case lists:member(SupportedVersion, supported_versions(Call)) of
|
||||
|
@ -976,6 +1002,19 @@ supported_versions(start_bridge_to_node) -> [2];
|
|||
supported_versions(start_bridges_to_all_nodes) -> [2];
|
||||
supported_versions(_Call) -> [1, 2].
|
||||
|
||||
to_hr_reason(nxdomain) ->
|
||||
<<"Host not found">>;
|
||||
to_hr_reason(econnrefused) ->
|
||||
<<"Connection refused">>;
|
||||
to_hr_reason({unauthorized_client, _}) ->
|
||||
<<"Unauthorized client">>;
|
||||
to_hr_reason({not_authorized, _}) ->
|
||||
<<"Not authorized">>;
|
||||
to_hr_reason({malformed_username_or_password, _}) ->
|
||||
<<"Malformed username or password">>;
|
||||
to_hr_reason(Reason) ->
|
||||
Reason.
|
||||
|
||||
redact(Term) ->
|
||||
emqx_misc:redact(Term).
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ parse_bridge_id(BridgeId) ->
|
|||
{to_type_atom(Type), validate_name(Name)};
|
||||
_ ->
|
||||
invalid_bridge_id(
|
||||
<<"should be of forst {type}:{name}, but got ", BridgeId/binary>>
|
||||
<<"should be of pattern {type}:{name}, but got ", BridgeId/binary>>
|
||||
)
|
||||
end.
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ init_per_suite(Config) ->
|
|||
_ = application:stop(emqx_resource),
|
||||
_ = application:stop(emqx_connector),
|
||||
ok = emqx_mgmt_api_test_util:init_suite(
|
||||
[emqx_rule_engine, emqx_bridge]
|
||||
[emqx_rule_engine, emqx_bridge, emqx_authn]
|
||||
),
|
||||
ok = emqx_common_test_helpers:load_config(
|
||||
emqx_rule_engine_schema,
|
||||
|
@ -83,7 +83,8 @@ init_per_suite(Config) ->
|
|||
Config.
|
||||
|
||||
end_per_suite(_Config) ->
|
||||
emqx_mgmt_api_test_util:end_suite([emqx_rule_engine, emqx_bridge]),
|
||||
emqx_mgmt_api_test_util:end_suite([emqx_rule_engine, emqx_bridge, emqx_authn]),
|
||||
mria:clear_table(emqx_authn_mnesia),
|
||||
ok.
|
||||
|
||||
init_per_testcase(t_broken_bpapi_vsn, Config) ->
|
||||
|
@ -195,6 +196,9 @@ t_http_crud_apis(Config) ->
|
|||
%% assert we there's no bridges at first
|
||||
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []),
|
||||
|
||||
{ok, 404, _} = request(get, uri(["bridges", "foo"]), []),
|
||||
{ok, 404, _} = request(get, uri(["bridges", "webhook:foo"]), []),
|
||||
|
||||
%% then we add a webhook bridge, using POST
|
||||
%% POST /bridges/ will create a bridge
|
||||
URL1 = ?URL(Port, "path1"),
|
||||
|
@ -213,7 +217,7 @@ t_http_crud_apis(Config) ->
|
|||
<<"status">> := _,
|
||||
<<"node_status">> := [_ | _],
|
||||
<<"url">> := URL1
|
||||
} = jsx:decode(Bridge),
|
||||
} = emqx_json:decode(Bridge, [return_maps]),
|
||||
|
||||
BridgeID = emqx_bridge_resource:bridge_id(?BRIDGE_TYPE, Name),
|
||||
%% send an message to emqx and the message should be forwarded to the HTTP server
|
||||
|
@ -250,7 +254,7 @@ t_http_crud_apis(Config) ->
|
|||
<<"node_status">> := [_ | _],
|
||||
<<"url">> := URL2
|
||||
},
|
||||
jsx:decode(Bridge2)
|
||||
emqx_json:decode(Bridge2, [return_maps])
|
||||
),
|
||||
|
||||
%% list all bridges again, assert Bridge2 is in it
|
||||
|
@ -268,7 +272,7 @@ t_http_crud_apis(Config) ->
|
|||
<<"url">> := URL2
|
||||
}
|
||||
],
|
||||
jsx:decode(Bridge2Str)
|
||||
emqx_json:decode(Bridge2Str, [return_maps])
|
||||
),
|
||||
|
||||
%% get the bridge by id
|
||||
|
@ -282,7 +286,7 @@ t_http_crud_apis(Config) ->
|
|||
<<"node_status">> := [_ | _],
|
||||
<<"url">> := URL2
|
||||
},
|
||||
jsx:decode(Bridge3Str)
|
||||
emqx_json:decode(Bridge3Str, [return_maps])
|
||||
),
|
||||
|
||||
%% send an message to emqx again, check the path has been changed
|
||||
|
@ -311,19 +315,30 @@ t_http_crud_apis(Config) ->
|
|||
),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"code">> := _,
|
||||
<<"message">> := <<"bridge not found">>
|
||||
<<"code">> := <<"NOT_FOUND">>,
|
||||
<<"message">> := _
|
||||
},
|
||||
jsx:decode(ErrMsg2)
|
||||
emqx_json:decode(ErrMsg2, [return_maps])
|
||||
),
|
||||
|
||||
%% try delete bad bridge id
|
||||
{ok, 404, BadId} = request(delete, uri(["bridges", "foo"]), []),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"code">> := <<"NOT_FOUND">>,
|
||||
<<"message">> := <<"Invalid bridge ID", _/binary>>
|
||||
},
|
||||
emqx_json:decode(BadId, [return_maps])
|
||||
),
|
||||
|
||||
%% Deleting a non-existing bridge should result in an error
|
||||
{ok, 404, ErrMsg3} = request(delete, uri(["bridges", BridgeID]), []),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"code">> := _,
|
||||
<<"message">> := <<"Bridge not found">>
|
||||
<<"code">> := <<"NOT_FOUND">>,
|
||||
<<"message">> := _
|
||||
},
|
||||
jsx:decode(ErrMsg3)
|
||||
emqx_json:decode(ErrMsg3, [return_maps])
|
||||
),
|
||||
ok.
|
||||
|
||||
|
@ -401,14 +416,17 @@ t_check_dependent_actions_on_delete(Config) ->
|
|||
<<"sql">> => <<"SELECT * from \"t\"">>
|
||||
}
|
||||
),
|
||||
#{<<"id">> := RuleId} = jsx:decode(Rule),
|
||||
%% delete the bridge should fail because there is a rule depenents on it
|
||||
{ok, 403, _} = request(delete, uri(["bridges", BridgeID]), []),
|
||||
#{<<"id">> := RuleId} = emqx_json:decode(Rule, [return_maps]),
|
||||
%% deleting the bridge should fail because there is a rule that depends on it
|
||||
{ok, 400, _} = request(
|
||||
delete, uri(["bridges", BridgeID]) ++ "?also_delete_dep_actions=false", []
|
||||
),
|
||||
%% delete the rule first
|
||||
{ok, 204, <<>>} = request(delete, uri(["rules", RuleId]), []),
|
||||
%% then delete the bridge is OK
|
||||
{ok, 204, <<>>} = request(delete, uri(["bridges", BridgeID]), []),
|
||||
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []),
|
||||
|
||||
ok.
|
||||
|
||||
t_cascade_delete_actions(Config) ->
|
||||
|
@ -436,18 +454,39 @@ t_cascade_delete_actions(Config) ->
|
|||
<<"sql">> => <<"SELECT * from \"t\"">>
|
||||
}
|
||||
),
|
||||
#{<<"id">> := RuleId} = jsx:decode(Rule),
|
||||
#{<<"id">> := RuleId} = emqx_json:decode(Rule, [return_maps]),
|
||||
%% delete the bridge will also delete the actions from the rules
|
||||
{ok, 204, _} = request(delete, uri(["bridges", BridgeID]) ++ "?also_delete_dep_actions", []),
|
||||
{ok, 204, _} = request(
|
||||
delete, uri(["bridges", BridgeID]) ++ "?also_delete_dep_actions=true", []
|
||||
),
|
||||
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []),
|
||||
{ok, 200, Rule1} = request(get, uri(["rules", RuleId]), []),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"actions">> := []
|
||||
},
|
||||
jsx:decode(Rule1)
|
||||
emqx_json:decode(Rule1, [return_maps])
|
||||
),
|
||||
{ok, 204, <<>>} = request(delete, uri(["rules", RuleId]), []),
|
||||
|
||||
{ok, 201, _} = request(
|
||||
post,
|
||||
uri(["bridges"]),
|
||||
?HTTP_BRIDGE(URL1, ?BRIDGE_TYPE, Name)
|
||||
),
|
||||
{ok, 201, _} = request(
|
||||
post,
|
||||
uri(["rules"]),
|
||||
#{
|
||||
<<"name">> => <<"t_http_crud_apis">>,
|
||||
<<"enable">> => true,
|
||||
<<"actions">> => [BridgeID],
|
||||
<<"sql">> => <<"SELECT * from \"t\"">>
|
||||
}
|
||||
),
|
||||
|
||||
{ok, 204, _} = request(delete, uri(["bridges", BridgeID]) ++ "?also_delete_dep_actions", []),
|
||||
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []),
|
||||
ok.
|
||||
|
||||
t_broken_bpapi_vsn(Config) ->
|
||||
|
@ -485,6 +524,18 @@ t_old_bpapi_vsn(Config) ->
|
|||
ok.
|
||||
|
||||
t_start_stop_bridges_node(Config) ->
|
||||
{ok, 404, _} =
|
||||
request(
|
||||
post,
|
||||
uri(["nodes", "thisbetterbenotanatomyet", "bridges", "webhook:foo", start]),
|
||||
<<"">>
|
||||
),
|
||||
{ok, 404, _} =
|
||||
request(
|
||||
post,
|
||||
uri(["nodes", "undefined", "bridges", "webhook:foo", start]),
|
||||
<<"">>
|
||||
),
|
||||
do_start_stop_bridges(node, Config).
|
||||
|
||||
t_start_stop_bridges_cluster(Config) ->
|
||||
|
@ -510,34 +561,42 @@ do_start_stop_bridges(Type, Config) ->
|
|||
<<"status">> := <<"connected">>,
|
||||
<<"node_status">> := [_ | _],
|
||||
<<"url">> := URL1
|
||||
} = jsx:decode(Bridge),
|
||||
} = emqx_json:decode(Bridge, [return_maps]),
|
||||
BridgeID = emqx_bridge_resource:bridge_id(?BRIDGE_TYPE, Name),
|
||||
%% stop it
|
||||
{ok, 204, <<>>} = request(post, operation_path(Type, stop, BridgeID), <<"">>),
|
||||
{ok, 200, Bridge2} = request(get, uri(["bridges", BridgeID]), []),
|
||||
?assertMatch(#{<<"status">> := <<"stopped">>}, jsx:decode(Bridge2)),
|
||||
?assertMatch(#{<<"status">> := <<"stopped">>}, emqx_json:decode(Bridge2, [return_maps])),
|
||||
%% start again
|
||||
{ok, 204, <<>>} = request(post, operation_path(Type, start, BridgeID), <<"">>),
|
||||
{ok, 200, Bridge3} = request(get, uri(["bridges", BridgeID]), []),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, jsx:decode(Bridge3)),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, emqx_json:decode(Bridge3, [return_maps])),
|
||||
%% start a started bridge
|
||||
{ok, 204, <<>>} = request(post, operation_path(Type, start, BridgeID), <<"">>),
|
||||
{ok, 200, Bridge3_1} = request(get, uri(["bridges", BridgeID]), []),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, jsx:decode(Bridge3_1)),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, emqx_json:decode(Bridge3_1, [return_maps])),
|
||||
%% restart an already started bridge
|
||||
{ok, 204, <<>>} = request(post, operation_path(Type, restart, BridgeID), <<"">>),
|
||||
{ok, 200, Bridge3} = request(get, uri(["bridges", BridgeID]), []),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, jsx:decode(Bridge3)),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, emqx_json:decode(Bridge3, [return_maps])),
|
||||
%% stop it again
|
||||
{ok, 204, <<>>} = request(post, operation_path(Type, stop, BridgeID), <<"">>),
|
||||
%% restart a stopped bridge
|
||||
{ok, 204, <<>>} = request(post, operation_path(Type, restart, BridgeID), <<"">>),
|
||||
{ok, 200, Bridge4} = request(get, uri(["bridges", BridgeID]), []),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, jsx:decode(Bridge4)),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, emqx_json:decode(Bridge4, [return_maps])),
|
||||
|
||||
{ok, 404, _} = request(post, operation_path(Type, invalidop, BridgeID), <<"">>),
|
||||
|
||||
%% delete the bridge
|
||||
{ok, 204, <<>>} = request(delete, uri(["bridges", BridgeID]), []),
|
||||
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []),
|
||||
|
||||
%% Fail parse-id check
|
||||
{ok, 404, _} = request(post, operation_path(Type, start, <<"wreckbook_fugazi">>), <<"">>),
|
||||
%% Looks ok but doesn't exist
|
||||
{ok, 404, _} = request(post, operation_path(Type, start, <<"webhook:cptn_hook">>), <<"">>),
|
||||
|
||||
%% Create broken bridge
|
||||
{ListenPort, Sock} = listen_on_random_port(),
|
||||
%% Connecting to this endpoint should always timeout
|
||||
|
@ -555,7 +614,7 @@ do_start_stop_bridges(Type, Config) ->
|
|||
<<"server">> := BadServer,
|
||||
<<"status">> := <<"connecting">>,
|
||||
<<"node_status">> := [_ | _]
|
||||
} = jsx:decode(BadBridge1),
|
||||
} = emqx_json:decode(BadBridge1, [return_maps]),
|
||||
BadBridgeID = emqx_bridge_resource:bridge_id(?BRIDGE_TYPE_MQTT, BadName),
|
||||
?assertMatch(
|
||||
{ok, SC, _} when SC == 500 orelse SC == 503,
|
||||
|
@ -584,33 +643,39 @@ t_enable_disable_bridges(Config) ->
|
|||
<<"status">> := <<"connected">>,
|
||||
<<"node_status">> := [_ | _],
|
||||
<<"url">> := URL1
|
||||
} = jsx:decode(Bridge),
|
||||
} = emqx_json:decode(Bridge, [return_maps]),
|
||||
BridgeID = emqx_bridge_resource:bridge_id(?BRIDGE_TYPE, Name),
|
||||
%% disable it
|
||||
{ok, 204, <<>>} = request(put, enable_path(false, BridgeID), <<"">>),
|
||||
{ok, 200, Bridge2} = request(get, uri(["bridges", BridgeID]), []),
|
||||
?assertMatch(#{<<"status">> := <<"stopped">>}, jsx:decode(Bridge2)),
|
||||
?assertMatch(#{<<"status">> := <<"stopped">>}, emqx_json:decode(Bridge2, [return_maps])),
|
||||
%% enable again
|
||||
{ok, 204, <<>>} = request(put, enable_path(true, BridgeID), <<"">>),
|
||||
{ok, 200, Bridge3} = request(get, uri(["bridges", BridgeID]), []),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, jsx:decode(Bridge3)),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, emqx_json:decode(Bridge3, [return_maps])),
|
||||
%% enable an already started bridge
|
||||
{ok, 204, <<>>} = request(put, enable_path(true, BridgeID), <<"">>),
|
||||
{ok, 200, Bridge3} = request(get, uri(["bridges", BridgeID]), []),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, jsx:decode(Bridge3)),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, emqx_json:decode(Bridge3, [return_maps])),
|
||||
%% disable it again
|
||||
{ok, 204, <<>>} = request(put, enable_path(false, BridgeID), <<"">>),
|
||||
|
||||
{ok, 403, Res} = request(post, operation_path(node, restart, BridgeID), <<"">>),
|
||||
%% bad param
|
||||
{ok, 404, _} = request(put, enable_path(foo, BridgeID), <<"">>),
|
||||
{ok, 404, _} = request(put, enable_path(true, "foo"), <<"">>),
|
||||
{ok, 404, _} = request(put, enable_path(true, "webhook:foo"), <<"">>),
|
||||
|
||||
{ok, 400, Res} = request(post, operation_path(node, start, BridgeID), <<"">>),
|
||||
?assertEqual(
|
||||
<<"{\"code\":\"FORBIDDEN_REQUEST\",\"message\":\"forbidden operation: bridge disabled\"}">>,
|
||||
<<"{\"code\":\"BAD_REQUEST\",\"message\":\"Forbidden operation, bridge not enabled\"}">>,
|
||||
Res
|
||||
),
|
||||
{ok, 400, Res} = request(post, operation_path(cluster, start, BridgeID), <<"">>),
|
||||
|
||||
%% enable a stopped bridge
|
||||
{ok, 204, <<>>} = request(put, enable_path(true, BridgeID), <<"">>),
|
||||
{ok, 200, Bridge4} = request(get, uri(["bridges", BridgeID]), []),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, jsx:decode(Bridge4)),
|
||||
?assertMatch(#{<<"status">> := <<"connected">>}, emqx_json:decode(Bridge4, [return_maps])),
|
||||
%% delete the bridge
|
||||
{ok, 204, <<>>} = request(delete, uri(["bridges", BridgeID]), []),
|
||||
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []).
|
||||
|
@ -635,7 +700,7 @@ t_reset_bridges(Config) ->
|
|||
<<"status">> := <<"connected">>,
|
||||
<<"node_status">> := [_ | _],
|
||||
<<"url">> := URL1
|
||||
} = jsx:decode(Bridge),
|
||||
} = emqx_json:decode(Bridge, [return_maps]),
|
||||
BridgeID = emqx_bridge_resource:bridge_id(?BRIDGE_TYPE, Name),
|
||||
{ok, 204, <<>>} = request(put, uri(["bridges", BridgeID, "metrics/reset"]), []),
|
||||
|
||||
|
@ -703,7 +768,7 @@ t_bridges_probe(Config) ->
|
|||
<<"code">> := <<"TEST_FAILED">>,
|
||||
<<"message">> := _
|
||||
},
|
||||
jsx:decode(NxDomain)
|
||||
emqx_json:decode(NxDomain, [return_maps])
|
||||
),
|
||||
|
||||
{ok, 204, _} = request(
|
||||
|
@ -720,9 +785,81 @@ t_bridges_probe(Config) ->
|
|||
?assertMatch(
|
||||
#{
|
||||
<<"code">> := <<"TEST_FAILED">>,
|
||||
<<"message">> := <<"econnrefused">>
|
||||
<<"message">> := <<"Connection refused">>
|
||||
},
|
||||
jsx:decode(ConnRefused)
|
||||
emqx_json:decode(ConnRefused, [return_maps])
|
||||
),
|
||||
|
||||
{ok, 400, HostNotFound} = request(
|
||||
post,
|
||||
uri(["bridges_probe"]),
|
||||
?MQTT_BRIDGE(<<"nohost:2883">>)
|
||||
),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"code">> := <<"TEST_FAILED">>,
|
||||
<<"message">> := <<"Host not found">>
|
||||
},
|
||||
emqx_json:decode(HostNotFound, [return_maps])
|
||||
),
|
||||
|
||||
AuthnConfig = #{
|
||||
<<"mechanism">> => <<"password_based">>,
|
||||
<<"backend">> => <<"built_in_database">>,
|
||||
<<"user_id_type">> => <<"username">>
|
||||
},
|
||||
Chain = 'mqtt:global',
|
||||
emqx:update_config(
|
||||
[authentication],
|
||||
{create_authenticator, Chain, AuthnConfig}
|
||||
),
|
||||
User = #{user_id => <<"u">>, password => <<"p">>},
|
||||
AuthenticatorID = <<"password_based:built_in_database">>,
|
||||
{ok, _} = emqx_authentication:add_user(
|
||||
Chain,
|
||||
AuthenticatorID,
|
||||
User
|
||||
),
|
||||
|
||||
{ok, 400, Unauthorized} = request(
|
||||
post,
|
||||
uri(["bridges_probe"]),
|
||||
?MQTT_BRIDGE(<<"127.0.0.1:1883">>)#{<<"proto_ver">> => <<"v4">>}
|
||||
),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"code">> := <<"TEST_FAILED">>,
|
||||
<<"message">> := <<"Unauthorized client">>
|
||||
},
|
||||
emqx_json:decode(Unauthorized, [return_maps])
|
||||
),
|
||||
|
||||
{ok, 400, Malformed} = request(
|
||||
post,
|
||||
uri(["bridges_probe"]),
|
||||
?MQTT_BRIDGE(<<"127.0.0.1:1883">>)#{
|
||||
<<"proto_ver">> => <<"v4">>, <<"password">> => <<"mySecret">>, <<"username">> => <<"u">>
|
||||
}
|
||||
),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"code">> := <<"TEST_FAILED">>,
|
||||
<<"message">> := <<"Malformed username or password">>
|
||||
},
|
||||
emqx_json:decode(Malformed, [return_maps])
|
||||
),
|
||||
|
||||
{ok, 400, NotAuthorized} = request(
|
||||
post,
|
||||
uri(["bridges_probe"]),
|
||||
?MQTT_BRIDGE(<<"127.0.0.1:1883">>)
|
||||
),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"code">> := <<"TEST_FAILED">>,
|
||||
<<"message">> := <<"Not authorized">>
|
||||
},
|
||||
emqx_json:decode(NotAuthorized, [return_maps])
|
||||
),
|
||||
|
||||
{ok, 400, BadReq} = request(
|
||||
|
@ -730,7 +867,7 @@ t_bridges_probe(Config) ->
|
|||
uri(["bridges_probe"]),
|
||||
?BRIDGE(<<"bad_bridge">>, <<"unknown_type">>)
|
||||
),
|
||||
?assertMatch(#{<<"code">> := <<"BAD_REQUEST">>}, jsx:decode(BadReq)),
|
||||
?assertMatch(#{<<"code">> := <<"BAD_REQUEST">>}, emqx_json:decode(BadReq, [return_maps])),
|
||||
ok.
|
||||
|
||||
t_metrics(Config) ->
|
||||
|
@ -756,7 +893,7 @@ t_metrics(Config) ->
|
|||
<<"status">> := _,
|
||||
<<"node_status">> := [_ | _],
|
||||
<<"url">> := URL1
|
||||
} = jsx:decode(Bridge),
|
||||
} = emqx_json:decode(Bridge, [return_maps]),
|
||||
|
||||
BridgeID = emqx_bridge_resource:bridge_id(?BRIDGE_TYPE, Name),
|
||||
|
||||
|
@ -767,12 +904,12 @@ t_metrics(Config) ->
|
|||
<<"metrics">> := #{<<"success">> := 0},
|
||||
<<"node_metrics">> := [_ | _]
|
||||
},
|
||||
jsx:decode(Bridge1Str)
|
||||
emqx_json:decode(Bridge1Str, [return_maps])
|
||||
),
|
||||
|
||||
%% check that the bridge doesn't contain metrics anymore
|
||||
{ok, 200, Bridge2Str} = request(get, uri(["bridges", BridgeID]), []),
|
||||
Decoded = jsx:decode(Bridge2Str),
|
||||
Decoded = emqx_json:decode(Bridge2Str, [return_maps]),
|
||||
?assertNot(maps:is_key(<<"metrics">>, Decoded)),
|
||||
?assertNot(maps:is_key(<<"node_metrics">>, Decoded)),
|
||||
|
||||
|
@ -802,7 +939,7 @@ t_metrics(Config) ->
|
|||
<<"metrics">> := #{<<"success">> := _},
|
||||
<<"node_metrics">> := [_ | _]
|
||||
},
|
||||
jsx:decode(Bridge3Str)
|
||||
emqx_json:decode(Bridge3Str, [return_maps])
|
||||
),
|
||||
|
||||
%% check for non-empty metrics when listing all bridges
|
||||
|
@ -814,7 +951,7 @@ t_metrics(Config) ->
|
|||
<<"node_metrics">> := [_ | _]
|
||||
}
|
||||
],
|
||||
jsx:decode(BridgesStr)
|
||||
emqx_json:decode(BridgesStr, [return_maps])
|
||||
),
|
||||
ok.
|
||||
|
||||
|
|
|
@ -359,9 +359,13 @@ t_mqtt_conn_bridge_egress(_) ->
|
|||
?assertMatch(<<ResourceID:Size/binary, _/binary>>, Msg#message.from),
|
||||
|
||||
%% verify the metrics of the bridge
|
||||
?assertMetrics(
|
||||
#{<<"matched">> := 1, <<"success">> := 1, <<"failed">> := 0},
|
||||
BridgeIDEgress
|
||||
?retry(
|
||||
_Interval = 200,
|
||||
_Attempts = 5,
|
||||
?assertMetrics(
|
||||
#{<<"matched">> := 1, <<"success">> := 1, <<"failed">> := 0},
|
||||
BridgeIDEgress
|
||||
)
|
||||
),
|
||||
|
||||
%% delete the bridge
|
||||
|
@ -402,9 +406,13 @@ t_mqtt_conn_bridge_egress_no_payload_template(_) ->
|
|||
?assertMatch(#{<<"payload">> := Payload}, jsx:decode(Msg#message.payload)),
|
||||
|
||||
%% verify the metrics of the bridge
|
||||
?assertMetrics(
|
||||
#{<<"matched">> := 1, <<"success">> := 1, <<"failed">> := 0},
|
||||
BridgeIDEgress
|
||||
?retry(
|
||||
_Interval = 200,
|
||||
_Attempts = 5,
|
||||
?assertMetrics(
|
||||
#{<<"matched">> := 1, <<"success">> := 1, <<"failed">> := 0},
|
||||
BridgeIDEgress
|
||||
)
|
||||
),
|
||||
|
||||
%% delete the bridge
|
||||
|
|
|
@ -512,7 +512,7 @@ do_alarm(Fun, Res, #{tnx_id := Id} = Meta) ->
|
|||
|
||||
wait_for_all_nodes_commit(TnxId, Delay, Remain) ->
|
||||
Lagging = lagging_nodes(TnxId),
|
||||
Stopped = Lagging -- mria_mnesia:running_nodes(),
|
||||
Stopped = Lagging -- mria:running_nodes(),
|
||||
case Lagging -- Stopped of
|
||||
[] when Stopped =:= [] ->
|
||||
ok;
|
||||
|
@ -537,7 +537,7 @@ wait_for_nodes_commit(RequiredSyncs, TnxId, Delay, Remain) ->
|
|||
[] ->
|
||||
ok;
|
||||
Lagging ->
|
||||
Stopped = Lagging -- mria_mnesia:running_nodes(),
|
||||
Stopped = Lagging -- mria:running_nodes(),
|
||||
case Stopped of
|
||||
[] -> {peers_lagging, Lagging};
|
||||
_ -> {stopped_nodes, Stopped}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{application, emqx_conf, [
|
||||
{description, "EMQX configuration management"},
|
||||
{vsn, "0.1.13"},
|
||||
{vsn, "0.1.14"},
|
||||
{registered, []},
|
||||
{mod, {emqx_conf_app, []}},
|
||||
{applications, [kernel, stdlib, emqx_ctl]},
|
||||
|
|
|
@ -146,8 +146,7 @@ dump_schema(Dir, SchemaModule, I18nFile) ->
|
|||
fun(Lang) ->
|
||||
gen_config_md(Dir, I18nFile, SchemaModule, Lang),
|
||||
gen_api_schema_json(Dir, I18nFile, Lang),
|
||||
ExampleDir = filename:join(filename:dirname(filename:dirname(I18nFile)), "etc"),
|
||||
gen_example_conf(ExampleDir, I18nFile, SchemaModule, Lang)
|
||||
gen_example_conf(Dir, I18nFile, SchemaModule, Lang)
|
||||
end,
|
||||
[en, zh]
|
||||
),
|
||||
|
|
|
@ -33,7 +33,7 @@ admins(["status"]) ->
|
|||
status();
|
||||
admins(["skip"]) ->
|
||||
status(),
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
lists:foreach(fun emqx_cluster_rpc:skip_failed_commit/1, Nodes),
|
||||
status();
|
||||
admins(["skip", Node0]) ->
|
||||
|
@ -46,13 +46,13 @@ admins(["tnxid", TnxId0]) ->
|
|||
emqx_ctl:print("~p~n", [emqx_cluster_rpc:query(TnxId)]);
|
||||
admins(["fast_forward"]) ->
|
||||
status(),
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
TnxId = emqx_cluster_rpc:latest_tnx_id(),
|
||||
lists:foreach(fun(N) -> emqx_cluster_rpc:fast_forward_to_commit(N, TnxId) end, Nodes),
|
||||
status();
|
||||
admins(["fast_forward", ToTnxId]) ->
|
||||
status(),
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
TnxId = list_to_integer(ToTnxId),
|
||||
lists:foreach(fun(N) -> emqx_cluster_rpc:fast_forward_to_commit(N, TnxId) end, Nodes),
|
||||
status();
|
||||
|
|
|
@ -48,14 +48,14 @@ init_per_suite(Config) ->
|
|||
meck:new(emqx_alarm, [non_strict, passthrough, no_link]),
|
||||
meck:expect(emqx_alarm, activate, 3, ok),
|
||||
meck:expect(emqx_alarm, deactivate, 3, ok),
|
||||
meck:new(mria_mnesia, [non_strict, passthrough, no_link]),
|
||||
meck:expect(mria_mnesia, running_nodes, 0, [?NODE1, {node(), ?NODE2}, {node(), ?NODE3}]),
|
||||
meck:new(mria, [non_strict, passthrough, no_link]),
|
||||
meck:expect(mria, running_nodes, 0, [?NODE1, {node(), ?NODE2}, {node(), ?NODE3}]),
|
||||
Config.
|
||||
|
||||
end_per_suite(_Config) ->
|
||||
ekka:stop(),
|
||||
mria:stop(),
|
||||
meck:unload(mria_mnesia),
|
||||
meck:unload(mria),
|
||||
mria_mnesia:delete_schema(),
|
||||
meck:unload(emqx_alarm),
|
||||
ok.
|
||||
|
|
|
@ -177,8 +177,8 @@ The MongoDB default port 27017 is used if `[:Port]` is not specified."""
|
|||
|
||||
heartbeat_period {
|
||||
desc {
|
||||
en: "Controls when the driver checks the state of the MongoDB deployment. Specify the interval between checks, counted from the end of the previous check until the beginning of the next one."
|
||||
zh: "控制驱动程序何时检查MongoDB部署的状态。指定检查的间隔时间,从上一次检查结束到下一次检查开始计算。"
|
||||
en: "Controls when the driver checks the state of the MongoDB deployment. Specify the interval between checks, counted from the end of the previous check until the beginning of the next one. If the number of connections is increased (which will happen, for example, if you increase the pool size), you may need to increase this period as well to avoid creating too many log entries in the MongoDB log file."
|
||||
zh: "控制驱动程序何时检查MongoDB部署的状态。指定检查的间隔时间,从上一次检查结束到下一次检查开始计算。如果连接数增加(例如,如果你增加池子的大小,就会发生这种情况),你可能也需要增加这个周期,以避免在MongoDB日志文件中创建太多的日志条目。"
|
||||
}
|
||||
label {
|
||||
en: "Heartbeat period"
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
-define(MONGO_DEFAULT_PORT, 27017).
|
||||
-define(REDIS_DEFAULT_PORT, 6379).
|
||||
-define(PGSQL_DEFAULT_PORT, 5432).
|
||||
-define(CLICKHOUSE_DEFAULT_PORT, 8123).
|
||||
|
||||
-define(AUTO_RECONNECT_INTERVAL, 2).
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
{application, emqx_connector, [
|
||||
{description, "EMQX Data Integration Connectors"},
|
||||
{vsn, "0.1.16"},
|
||||
{vsn, "0.1.17"},
|
||||
{registered, []},
|
||||
{mod, {emqx_connector_app, []}},
|
||||
{applications, [
|
||||
|
|
|
@ -328,15 +328,17 @@ on_query(
|
|||
{ok, StatusCode, Headers} ->
|
||||
?SLOG(error, #{
|
||||
msg => "http connector do request, received error response",
|
||||
request => redact(NRequest),
|
||||
note => "the body will be redacted due to security reasons",
|
||||
request => redact_request(NRequest),
|
||||
connector => InstId,
|
||||
status_code => StatusCode
|
||||
}),
|
||||
{error, #{status_code => StatusCode, headers => Headers}};
|
||||
{ok, StatusCode, Headers, Body} ->
|
||||
?SLOG(error, #{
|
||||
msg => "http connector do request, received error response",
|
||||
request => redact(NRequest),
|
||||
msg => "http connector do request, received error response.",
|
||||
note => "the body will be redacted due to security reasons",
|
||||
request => redact_request(NRequest),
|
||||
connector => InstId,
|
||||
status_code => StatusCode
|
||||
}),
|
||||
|
@ -603,6 +605,15 @@ is_sensitive_key(_) ->
|
|||
redact(Data) ->
|
||||
emqx_misc:redact(Data, fun is_sensitive_key/1).
|
||||
|
||||
%% because the body may contain some sensitive data
|
||||
%% and at the same time the redact function will not scan the binary data
|
||||
%% and we also can't know the body format and where the sensitive data will be
|
||||
%% so the easy way to keep data security is redacted the whole body
|
||||
redact_request({Path, Headers}) ->
|
||||
{Path, redact(Headers)};
|
||||
redact_request({Path, Headers, _Body}) ->
|
||||
{Path, redact(Headers), <<"******">>}.
|
||||
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ fields(topology) ->
|
|||
{socket_timeout_ms, duration("socket_timeout")},
|
||||
{server_selection_timeout_ms, duration("server_selection_timeout")},
|
||||
{wait_queue_timeout_ms, duration("wait_queue_timeout")},
|
||||
{heartbeat_frequency_ms, duration("heartbeat_period")},
|
||||
{heartbeat_frequency_ms, fun heartbeat_frequency_ms/1},
|
||||
{min_heartbeat_frequency_ms, duration("min_heartbeat_period")}
|
||||
].
|
||||
|
||||
|
@ -407,6 +407,12 @@ duration(Desc) ->
|
|||
desc => ?DESC(Desc)
|
||||
}.
|
||||
|
||||
heartbeat_frequency_ms(type) -> emqx_schema:duration_ms();
|
||||
heartbeat_frequency_ms(desc) -> ?DESC("heartbeat_period");
|
||||
heartbeat_frequency_ms(default) -> 200000;
|
||||
heartbeat_frequency_ms(validator) -> [?MIN(1)];
|
||||
heartbeat_frequency_ms(_) -> undefined.
|
||||
|
||||
max_overflow(type) -> non_neg_integer();
|
||||
max_overflow(desc) -> ?DESC("max_overflow");
|
||||
max_overflow(default) -> 0;
|
||||
|
|
|
@ -391,14 +391,18 @@ proc_sql_params(TypeOrKey, SQLOrData, Params, #{params_tokens := ParamsTokens})
|
|||
end.
|
||||
|
||||
on_batch_insert(InstId, BatchReqs, InsertPart, Tokens, State) ->
|
||||
SQL = emqx_plugin_libs_rule:proc_batch_sql(BatchReqs, InsertPart, Tokens),
|
||||
on_sql_query(InstId, query, SQL, [], default_timeout, State).
|
||||
ValuesPart = lists:join($,, [
|
||||
emqx_placeholder:proc_param_str(Tokens, Msg, fun emqx_placeholder:quote_mysql/1)
|
||||
|| {_, Msg} <- BatchReqs
|
||||
]),
|
||||
Query = [InsertPart, <<" values ">> | ValuesPart],
|
||||
on_sql_query(InstId, query, Query, no_params, default_timeout, State).
|
||||
|
||||
on_sql_query(
|
||||
InstId,
|
||||
SQLFunc,
|
||||
SQLOrKey,
|
||||
Data,
|
||||
Params,
|
||||
Timeout,
|
||||
#{poolname := PoolName} = State
|
||||
) ->
|
||||
|
@ -409,9 +413,9 @@ on_sql_query(
|
|||
{ok, Conn} ->
|
||||
?tp(
|
||||
mysql_connector_send_query,
|
||||
#{sql_func => SQLFunc, sql_or_key => SQLOrKey, data => Data}
|
||||
#{sql_func => SQLFunc, sql_or_key => SQLOrKey, data => Params}
|
||||
),
|
||||
do_sql_query(SQLFunc, Conn, SQLOrKey, Data, Timeout, LogMeta);
|
||||
do_sql_query(SQLFunc, Conn, SQLOrKey, Params, Timeout, LogMeta);
|
||||
{error, disconnected} ->
|
||||
?SLOG(
|
||||
error,
|
||||
|
@ -423,8 +427,8 @@ on_sql_query(
|
|||
{error, {recoverable_error, disconnected}}
|
||||
end.
|
||||
|
||||
do_sql_query(SQLFunc, Conn, SQLOrKey, Data, Timeout, LogMeta) ->
|
||||
try mysql:SQLFunc(Conn, SQLOrKey, Data, Timeout) of
|
||||
do_sql_query(SQLFunc, Conn, SQLOrKey, Params, Timeout, LogMeta) ->
|
||||
try mysql:SQLFunc(Conn, SQLOrKey, Params, no_filtermap_fun, Timeout) of
|
||||
{error, disconnected} ->
|
||||
?SLOG(
|
||||
error,
|
||||
|
@ -466,7 +470,7 @@ do_sql_query(SQLFunc, Conn, SQLOrKey, Data, Timeout, LogMeta) ->
|
|||
error:badarg ->
|
||||
?SLOG(
|
||||
error,
|
||||
LogMeta#{msg => "mysql_connector_invalid_params", params => Data}
|
||||
LogMeta#{msg => "mysql_connector_invalid_params", params => Params}
|
||||
),
|
||||
{error, {unrecoverable_error, {invalid_params, Data}}}
|
||||
{error, {unrecoverable_error, {invalid_params, Params}}}
|
||||
end.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{application, emqx_dashboard, [
|
||||
{description, "EMQX Web Dashboard"},
|
||||
% strict semver, bump manually!
|
||||
{vsn, "5.0.14"},
|
||||
{vsn, "5.0.15"},
|
||||
{modules, []},
|
||||
{registered, [emqx_dashboard_sup]},
|
||||
{applications, [kernel, stdlib, mnesia, minirest, emqx, emqx_ctl]},
|
||||
|
|
|
@ -126,7 +126,7 @@ current_rate() ->
|
|||
(_Node, Error) ->
|
||||
Error
|
||||
end,
|
||||
case lists:foldl(Fun, #{}, mria_mnesia:cluster_nodes(running)) of
|
||||
case lists:foldl(Fun, #{}, mria:cluster_nodes(running)) of
|
||||
{badrpc, Reason} ->
|
||||
{badrpc, Reason};
|
||||
Rate ->
|
||||
|
@ -205,7 +205,7 @@ do_call(Request) ->
|
|||
gen_server:call(?MODULE, Request, 5000).
|
||||
|
||||
do_sample(all, Time) ->
|
||||
do_sample(mria_mnesia:cluster_nodes(running), Time, #{});
|
||||
do_sample(mria:cluster_nodes(running), Time, #{});
|
||||
do_sample(Node, Time) when Node == node() ->
|
||||
MS = match_spec(Time),
|
||||
internal_format(ets:select(?TAB, MS));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
{application, emqx_exhook, [
|
||||
{description, "EMQX Extension for Hook"},
|
||||
{vsn, "5.0.10"},
|
||||
{vsn, "5.0.11"},
|
||||
{modules, []},
|
||||
{registered, []},
|
||||
{mod, {emqx_exhook_app, []}},
|
||||
|
|
|
@ -471,7 +471,7 @@ fill_server_hooks_info([], _Name, _Default, MetricsL) ->
|
|||
-spec call_cluster(fun(([node()]) -> emqx_rpc:erpc_multicall(A))) ->
|
||||
[{node(), A | {error, _Err}}].
|
||||
call_cluster(Fun) ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
Ret = Fun(Nodes),
|
||||
lists:zip(Nodes, lists:map(fun emqx_rpc:unwrap_erpc/1, Ret)).
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
{application, emqx_gateway, [
|
||||
{description, "The Gateway management application"},
|
||||
{vsn, "0.1.12"},
|
||||
{vsn, "0.1.13"},
|
||||
{registered, []},
|
||||
{mod, {emqx_gateway_app, []}},
|
||||
{applications, [kernel, stdlib, grpc, emqx, emqx_authn, emqx_ctl]},
|
||||
|
|
|
@ -283,7 +283,7 @@ get_cluster_listeners_info(GwName) ->
|
|||
).
|
||||
|
||||
listeners_cluster_status(Listeners) ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
case emqx_gateway_api_listeners_proto_v1:listeners_cluster_status(Nodes, Listeners) of
|
||||
{Results, []} ->
|
||||
Results;
|
||||
|
|
|
@ -214,7 +214,7 @@ get_chan_info(GwName, ClientId, ChanPid) ->
|
|||
|
||||
-spec lookup_by_clientid(gateway_name(), emqx_types:clientid()) -> [pid()].
|
||||
lookup_by_clientid(GwName, ClientId) ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
case
|
||||
emqx_gateway_cm_proto_v1:lookup_by_clientid(
|
||||
Nodes, GwName, ClientId
|
||||
|
|
|
@ -148,7 +148,7 @@ gateway_status(GwName) ->
|
|||
end.
|
||||
|
||||
cluster_gateway_status(GwName) ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
case emqx_gateway_http_proto_v1:get_cluster_status(Nodes, GwName) of
|
||||
{Results, []} ->
|
||||
Results;
|
||||
|
|
|
@ -389,7 +389,12 @@ process_connect(
|
|||
clientinfo = ClientInfo
|
||||
}
|
||||
) ->
|
||||
SessFun = fun(_, _) -> emqx_session:init(#{max_inflight => 1}) end,
|
||||
SessFun = fun(ClientInfoT, _) ->
|
||||
Conf = emqx_cm:get_session_confs(
|
||||
ClientInfoT, #{receive_maximum => 1, expiry_interval => 0}
|
||||
),
|
||||
emqx_session:init(Conf)
|
||||
end,
|
||||
case
|
||||
emqx_gateway_ctx:open_session(
|
||||
Ctx,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
{id, "emqx_machine"},
|
||||
{description, "The EMQX Machine"},
|
||||
% strict semver, bump manually!
|
||||
{vsn, "0.2.0"},
|
||||
{vsn, "0.2.1"},
|
||||
{modules, []},
|
||||
{registered, []},
|
||||
{applications, [kernel, stdlib, emqx_ctl]},
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
-export([
|
||||
start/0,
|
||||
graceful_shutdown/0,
|
||||
brutal_shutdown/0,
|
||||
is_ready/0,
|
||||
|
||||
node_status/0,
|
||||
|
@ -47,6 +48,10 @@ start() ->
|
|||
graceful_shutdown() ->
|
||||
emqx_machine_terminator:graceful_wait().
|
||||
|
||||
%% only used when failed to boot
|
||||
brutal_shutdown() ->
|
||||
init:stop().
|
||||
|
||||
set_backtrace_depth() ->
|
||||
{ok, Depth} = application:get_env(emqx_machine, backtrace_depth),
|
||||
_ = erlang:system_flag(backtrace_depth, Depth),
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
-export([stop_apps/0, ensure_apps_started/0]).
|
||||
-export([sorted_reboot_apps/0]).
|
||||
-export([start_autocluster/0]).
|
||||
-export([stop_port_apps/0]).
|
||||
|
||||
-dialyzer({no_match, [basic_reboot_apps/0]}).
|
||||
|
||||
|
@ -61,6 +62,20 @@ stop_apps() ->
|
|||
_ = emqx_alarm_handler:unload(),
|
||||
lists:foreach(fun stop_one_app/1, lists:reverse(sorted_reboot_apps())).
|
||||
|
||||
%% Those port apps are terminated after the main apps
|
||||
%% Don't need to stop when reboot.
|
||||
stop_port_apps() ->
|
||||
Loaded = application:loaded_applications(),
|
||||
lists:foreach(
|
||||
fun(App) ->
|
||||
case lists:keymember(App, 1, Loaded) of
|
||||
true -> stop_one_app(App);
|
||||
false -> ok
|
||||
end
|
||||
end,
|
||||
[os_mon, jq]
|
||||
).
|
||||
|
||||
stop_one_app(App) ->
|
||||
?SLOG(debug, #{msg => "stopping_app", app => App}),
|
||||
try
|
||||
|
|
|
@ -87,7 +87,8 @@ handle_cast(_Cast, State) ->
|
|||
|
||||
handle_call(?DO_IT, _From, State) ->
|
||||
try
|
||||
emqx_machine_boot:stop_apps()
|
||||
emqx_machine_boot:stop_apps(),
|
||||
emqx_machine_boot:stop_port_apps()
|
||||
catch
|
||||
C:E:St ->
|
||||
Apps = [element(1, A) || A <- application:which_applications()],
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{application, emqx_management, [
|
||||
{description, "EMQX Management API and CLI"},
|
||||
% strict semver, bump manually!
|
||||
{vsn, "5.0.15"},
|
||||
{vsn, "5.0.16"},
|
||||
{modules, []},
|
||||
{registered, [emqx_management_sup]},
|
||||
{applications, [kernel, stdlib, emqx_plugins, minirest, emqx, emqx_ctl]},
|
||||
|
|
|
@ -112,8 +112,8 @@
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
list_nodes() ->
|
||||
Running = mria_mnesia:cluster_nodes(running),
|
||||
Stopped = mria_mnesia:cluster_nodes(stopped),
|
||||
Running = mria:cluster_nodes(running),
|
||||
Stopped = mria:cluster_nodes(stopped),
|
||||
DownNodes = lists:map(fun stopped_node_info/1, Stopped),
|
||||
[{Node, Info} || #{node := Node} = Info <- node_info(Running)] ++ DownNodes.
|
||||
|
||||
|
@ -199,7 +199,7 @@ vm_stats() ->
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
list_brokers() ->
|
||||
Running = mria_mnesia:running_nodes(),
|
||||
Running = mria:running_nodes(),
|
||||
[{Node, Broker} || #{node := Node} = Broker <- broker_info(Running)].
|
||||
|
||||
lookup_broker(Node) ->
|
||||
|
@ -223,7 +223,7 @@ broker_info(Nodes) ->
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
get_metrics() ->
|
||||
nodes_info_count([get_metrics(Node) || Node <- mria_mnesia:running_nodes()]).
|
||||
nodes_info_count([get_metrics(Node) || Node <- mria:running_nodes()]).
|
||||
|
||||
get_metrics(Node) ->
|
||||
unwrap_rpc(emqx_proto_v1:get_metrics(Node)).
|
||||
|
@ -243,7 +243,7 @@ get_stats() ->
|
|||
Stats = get_stats(Node),
|
||||
delete_keys(Stats, GlobalStatsKeys)
|
||||
end
|
||||
|| Node <- mria_mnesia:running_nodes()
|
||||
|| Node <- mria:running_nodes()
|
||||
]),
|
||||
GlobalStats = maps:with(GlobalStatsKeys, maps:from_list(get_stats(node()))),
|
||||
maps:merge(CountStats, GlobalStats).
|
||||
|
@ -275,12 +275,12 @@ nodes_info_count(PropList) ->
|
|||
lookup_client({clientid, ClientId}, FormatFun) ->
|
||||
lists:append([
|
||||
lookup_client(Node, {clientid, ClientId}, FormatFun)
|
||||
|| Node <- mria_mnesia:running_nodes()
|
||||
|| Node <- mria:running_nodes()
|
||||
]);
|
||||
lookup_client({username, Username}, FormatFun) ->
|
||||
lists:append([
|
||||
lookup_client(Node, {username, Username}, FormatFun)
|
||||
|| Node <- mria_mnesia:running_nodes()
|
||||
|| Node <- mria:running_nodes()
|
||||
]).
|
||||
|
||||
lookup_client(Node, Key, FormatFun) ->
|
||||
|
@ -307,7 +307,7 @@ kickout_client(ClientId) ->
|
|||
[] ->
|
||||
{error, not_found};
|
||||
_ ->
|
||||
Results = [kickout_client(Node, ClientId) || Node <- mria_mnesia:running_nodes()],
|
||||
Results = [kickout_client(Node, ClientId) || Node <- mria:running_nodes()],
|
||||
check_results(Results)
|
||||
end.
|
||||
|
||||
|
@ -322,7 +322,7 @@ list_client_subscriptions(ClientId) ->
|
|||
[] ->
|
||||
{error, not_found};
|
||||
_ ->
|
||||
Results = [client_subscriptions(Node, ClientId) || Node <- mria_mnesia:running_nodes()],
|
||||
Results = [client_subscriptions(Node, ClientId) || Node <- mria:running_nodes()],
|
||||
Filter =
|
||||
fun
|
||||
({error, _}) ->
|
||||
|
@ -340,18 +340,18 @@ client_subscriptions(Node, ClientId) ->
|
|||
{Node, unwrap_rpc(emqx_broker_proto_v1:list_client_subscriptions(Node, ClientId))}.
|
||||
|
||||
clean_authz_cache(ClientId) ->
|
||||
Results = [clean_authz_cache(Node, ClientId) || Node <- mria_mnesia:running_nodes()],
|
||||
Results = [clean_authz_cache(Node, ClientId) || Node <- mria:running_nodes()],
|
||||
check_results(Results).
|
||||
|
||||
clean_authz_cache(Node, ClientId) ->
|
||||
unwrap_rpc(emqx_proto_v1:clean_authz_cache(Node, ClientId)).
|
||||
|
||||
clean_authz_cache_all() ->
|
||||
Results = [{Node, clean_authz_cache_all(Node)} || Node <- mria_mnesia:running_nodes()],
|
||||
Results = [{Node, clean_authz_cache_all(Node)} || Node <- mria:running_nodes()],
|
||||
wrap_results(Results).
|
||||
|
||||
clean_pem_cache_all() ->
|
||||
Results = [{Node, clean_pem_cache_all(Node)} || Node <- mria_mnesia:running_nodes()],
|
||||
Results = [{Node, clean_pem_cache_all(Node)} || Node <- mria:running_nodes()],
|
||||
wrap_results(Results).
|
||||
|
||||
wrap_results(Results) ->
|
||||
|
@ -379,7 +379,7 @@ set_keepalive(_ClientId, _Interval) ->
|
|||
|
||||
%% @private
|
||||
call_client(ClientId, Req) ->
|
||||
Results = [call_client(Node, ClientId, Req) || Node <- mria_mnesia:running_nodes()],
|
||||
Results = [call_client(Node, ClientId, Req) || Node <- mria:running_nodes()],
|
||||
Expected = lists:filter(
|
||||
fun
|
||||
({error, _}) -> false;
|
||||
|
@ -428,7 +428,7 @@ list_subscriptions(Node) ->
|
|||
list_subscriptions_via_topic(Topic, FormatFun) ->
|
||||
lists:append([
|
||||
list_subscriptions_via_topic(Node, Topic, FormatFun)
|
||||
|| Node <- mria_mnesia:running_nodes()
|
||||
|| Node <- mria:running_nodes()
|
||||
]).
|
||||
|
||||
list_subscriptions_via_topic(Node, Topic, _FormatFun = {M, F}) ->
|
||||
|
@ -442,7 +442,7 @@ list_subscriptions_via_topic(Node, Topic, _FormatFun = {M, F}) ->
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
subscribe(ClientId, TopicTables) ->
|
||||
subscribe(mria_mnesia:running_nodes(), ClientId, TopicTables).
|
||||
subscribe(mria:running_nodes(), ClientId, TopicTables).
|
||||
|
||||
subscribe([Node | Nodes], ClientId, TopicTables) ->
|
||||
case unwrap_rpc(emqx_management_proto_v3:subscribe(Node, ClientId, TopicTables)) of
|
||||
|
@ -467,7 +467,7 @@ publish(Msg) ->
|
|||
-spec unsubscribe(emqx_types:clientid(), emqx_types:topic()) ->
|
||||
{unsubscribe, _} | {error, channel_not_found}.
|
||||
unsubscribe(ClientId, Topic) ->
|
||||
unsubscribe(mria_mnesia:running_nodes(), ClientId, Topic).
|
||||
unsubscribe(mria:running_nodes(), ClientId, Topic).
|
||||
|
||||
-spec unsubscribe([node()], emqx_types:clientid(), emqx_types:topic()) ->
|
||||
{unsubscribe, _} | {error, channel_not_found}.
|
||||
|
@ -490,7 +490,7 @@ do_unsubscribe(ClientId, Topic) ->
|
|||
-spec unsubscribe_batch(emqx_types:clientid(), [emqx_types:topic()]) ->
|
||||
{unsubscribe, _} | {error, channel_not_found}.
|
||||
unsubscribe_batch(ClientId, Topics) ->
|
||||
unsubscribe_batch(mria_mnesia:running_nodes(), ClientId, Topics).
|
||||
unsubscribe_batch(mria:running_nodes(), ClientId, Topics).
|
||||
|
||||
-spec unsubscribe_batch([node()], emqx_types:clientid(), [emqx_types:topic()]) ->
|
||||
{unsubscribe_batch, _} | {error, channel_not_found}.
|
||||
|
@ -515,7 +515,7 @@ do_unsubscribe_batch(ClientId, Topics) ->
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
get_alarms(Type) ->
|
||||
[{Node, get_alarms(Node, Type)} || Node <- mria_mnesia:running_nodes()].
|
||||
[{Node, get_alarms(Node, Type)} || Node <- mria:running_nodes()].
|
||||
|
||||
get_alarms(Node, Type) ->
|
||||
add_duration_field(unwrap_rpc(emqx_proto_v1:get_alarms(Node, Type))).
|
||||
|
@ -524,7 +524,7 @@ deactivate(Node, Name) ->
|
|||
unwrap_rpc(emqx_proto_v1:deactivate_alarm(Node, Name)).
|
||||
|
||||
delete_all_deactivated_alarms() ->
|
||||
[delete_all_deactivated_alarms(Node) || Node <- mria_mnesia:running_nodes()].
|
||||
[delete_all_deactivated_alarms(Node) || Node <- mria:running_nodes()].
|
||||
|
||||
delete_all_deactivated_alarms(Node) ->
|
||||
unwrap_rpc(emqx_proto_v1:delete_all_deactivated_alarms(Node)).
|
||||
|
|
|
@ -163,7 +163,7 @@ cluster_query(Tab, QString, QSchema, MsFun, FmtFun) ->
|
|||
{error, page_limit_invalid};
|
||||
Meta ->
|
||||
{_CodCnt, NQString} = parse_qstring(QString, QSchema),
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
ResultAcc = init_query_result(),
|
||||
QueryState = init_query_state(Tab, NQString, MsFun, Meta),
|
||||
NResultAcc = do_cluster_query(
|
||||
|
|
|
@ -101,7 +101,7 @@ cluster_info(get, _) ->
|
|||
ClusterName = application:get_env(ekka, cluster_name, emqxcl),
|
||||
Info = #{
|
||||
name => ClusterName,
|
||||
nodes => mria_mnesia:running_nodes(),
|
||||
nodes => mria:running_nodes(),
|
||||
self => node()
|
||||
},
|
||||
{200, Info}.
|
||||
|
|
|
@ -279,7 +279,7 @@ configs(get, Params, _Req) ->
|
|||
QS = maps:get(query_string, Params, #{}),
|
||||
Node = maps:get(<<"node">>, QS, node()),
|
||||
case
|
||||
lists:member(Node, mria_mnesia:running_nodes()) andalso
|
||||
lists:member(Node, mria:running_nodes()) andalso
|
||||
emqx_management_proto_v2:get_full_config(Node)
|
||||
of
|
||||
false ->
|
||||
|
|
|
@ -483,7 +483,7 @@ err_msg_str(Reason) ->
|
|||
io_lib:format("~p", [Reason]).
|
||||
|
||||
list_listeners() ->
|
||||
[list_listeners(Node) || Node <- mria_mnesia:running_nodes()].
|
||||
[list_listeners(Node) || Node <- mria:running_nodes()].
|
||||
|
||||
list_listeners(Node) ->
|
||||
wrap_rpc(emqx_management_proto_v2:list_listeners(Node)).
|
||||
|
|
|
@ -59,7 +59,7 @@ metrics(get, #{query_string := Qs}) ->
|
|||
maps:from_list(
|
||||
emqx_mgmt:get_metrics(Node) ++ [{node, Node}]
|
||||
)
|
||||
|| Node <- mria_mnesia:running_nodes()
|
||||
|| Node <- mria:running_nodes()
|
||||
],
|
||||
{200, Data}
|
||||
end.
|
||||
|
|
|
@ -129,7 +129,7 @@ list(get, #{query_string := Qs}) ->
|
|||
_ ->
|
||||
Data = [
|
||||
maps:from_list(emqx_mgmt:get_stats(Node) ++ [{node, Node}])
|
||||
|| Node <- mria_mnesia:running_nodes()
|
||||
|| Node <- mria:running_nodes()
|
||||
],
|
||||
{200, Data}
|
||||
end.
|
||||
|
|
|
@ -376,7 +376,7 @@ trace(get, _Params) ->
|
|||
fun(#{start_at := A}, #{start_at := B}) -> A > B end,
|
||||
emqx_trace:format(List0)
|
||||
),
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
TraceSize = wrap_rpc(emqx_mgmt_trace_proto_v2:get_trace_size(Nodes)),
|
||||
AllFileSize = lists:foldl(fun(F, Acc) -> maps:merge(Acc, F) end, #{}, TraceSize),
|
||||
Now = erlang:system_time(second),
|
||||
|
@ -445,7 +445,7 @@ format_trace(Trace0) ->
|
|||
LogSize = lists:foldl(
|
||||
fun(Node, Acc) -> Acc#{Node => 0} end,
|
||||
#{},
|
||||
mria_mnesia:running_nodes()
|
||||
mria:running_nodes()
|
||||
),
|
||||
Trace2 = maps:without([enable, filter], Trace1),
|
||||
Trace2#{
|
||||
|
@ -541,13 +541,13 @@ group_trace_file(ZipDir, TraceLog, TraceFiles) ->
|
|||
).
|
||||
|
||||
collect_trace_file(undefined, TraceLog) ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
wrap_rpc(emqx_mgmt_trace_proto_v2:trace_file(Nodes, TraceLog));
|
||||
collect_trace_file(Node, TraceLog) ->
|
||||
wrap_rpc(emqx_mgmt_trace_proto_v2:trace_file([Node], TraceLog)).
|
||||
|
||||
collect_trace_file_detail(TraceLog) ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
wrap_rpc(emqx_mgmt_trace_proto_v2:trace_file_detail(Nodes, TraceLog)).
|
||||
|
||||
wrap_rpc({GoodRes, BadNodes}) ->
|
||||
|
@ -677,7 +677,7 @@ parse_node(Query, Default) ->
|
|||
{ok, Default};
|
||||
{ok, NodeBin} ->
|
||||
Node = binary_to_existing_atom(NodeBin),
|
||||
true = lists:member(Node, mria_mnesia:running_nodes()),
|
||||
true = lists:member(Node, mria:running_nodes()),
|
||||
{ok, Node}
|
||||
end
|
||||
catch
|
||||
|
|
|
@ -36,16 +36,16 @@ end_per_suite(_) ->
|
|||
emqx_mgmt_api_test_util:end_suite([emqx_management, emqx_conf]).
|
||||
|
||||
init_per_testcase(TestCase, Config) ->
|
||||
meck:expect(mria_mnesia, running_nodes, 0, [node()]),
|
||||
meck:expect(mria, running_nodes, 0, [node()]),
|
||||
emqx_common_test_helpers:init_per_testcase(?MODULE, TestCase, Config).
|
||||
|
||||
end_per_testcase(TestCase, Config) ->
|
||||
meck:unload(mria_mnesia),
|
||||
meck:unload(mria),
|
||||
emqx_common_test_helpers:end_per_testcase(?MODULE, TestCase, Config).
|
||||
|
||||
t_list_nodes(init, Config) ->
|
||||
meck:expect(
|
||||
mria_mnesia,
|
||||
mria,
|
||||
cluster_nodes,
|
||||
fun
|
||||
(running) -> [node()];
|
||||
|
@ -125,7 +125,7 @@ t_lookup_client(_Config) ->
|
|||
emqx_mgmt:lookup_client({username, <<"user1">>}, ?FORMATFUN)
|
||||
),
|
||||
?assertEqual([], emqx_mgmt:lookup_client({clientid, <<"notfound">>}, ?FORMATFUN)),
|
||||
meck:expect(mria_mnesia, running_nodes, 0, [node(), 'fake@nonode']),
|
||||
meck:expect(mria, running_nodes, 0, [node(), 'fake@nonode']),
|
||||
?assertMatch(
|
||||
[_ | {error, nodedown}], emqx_mgmt:lookup_client({clientid, <<"client1">>}, ?FORMATFUN)
|
||||
).
|
||||
|
@ -188,7 +188,7 @@ t_clean_cache(_Config) ->
|
|||
{error, _},
|
||||
emqx_mgmt:clean_pem_cache_all()
|
||||
),
|
||||
meck:expect(mria_mnesia, running_nodes, 0, [node(), 'fake@nonode']),
|
||||
meck:expect(mria, running_nodes, 0, [node(), 'fake@nonode']),
|
||||
?assertMatch(
|
||||
{error, [{'fake@nonode', {error, _}}]},
|
||||
emqx_mgmt:clean_authz_cache_all()
|
||||
|
|
|
@ -179,14 +179,14 @@ t_bad_rpc(_) ->
|
|||
ClientLs1 = [start_emqtt_client(node(), I, 1883) || I <- lists:seq(1, 10)],
|
||||
Path = emqx_mgmt_api_test_util:api_path(["clients?limit=2&page=2"]),
|
||||
try
|
||||
meck:expect(mria_mnesia, running_nodes, 0, ['fake@nohost']),
|
||||
meck:expect(mria, running_nodes, 0, ['fake@nohost']),
|
||||
{error, {_, 500, _}} = emqx_mgmt_api_test_util:request_api(get, Path),
|
||||
%% good cop, bad cop
|
||||
meck:expect(mria_mnesia, running_nodes, 0, [node(), 'fake@nohost']),
|
||||
meck:expect(mria, running_nodes, 0, [node(), 'fake@nohost']),
|
||||
{error, {_, 500, _}} = emqx_mgmt_api_test_util:request_api(get, Path)
|
||||
after
|
||||
_ = lists:foreach(fun(C) -> emqtt:disconnect(C) end, ClientLs1),
|
||||
meck:unload(mria_mnesia),
|
||||
meck:unload(mria),
|
||||
emqx_mgmt_api_test_util:end_suite()
|
||||
end.
|
||||
|
||||
|
|
|
@ -212,7 +212,7 @@ t_dashboard(_Config) ->
|
|||
|
||||
t_configs_node({'init', Config}) ->
|
||||
Node = node(),
|
||||
meck:expect(mria_mnesia, running_nodes, fun() -> [Node, bad_node, other_node] end),
|
||||
meck:expect(mria, running_nodes, fun() -> [Node, bad_node, other_node] end),
|
||||
meck:expect(
|
||||
emqx_management_proto_v2,
|
||||
get_full_config,
|
||||
|
@ -224,7 +224,7 @@ t_configs_node({'init', Config}) ->
|
|||
),
|
||||
Config;
|
||||
t_configs_node({'end', _}) ->
|
||||
meck:unload([mria_mnesia, emqx_management_proto_v2]);
|
||||
meck:unload([mria, emqx_management_proto_v2]);
|
||||
t_configs_node(_) ->
|
||||
Node = atom_to_list(node()),
|
||||
|
||||
|
|
|
@ -168,8 +168,8 @@ t_api_listeners_list_not_ready(Config) when is_list(Config) ->
|
|||
L3 = get_tcp_listeners(Node2),
|
||||
|
||||
Comment = #{
|
||||
node1 => rpc:call(Node1, mria_mnesia, running_nodes, []),
|
||||
node2 => rpc:call(Node2, mria_mnesia, running_nodes, [])
|
||||
node1 => rpc:call(Node1, mria, running_nodes, []),
|
||||
node2 => rpc:call(Node2, mria, running_nodes, [])
|
||||
},
|
||||
|
||||
?assert(length(L1) > length(L2), Comment),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
{application, emqx_modules, [
|
||||
{description, "EMQX Modules"},
|
||||
{vsn, "5.0.10"},
|
||||
{vsn, "5.0.11"},
|
||||
{modules, []},
|
||||
{applications, [kernel, stdlib, emqx, emqx_ctl]},
|
||||
{mod, {emqx_modules_app, []}},
|
||||
|
|
|
@ -266,7 +266,7 @@ uptime() ->
|
|||
element(1, erlang:statistics(wall_clock)).
|
||||
|
||||
nodes_uuid() ->
|
||||
Nodes = lists:delete(node(), mria_mnesia:running_nodes()),
|
||||
Nodes = lists:delete(node(), mria:running_nodes()),
|
||||
lists:foldl(
|
||||
fun(Node, Acc) ->
|
||||
case emqx_telemetry_proto_v1:get_node_uuid(Node) of
|
||||
|
|
|
@ -321,7 +321,7 @@ operate_topic_metrics(delete, #{bindings := #{topic := Topic}}) ->
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
cluster_accumulation_metrics() ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
case emqx_topic_metrics_proto_v1:metrics(Nodes) of
|
||||
{SuccResList, []} ->
|
||||
{ok, accumulate_nodes_metrics(SuccResList)};
|
||||
|
@ -330,7 +330,7 @@ cluster_accumulation_metrics() ->
|
|||
end.
|
||||
|
||||
cluster_accumulation_metrics(Topic) ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
case emqx_topic_metrics_proto_v1:metrics(Nodes, Topic) of
|
||||
{SuccResList, []} ->
|
||||
case
|
||||
|
@ -422,12 +422,12 @@ do_accumulation_metrics(MetricsIn, {MetricsAcc, _}) ->
|
|||
).
|
||||
|
||||
reset() ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
_ = emqx_topic_metrics_proto_v1:reset(Nodes),
|
||||
ok.
|
||||
|
||||
reset(Topic) ->
|
||||
Nodes = mria_mnesia:running_nodes(),
|
||||
Nodes = mria:running_nodes(),
|
||||
case emqx_topic_metrics_proto_v1:reset(Nodes, Topic) of
|
||||
{SuccResList, []} ->
|
||||
case
|
||||
|
|
|
@ -856,7 +856,7 @@ stop_slave(Node) ->
|
|||
%emqx_cluster_rpc:fast_forward_to_commit(Node, 100),
|
||||
rpc:call(Node, ?MODULE, leave_cluster, []),
|
||||
ok = slave:stop(Node),
|
||||
?assertEqual([node()], mria_mnesia:running_nodes()),
|
||||
?assertEqual([node()], mria:running_nodes()),
|
||||
?assertEqual([], nodes()),
|
||||
_ = application:stop(mria),
|
||||
ok = application:start(mria).
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
proc_sql/2,
|
||||
proc_sql_param_str/2,
|
||||
proc_cql_param_str/2,
|
||||
proc_param_str/3,
|
||||
preproc_tmpl_deep/1,
|
||||
preproc_tmpl_deep/2,
|
||||
proc_tmpl_deep/2,
|
||||
|
@ -39,6 +40,12 @@
|
|||
sql_data/1
|
||||
]).
|
||||
|
||||
-export([
|
||||
quote_sql/1,
|
||||
quote_cql/1,
|
||||
quote_mysql/1
|
||||
]).
|
||||
|
||||
-include_lib("emqx/include/emqx_placeholder.hrl").
|
||||
|
||||
-define(EX_PLACE_HOLDER, "(\\$\\{[a-zA-Z0-9\\._]+\\})").
|
||||
|
@ -83,6 +90,8 @@
|
|||
| {tmpl, tmpl_token()}
|
||||
| {value, term()}.
|
||||
|
||||
-dialyzer({no_improper_lists, [quote_mysql/1, escape_mysql/4, escape_prepend/4]}).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% APIs
|
||||
%%------------------------------------------------------------------------------
|
||||
|
@ -162,12 +171,22 @@ proc_sql(Tokens, Data) ->
|
|||
|
||||
-spec proc_sql_param_str(tmpl_token(), map()) -> binary().
|
||||
proc_sql_param_str(Tokens, Data) ->
|
||||
% NOTE
|
||||
% This is a bit misleading: currently, escaping logic in `quote_sql/1` likely
|
||||
% won't work with pgsql since it does not support C-style escapes by default.
|
||||
% https://www.postgresql.org/docs/14/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS
|
||||
proc_param_str(Tokens, Data, fun quote_sql/1).
|
||||
|
||||
-spec proc_cql_param_str(tmpl_token(), map()) -> binary().
|
||||
proc_cql_param_str(Tokens, Data) ->
|
||||
proc_param_str(Tokens, Data, fun quote_cql/1).
|
||||
|
||||
-spec proc_param_str(tmpl_token(), map(), fun((_Value) -> iodata())) -> binary().
|
||||
proc_param_str(Tokens, Data, Quote) ->
|
||||
iolist_to_binary(
|
||||
proc_tmpl(Tokens, Data, #{return => rawlist, var_trans => Quote})
|
||||
).
|
||||
|
||||
-spec preproc_tmpl_deep(term()) -> deep_template().
|
||||
preproc_tmpl_deep(Data) ->
|
||||
preproc_tmpl_deep(Data, #{process_keys => true}).
|
||||
|
@ -226,15 +245,29 @@ sql_data(Map) when is_map(Map) -> emqx_json:encode(Map).
|
|||
-spec bin(term()) -> binary().
|
||||
bin(Val) -> emqx_plugin_libs_rule:bin(Val).
|
||||
|
||||
-spec quote_sql(_Value) -> iolist().
|
||||
quote_sql(Str) ->
|
||||
quote_escape(Str, fun escape_sql/1).
|
||||
|
||||
-spec quote_cql(_Value) -> iolist().
|
||||
quote_cql(Str) ->
|
||||
quote_escape(Str, fun escape_cql/1).
|
||||
|
||||
-spec quote_mysql(_Value) -> iolist().
|
||||
quote_mysql(Str) when is_binary(Str) ->
|
||||
try
|
||||
escape_mysql(Str)
|
||||
catch
|
||||
throw:invalid_utf8 ->
|
||||
[<<"0x">> | binary:encode_hex(Str)]
|
||||
end;
|
||||
quote_mysql(Str) ->
|
||||
quote_escape(Str, fun escape_mysql/1).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Internal functions
|
||||
%%------------------------------------------------------------------------------
|
||||
|
||||
proc_param_str(Tokens, Data, Quote) ->
|
||||
iolist_to_binary(
|
||||
proc_tmpl(Tokens, Data, #{return => rawlist, var_trans => Quote})
|
||||
).
|
||||
|
||||
get_phld_var(Phld, Data) ->
|
||||
emqx_rule_maps:nested_get(Phld, Data).
|
||||
|
||||
|
@ -312,21 +345,56 @@ unwrap(<<"\"${", Val/binary>>, _StripDoubleQuote = true) ->
|
|||
unwrap(<<"${", Val/binary>>, _StripDoubleQuote) ->
|
||||
binary:part(Val, {0, byte_size(Val) - 1}).
|
||||
|
||||
quote_sql(Str) ->
|
||||
quote(Str, <<"\\\\'">>).
|
||||
|
||||
quote_cql(Str) ->
|
||||
quote(Str, <<"''">>).
|
||||
|
||||
quote(Str, ReplaceWith) when
|
||||
is_list(Str);
|
||||
is_binary(Str);
|
||||
is_atom(Str);
|
||||
is_map(Str)
|
||||
->
|
||||
[$', escape_apo(bin(Str), ReplaceWith), $'];
|
||||
quote(Val, _) ->
|
||||
-spec quote_escape(_Value, fun((binary()) -> iodata())) -> iodata().
|
||||
quote_escape(Str, EscapeFun) when is_binary(Str) ->
|
||||
EscapeFun(Str);
|
||||
quote_escape(Str, EscapeFun) when is_list(Str) ->
|
||||
case unicode:characters_to_binary(Str) of
|
||||
Bin when is_binary(Bin) ->
|
||||
EscapeFun(Bin);
|
||||
Otherwise ->
|
||||
error(Otherwise)
|
||||
end;
|
||||
quote_escape(Str, EscapeFun) when is_atom(Str) orelse is_map(Str) ->
|
||||
EscapeFun(bin(Str));
|
||||
quote_escape(Val, _EscapeFun) ->
|
||||
bin(Val).
|
||||
|
||||
escape_apo(Str, ReplaceWith) ->
|
||||
re:replace(Str, <<"'">>, ReplaceWith, [{return, binary}, global]).
|
||||
-spec escape_sql(binary()) -> iolist().
|
||||
escape_sql(S) ->
|
||||
ES = binary:replace(S, [<<"\\">>, <<"'">>], <<"\\">>, [global, {insert_replaced, 1}]),
|
||||
[$', ES, $'].
|
||||
|
||||
-spec escape_cql(binary()) -> iolist().
|
||||
escape_cql(S) ->
|
||||
ES = binary:replace(S, <<"'">>, <<"'">>, [global, {insert_replaced, 1}]),
|
||||
[$', ES, $'].
|
||||
|
||||
-spec escape_mysql(binary()) -> iolist().
|
||||
escape_mysql(S0) ->
|
||||
% https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
|
||||
[$', escape_mysql(S0, 0, 0, S0), $'].
|
||||
|
||||
%% NOTE
|
||||
%% This thing looks more complicated than needed because it's optimized for as few
|
||||
%% intermediate memory (re)allocations as possible.
|
||||
escape_mysql(<<$', Rest/binary>>, I, Run, Src) ->
|
||||
escape_prepend(I, Run, Src, [<<"\\'">> | escape_mysql(Rest, I + Run + 1, 0, Src)]);
|
||||
escape_mysql(<<$\\, Rest/binary>>, I, Run, Src) ->
|
||||
escape_prepend(I, Run, Src, [<<"\\\\">> | escape_mysql(Rest, I + Run + 1, 0, Src)]);
|
||||
escape_mysql(<<0, Rest/binary>>, I, Run, Src) ->
|
||||
escape_prepend(I, Run, Src, [<<"\\0">> | escape_mysql(Rest, I + Run + 1, 0, Src)]);
|
||||
escape_mysql(<<_/utf8, Rest/binary>> = S, I, Run, Src) ->
|
||||
CWidth = byte_size(S) - byte_size(Rest),
|
||||
escape_mysql(Rest, I, Run + CWidth, Src);
|
||||
escape_mysql(<<>>, 0, _, Src) ->
|
||||
Src;
|
||||
escape_mysql(<<>>, I, Run, Src) ->
|
||||
binary:part(Src, I, Run);
|
||||
escape_mysql(_, _I, _Run, _Src) ->
|
||||
throw(invalid_utf8).
|
||||
|
||||
escape_prepend(_RunI, 0, _Src, Tail) ->
|
||||
Tail;
|
||||
escape_prepend(I, Run, Src, Tail) ->
|
||||
[binary:part(Src, I, Run) | Tail].
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
{application, emqx_plugin_libs, [
|
||||
{description, "EMQX Plugin utility libs"},
|
||||
{vsn, "4.3.6"},
|
||||
{vsn, "4.3.7"},
|
||||
{modules, []},
|
||||
{applications, [kernel, stdlib]},
|
||||
{env, []}
|
||||
|
|
|
@ -68,11 +68,6 @@
|
|||
|
||||
-compile({no_auto_import, [float/1]}).
|
||||
|
||||
-define(EX_PLACE_HOLDER, "(\\$\\{[a-zA-Z0-9\\._]+\\})").
|
||||
|
||||
%% Space and CRLF
|
||||
-define(EX_WITHE_CHARS, "\\s").
|
||||
|
||||
-type uri_string() :: iodata().
|
||||
|
||||
-type tmpl_token() :: list({var, binary()} | {str, binary()}).
|
||||
|
@ -172,8 +167,8 @@ detect_sql_type(SQL) ->
|
|||
) -> InsertSQL :: binary().
|
||||
proc_batch_sql(BatchReqs, InsertPart, Tokens) ->
|
||||
ValuesPart = erlang:iolist_to_binary(
|
||||
lists:join(", ", [
|
||||
emqx_plugin_libs_rule:proc_sql_param_str(Tokens, Msg)
|
||||
lists:join($,, [
|
||||
proc_sql_param_str(Tokens, Msg)
|
||||
|| {_, Msg} <- BatchReqs
|
||||
])
|
||||
),
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue