Repository: tetratelabs/getenvoy (go)

Issue:
ci: consider removing use of `chrono` library from Rust init templates since it's the slowest to compile in `e2e` tests on Mac
**Is your feature request related to a problem? Please describe.**

* `e2e` tests on `Mac` are much slower than on `Linux` (e.g., `40 min` vs `10 min`)
* tests for extensions in `Rust` take `3x` more time than tests for `TinyGo` (because `Rust` extension templates have more dependent libraries and it simply takes more time to compile them all)
* it seems that `chrono` library is the slowest to compile

**Describe the solution you'd like**

* consider removing use of `chrono` library in Rust init templates to speed up `e2e` tests on `Mac`
* this might cut `~5 min` out of `40 min`

**Describe alternatives you've considered**

N/A

**Additional context**

N/A

Pull request description:
Removes chrono from rust extension examples
This removes chrono from the logging examples. Using this library
contributes to compilation time and is also unrealistic as logging
libraries typically perform their own timestamps. We used the chrono
lib to convert the envoy time into a timestamp, but it is better for the
build to not use that api.

This also removes unused build aliases and renames .cargo/config to
.cargo/config.toml per recommendations:
https://doc.rust-lang.org/cargo/reference/config.html

Fixes #144

Patch:
diff --git a/data/extension/init/templates/rust/envoy.access_loggers/default/Cargo.toml b/data/extension/init/templates/rust/envoy.access_loggers/default/Cargo.toml
index 232e6dd..3b42404 100644
--- a/data/extension/init/templates/rust/envoy.access_loggers/default/Cargo.toml
+++ b/data/extension/init/templates/rust/envoy.access_loggers/default/Cargo.toml
@@ -19,4 +19,3 @@ crate-type = ["rlib"]
 envoy = { package = "envoy-sdk", version = "^0.2.0-alpha.1" }
 serde = { version = "^1.0", features = ["derive"] }
 serde_json = "^1.0"
-chrono = "^0.4"
diff --git a/data/extension/init/templates/rust/envoy.access_loggers/default/cargo/config b/data/extension/init/templates/rust/envoy.access_loggers/default/cargo/config.toml
similarity index 80%
rename from data/extension/init/templates/rust/envoy.access_loggers/default/cargo/config
rename to data/extension/init/templates/rust/envoy.access_loggers/default/cargo/config.toml
index 9c3fe36..b60e6c5 100644
--- a/data/extension/init/templates/rust/envoy.access_loggers/default/cargo/config
+++ b/data/extension/init/templates/rust/envoy.access_loggers/default/cargo/config.toml
@@ -1,7 +1,3 @@
-[alias]
-"build:wasm" = ["build", "--target", "wasm32-unknown-unknown"]
-"check:wasm" = ["check", "--target", "wasm32-unknown-unknown"]
-
 # To be able to run unit tests on macOS, support compilation to 'x86_64-apple-darwin'.
 [target.'cfg(target_vendor = "apple")']
 rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]
diff --git a/data/extension/init/templates/rust/envoy.access_loggers/default/src/logger.rs b/data/extension/init/templates/rust/envoy.access_loggers/default/src/logger.rs
index f0d5650..7d4e21d 100644
--- a/data/extension/init/templates/rust/envoy.access_loggers/default/src/logger.rs
+++ b/data/extension/init/templates/rust/envoy.access_loggers/default/src/logger.rs
@@ -1,7 +1,5 @@
 use std::convert::TryFrom;
 
-use chrono::{offset::Local, DateTime};
-
 use envoy::extension::{access_logger, AccessLogger, ConfigStatus, Result};
 use envoy::host::{log, ByteString, Clock, Stats};
 
@@ -67,11 +65,9 @@ impl<'a> AccessLogger for SampleAccessLogger<'a> {
         // Update stats
         self.stats.log_entries_total().inc()?;
 
-        let now: DateTime<Local> = self.clock.now()?.into();
-
         log::info!(
-            "logging at {} with config: {:?}",
-            now.format("%+"),
+            "logging at {:?} with config: {:?}",
+            self.clock.now()?,
             self.config,
         );
 
diff --git a/data/extension/init/templates/rust/envoy.filters.http/default/Cargo.toml b/data/extension/init/templates/rust/envoy.filters.http/default/Cargo.toml
index c09bdac..62183bd 100644
--- a/data/extension/init/templates/rust/envoy.filters.http/default/Cargo.toml
+++ b/data/extension/init/templates/rust/envoy.filters.http/default/Cargo.toml
@@ -19,4 +19,3 @@ crate-type = ["rlib"]
 envoy = { package = "envoy-sdk", version = "^0.2.0-alpha.1" }
 serde = { version = "^1.0", features = ["derive"] }
 serde_json = "^1.0"
-chrono = "^0.4"
diff --git a/data/extension/init/templates/rust/envoy.filters.http/default/cargo/config b/data/extension/init/templates/rust/envoy.filters.http/default/cargo/config.toml
similarity index 80%
rename from data/extension/init/templates/rust/envoy.filters.http/default/cargo/config
rename to data/extension/init/templates/rust/envoy.filters.http/default/cargo/config.toml
index 9c3fe36..b60e6c5 100644
--- a/data/extension/init/templates/rust/envoy.filters.http/default/cargo/config
+++ b/data/extension/init/templates/rust/envoy.filters.http/default/cargo/config.toml
@@ -1,7 +1,3 @@
-[alias]
-"build:wasm" = ["build", "--target", "wasm32-unknown-unknown"]
-"check:wasm" = ["check", "--target", "wasm32-unknown-unknown"]
-
 # To be able to run unit tests on macOS, support compilation to 'x86_64-apple-darwin'.
 [target.'cfg(target_vendor = "apple")']
 rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]
diff --git a/data/extension/init/templates/rust/envoy.filters.http/default/src/filter.rs b/data/extension/init/templates/rust/envoy.filters.http/default/src/filter.rs
index 1ffdb18..1f5baee 100644
--- a/data/extension/init/templates/rust/envoy.filters.http/default/src/filter.rs
+++ b/data/extension/init/templates/rust/envoy.filters.http/default/src/filter.rs
@@ -1,7 +1,5 @@
 use std::rc::Rc;
 
-use chrono::{offset::Local, DateTime};
-
 use envoy::extension::{filter::http, HttpFilter, InstanceId, Result};
 use envoy::host::log::info;
 use envoy::host::Clock;
@@ -50,12 +48,10 @@ impl<'a> HttpFilter for SampleHttpFilter<'a> {
         _end_of_stream: bool,
         filter_ops: &dyn http::RequestHeadersOps,
     ) -> Result<http::FilterHeadersStatus> {
-        let now: DateTime<Local> = self.clock.now()?.into();
-
         info!(
-            "#{} new http exchange starts at {} with config: {:?}",
+            "#{} new http exchange starts at {:?} with config: {:?}",
             self.instance_id,
-            now.format("%+"),
+            self.clock.now()?,
             self.config,
         );
 
diff --git a/data/extension/init/templates/rust/envoy.filters.network/default/Cargo.toml b/data/extension/init/templates/rust/envoy.filters.network/default/Cargo.toml
index 891d907..4f53b05 100644
--- a/data/extension/init/templates/rust/envoy.filters.network/default/Cargo.toml
+++ b/data/extension/init/templates/rust/envoy.filters.network/default/Cargo.toml
@@ -19,4 +19,3 @@ crate-type = ["rlib"]
 envoy = { package = "envoy-sdk", version = "^0.2.0-alpha.1" }
 serde = { version = "^1.0", features = ["derive"] }
 serde_json = "^1.0"
-chrono = "^0.4"
diff --git a/data/extension/init/templates/rust/envoy.filters.network/default/cargo/config b/data/extension/init/templates/rust/envoy.filters.network/default/cargo/config.toml
similarity index 80%
rename from data/extension/init/templates/rust/envoy.filters.network/default/cargo/config
rename to data/extension/init/templates/rust/envoy.filters.network/default/cargo/config.toml
index 9c3fe36..b60e6c5 100644
--- a/data/extension/init/templates/rust/envoy.filters.network/default/cargo/config
+++ b/data/extension/init/templates/rust/envoy.filters.network/default/cargo/config.toml
@@ -1,7 +1,3 @@
-[alias]
-"build:wasm" = ["build", "--target", "wasm32-unknown-unknown"]
-"check:wasm" = ["check", "--target", "wasm32-unknown-unknown"]
-
 # To be able to run unit tests on macOS, support compilation to 'x86_64-apple-darwin'.
 [target.'cfg(target_vendor = "apple")']
 rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]
diff --git a/data/extension/init/templates/rust/envoy.filters.network/default/src/filter.rs b/data/extension/init/templates/rust/envoy.filters.network/default/src/filter.rs
index d7934ac..2692d66 100644
--- a/data/extension/init/templates/rust/envoy.filters.network/default/src/filter.rs
+++ b/data/extension/init/templates/rust/envoy.filters.network/default/src/filter.rs
@@ -1,7 +1,5 @@
 use std::rc::Rc;
 
-use chrono::{offset::Local, DateTime};
-
 use envoy::extension::{filter::network, InstanceId, NetworkFilter, Result};
 use envoy::host::log::info;
 use envoy::host::Clock;
@@ -43,12 +41,10 @@ impl<'a> SampleNetworkFilter<'a> {
 impl<'a> NetworkFilter for SampleNetworkFilter<'a> {
     /// Called when a new TCP connection is opened.
     fn on_new_connection(&mut self) -> Result<network::FilterStatus> {
-        let now: DateTime<Local> = self.clock.now()?.into();
-
         info!(
-            "#{} new TCP connection starts at {} with config: {:?}",
+            "#{} new TCP connection starts at {:?} with config: {:?}",
             self.instance_id,
-            now.format("%+"),
+            self.clock.now()?,
             self.config,
         );
 


Test patch:
diff --git a/pkg/cmd/extension/init/cmd_test.go b/pkg/cmd/extension/init/cmd_test.go
index 9afa767..d40d451 100644
--- a/pkg/cmd/extension/init/cmd_test.go
+++ b/pkg/cmd/extension/init/cmd_test.go
@@ -187,7 +187,7 @@ func TestGetEnvoyExtensionInit(t *testing.T) {
 			switch test.Language {
 			case extension.LanguageRust:
 				languageSpecificPaths = []string{
-					".cargo/config",
+					".cargo/config.toml",
 					"Cargo.toml",
 					"README.md",
 					"src/config.rs",
diff --git a/test/e2e/getenvoy_extension_init_test.go b/test/e2e/getenvoy_extension_init_test.go
index f07ee9b..2c42f7f 100644
--- a/test/e2e/getenvoy_extension_init_test.go
+++ b/test/e2e/getenvoy_extension_init_test.go
@@ -111,7 +111,7 @@ func TestGetEnvoyExtensionInit(t *testing.T) {
 			switch test.Language {
 			case extension.LanguageRust:
 				languageSpecificPaths = []string{
-					".cargo/config",
+					".cargo/config.toml",
 					"Cargo.toml",
 					"README.md",
 					"src/config.rs",