Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into local_address
Browse files Browse the repository at this point in the history
Signed-off-by: pcrao <[email protected]>
  • Loading branch information
pradeepcrao committed Sep 6, 2023
2 parents 29c0258 + 0546512 commit f54b072
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void flushStats() {

@Override
public String dumpStats() {
return JniLibrary.dumpStats();
return JniLibrary.dumpStats(engineHandle);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ protected static native int recordCounterInc(long engine, String elements, byte[

/**
* Retrieve the value of all active stats. Note that this function may block for some time.
* @param engine, handle to the engine that owns the counter.
* @return The list of active stats and their values, or empty string of the operation failed
*/
protected static native String dumpStats();
protected static native String dumpStats(long engine);

/**
* Register a platform-provided key-value store implementation.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.envoyproxy.envoymobile.utilities;

import java.util.HashMap;
import java.util.Map;

/**
* Class for utilities around Envoy stats.
*/
public class StatsUtils {

/**
* Takes in a stats string from engine.dumpStats() and parses it into individual map entries.
* @param statsString, the string from dumpStats
* @return a map of stats entries, e.g. "runtime.load_success", "1"
*/
public static Map<String, String> statsToList(String statsString) {
Map<String, String> stats = new HashMap<>();

for (String line : statsString.split("\n")) {
String[] keyValue = line.split(": ");
if (keyValue.length != 2) {
System.out.println("Unexpected stats token");
continue;
}
stats.put(keyValue[0], keyValue[1]);
}
return stats;
}
}
9 changes: 9 additions & 0 deletions mobile/test/java/org/chromium/net/impl/CronvoyEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.test.core.app.ApplicationProvider;
import io.envoyproxy.envoymobile.RequestMethod;
import io.envoyproxy.envoymobile.engine.AndroidJniLibrary;
import io.envoyproxy.envoymobile.utilities.StatsUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
Expand Down Expand Up @@ -88,6 +89,14 @@ public void get_simple() throws Exception {
assertThat(response.getResponseCode()).isEqualTo(HTTP_OK);
assertThat(response.getBodyAsString()).isEqualTo("hello, world");
assertThat(response.getCronetException()).withFailMessage(response.getErrorMessage()).isNull();

// Do some basic stats accounting.
String stats = cronvoyEngine.getEnvoyEngine().dumpStats();
Map<String, String> statsMap = StatsUtils.statsToList(stats);
assertThat(statsMap.containsKey("http.hcm.downstream_rq_2xx"));
assertThat(statsMap.containsKey("http.hcm.downstream_total"));
assertThat(statsMap.containsKey("runtime.load_success"));
assertThat(statsMap.get("runtime.load_success")).isEqualTo("1");
}

@Test
Expand Down
3 changes: 1 addition & 2 deletions mobile/test/kotlin/integration/EngineApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class EngineApiTest {

engine.pulseClient().counter(Element("foo"), Element("bar")).increment(1)

// FIXME(jpsim): Fix crash that occurs when uncommenting this line
// assertThat(engine?.dumpStats()).contains("pulse.foo.bar: 1")
assertThat(engine.dumpStats()).contains("pulse.foo.bar: 1")

engine.terminate()
}
Expand Down
41 changes: 0 additions & 41 deletions tools/code_format/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ paths:
- source/extensions/common/matcher/trie_matcher.h
# legacy core files which throw exceptions. We can add to this list but strongly prefer
# StausOr where possible.
- source/common/upstream/wrsq_scheduler.h
- source/common/upstream/cds_api_helper.cc
- source/common/upstream/thread_aware_lb_impl.cc
- source/common/upstream/load_balancer_impl.cc
Expand All @@ -103,18 +102,13 @@ paths:
- source/common/upstream/outlier_detection_impl.cc
- source/common/upstream/upstream_impl.cc
- source/common/upstream/default_local_address_selector_factory.cc
- source/common/network/connection_impl.cc
- source/common/network/listen_socket_impl.cc
- source/common/network/io_socket_handle_impl.cc
- source/common/network/address_impl.cc
- source/common/network/address_impl.h
- source/common/network/cidr_range.cc
- source/common/network/utility.cc
- source/common/network/dns_resolver/dns_factory_util.cc
- source/common/network/dns_resolver/dns_factory_util.h
- source/common/network/resolver_impl.cc
- source/common/network/utility.h
- source/common/network/lc_trie.h
- source/common/network/socket_impl.cc
- source/common/ssl/tls_certificate_config_impl.cc
- source/common/formatter/http_specific_formatter.cc
Expand All @@ -129,62 +123,35 @@ paths:
- source/common/http/filter_chain_helper.cc
- source/common/http/utility.cc
- source/common/http/hash_policy.cc
- source/common/http/utility.h
- source/common/http/filter_chain_helper.h
- source/common/http/conn_manager_utility.cc
- source/common/http/match_delegate/config.cc
- source/common/protobuf/yaml_utility.cc
- source/common/protobuf/visitor_helper.h
- source/common/protobuf/visitor.cc
- source/common/protobuf/utility.cc
- source/common/protobuf/utility.h
- source/common/protobuf/message_validator_impl.cc
- source/common/access_log/access_log_impl.h
- source/common/access_log/access_log_manager_impl.cc
- source/common/secret/secret_manager_impl.cc
- source/common/secret/sds_api.h
- source/common/secret/sds_api.cc
- source/common/grpc/async_client_manager_impl.cc
- source/common/grpc/common.cc
- source/common/grpc/google_grpc_utils.cc
- source/common/grpc/common.h
- source/common/tcp_proxy/tcp_proxy.cc
- source/common/config/xds_resource.h
- source/common/config/subscription_factory_impl.cc
- source/common/config/xds_resource.cc
- source/common/config/datasource.cc
- source/common/config/xds_mux/delta_subscription_state.cc
- source/common/config/xds_mux/sotw_subscription_state.cc
- source/common/config/xds_mux/grpc_mux_impl.cc
- source/common/config/utility.cc
- source/common/config/watch_map.h
- source/common/config/datasource.h
- source/common/config/null_grpc_mux_impl.h
- source/common/config/utility.h
- source/common/config/custom_config_validators_impl.h
- source/common/config/xds_context_params.cc
- source/common/config/custom_config_validators_impl.cc
- source/common/runtime/runtime_impl.cc
- source/common/quic/quic_transport_socket_factory.cc
- source/common/filter/config_discovery_impl.cc
- source/common/event/timer_impl.h
- source/common/matcher/map_matcher.h
- source/common/matcher/field_matcher.h
- source/common/json/json_internal.cc
- source/common/json/json_internal.h
- source/common/json/json_sanitizer.cc
- source/common/router/header_formatter.cc
- source/common/router/scoped_rds.cc
- source/common/router/rds_impl.cc
- source/common/router/config_impl.cc
- source/common/router/config_impl.h
- source/common/router/scoped_config_impl.cc
- source/common/router/router_ratelimit.cc
- source/common/router/vhds.cc
- source/common/router/config_utility.cc
- source/common/router/scoped_rds.h
- source/common/router/header_parser.cc
- source/common/router/config_utility.h
- source/common/rds/rds_route_config_subscription.cc
- source/common/filesystem/inotify/watcher_impl.cc
- source/common/filesystem/posix/directory_iterator_impl.cc
Expand All @@ -195,22 +162,14 @@ paths:
- source/common/filesystem/win32/watcher_impl.cc
- source/common/common/utility.cc
- source/common/common/regex.cc
- source/common/common/logger.h
- source/common/common/thread.h
- source/common/common/utility.h
- source/common/common/matchers.h
- source/common/common/matchers.cc
- source/exe/stripped_main_base.cc
- source/server/options_impl.cc
- source/server/options_impl.h
- source/server/server.h
- source/server/overload_manager_impl.cc
- source/server/config_validation/cluster_manager.cc
- source/server/config_validation/server.cc
- source/server/admin/html/active_stats.js
- source/server/server.cc
- source/server/utils.cc
- source/server/configuration_impl.h
- source/server/hot_restarting_base.cc
- source/server/hot_restart_impl.cc
- source/server/ssl_context_manager.cc
Expand Down

0 comments on commit f54b072

Please sign in to comment.