Update Proxy heartbeat & logging (#502)

This commit is contained in:
bmc-msft
2021-02-04 15:38:17 -05:00
committed by GitHub
parent 4abfbeca56
commit c5bb0f0588
7 changed files with 294 additions and 56 deletions

View File

@ -74,6 +74,7 @@ pub enum EventData {
CoveragePathsImported(u64), CoveragePathsImported(u64),
CoverageMaxDepth(u64), CoverageMaxDepth(u64),
ToolName(String), ToolName(String),
Region(String),
} }
impl EventData { impl EventData {
@ -109,6 +110,7 @@ impl EventData {
Self::CoverageMaxDepth(x) => ("coverage_paths_depth", x.to_string()), Self::CoverageMaxDepth(x) => ("coverage_paths_depth", x.to_string()),
Self::Coverage(x) => ("coverage", x.to_string()), Self::Coverage(x) => ("coverage", x.to_string()),
Self::ToolName(x) => ("tool_name", x.to_owned()), Self::ToolName(x) => ("tool_name", x.to_owned()),
Self::Region(x) => ("region", x.to_owned()),
} }
} }
@ -146,6 +148,7 @@ impl EventData {
Self::CoverageMaxDepth(_) => true, Self::CoverageMaxDepth(_) => true,
Self::Coverage(_) => true, Self::Coverage(_) => true,
Self::ToolName(_) => true, Self::ToolName(_) => true,
Self::Region(_) => false,
} }
} }
} }

View File

@ -5,6 +5,7 @@
import datetime import datetime
import logging import logging
import os
from typing import List, Optional, Tuple from typing import List, Optional, Tuple
from azure.mgmt.compute.models import VirtualMachine from azure.mgmt.compute.models import VirtualMachine
@ -23,6 +24,7 @@ from pydantic import Field
from .__version__ import __version__ from .__version__ import __version__
from .azure.auth import build_auth from .azure.auth import build_auth
from .azure.containers import get_file_sas_url, save_blob from .azure.containers import get_file_sas_url, save_blob
from .azure.creds import get_instance_id
from .azure.ip import get_public_ip from .azure.ip import get_public_ip
from .azure.queue import get_queue_sas from .azure.queue import get_queue_sas
from .azure.storage import StorageType from .azure.storage import StorageType
@ -211,6 +213,9 @@ class Proxy(ORMMixin):
), ),
forwards=forwards, forwards=forwards,
region=self.region, region=self.region,
instrumentation_key=os.environ.get("APPINSIGHTS_INSTRUMENTATIONKEY"),
telemetry_key=os.environ.get("ONEFUZZ_TELEMETRY"),
instance_id=get_instance_id(),
) )
save_blob( save_blob(

View File

@ -24,6 +24,25 @@ version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c0df63cb2955042487fad3aefd2c6e3ae7389ac5dc1beb28921de0b69f779d4" checksum = "2c0df63cb2955042487fad3aefd2c6e3ae7389ac5dc1beb28921de0b69f779d4"
[[package]]
name = "appinsights"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ae436410b1221062849ced02d4acd4193cbe2f27da551bc0053dfdf3a66edf6"
dependencies = [
"chrono",
"crossbeam-channel",
"hostname",
"http",
"log",
"paste",
"reqwest",
"serde",
"serde_json",
"sm",
"uuid",
]
[[package]] [[package]]
name = "async-channel" name = "async-channel"
version = "1.5.1" version = "1.5.1"
@ -102,7 +121,7 @@ dependencies = [
"async-io", "async-io",
"async-mutex", "async-mutex",
"blocking", "blocking",
"crossbeam-utils", "crossbeam-utils 0.8.1",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"futures-io", "futures-io",
@ -131,9 +150,9 @@ version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d3a45e77e34375a7923b1e8febb049bb011f064714a8e17a1a616fef01da13d" checksum = "8d3a45e77e34375a7923b1e8febb049bb011f064714a8e17a1a616fef01da13d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 1.0.24",
"quote", "quote 1.0.7",
"syn", "syn 1.0.54",
] ]
[[package]] [[package]]
@ -240,6 +259,19 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.33.3" version = "2.33.3"
@ -280,6 +312,27 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b"
[[package]]
name = "crossbeam-channel"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87"
dependencies = [
"crossbeam-utils 0.7.2",
"maybe-uninit",
]
[[package]]
name = "crossbeam-utils"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
dependencies = [
"autocfg",
"cfg-if 0.1.10",
"lazy_static",
]
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.1" version = "0.8.1"
@ -445,9 +498,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77408a692f1f97bcc61dc001d752e00643408fbc922e4d634c655df50d595556" checksum = "77408a692f1f97bcc61dc001d752e00643408fbc922e4d634c655df50d595556"
dependencies = [ dependencies = [
"proc-macro-hack", "proc-macro-hack",
"proc-macro2", "proc-macro2 1.0.24",
"quote", "quote 1.0.7",
"syn", "syn 1.0.54",
] ]
[[package]] [[package]]
@ -493,7 +546,18 @@ checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if 0.1.10",
"libc", "libc",
"wasi", "wasi 0.9.0+wasi-snapshot-preview1",
]
[[package]]
name = "getrandom"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
] ]
[[package]] [[package]]
@ -544,6 +608,17 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "hostname"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867"
dependencies = [
"libc",
"match_cfg",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "http" name = "http"
version = "0.2.2" version = "0.2.2"
@ -723,12 +798,24 @@ dependencies = [
"cfg-if 0.1.10", "cfg-if 0.1.10",
] ]
[[package]]
name = "match_cfg"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4"
[[package]] [[package]]
name = "matches" name = "matches"
version = "0.1.8" version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.3.4" version = "2.3.4"
@ -854,6 +941,25 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "num_cpus" name = "num_cpus"
version = "1.13.0" version = "1.13.0"
@ -878,7 +984,7 @@ dependencies = [
"clap", "clap",
"env_logger", "env_logger",
"futures", "futures",
"log", "onefuzz-telemetry",
"reqwest", "reqwest",
"reqwest-retry", "reqwest-retry",
"serde", "serde",
@ -887,6 +993,16 @@ dependencies = [
"thiserror", "thiserror",
"tokio", "tokio",
"url", "url",
"uuid",
]
[[package]]
name = "onefuzz-telemetry"
version = "0.1.0"
dependencies = [
"appinsights",
"log",
"uuid",
] ]
[[package]] [[package]]
@ -928,6 +1044,25 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
[[package]]
name = "paste"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880"
dependencies = [
"paste-impl",
"proc-macro-hack",
]
[[package]]
name = "paste-impl"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6"
dependencies = [
"proc-macro-hack",
]
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.1.0" version = "2.1.0"
@ -958,9 +1093,9 @@ version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 1.0.24",
"quote", "quote 1.0.7",
"syn", "syn 1.0.54",
] ]
[[package]] [[package]]
@ -969,9 +1104,9 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f" checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 1.0.24",
"quote", "quote 1.0.7",
"syn", "syn 1.0.54",
] ]
[[package]] [[package]]
@ -1029,13 +1164,22 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a"
[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid 0.1.0",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.24" version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid 0.2.1",
] ]
[[package]] [[package]]
@ -1044,13 +1188,22 @@ version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [
"proc-macro2 0.4.30",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.7" version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 1.0.24",
] ]
[[package]] [[package]]
@ -1059,7 +1212,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [ dependencies = [
"getrandom", "getrandom 0.1.15",
"libc", "libc",
"rand_chacha", "rand_chacha",
"rand_core", "rand_core",
@ -1082,7 +1235,7 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [ dependencies = [
"getrandom", "getrandom 0.1.15",
] ]
[[package]] [[package]]
@ -1240,9 +1393,9 @@ version = "1.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 1.0.24",
"quote", "quote 1.0.7",
"syn", "syn 1.0.54",
] ]
[[package]] [[package]]
@ -1283,6 +1436,26 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "sm"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8e4a3f3651a411045a4324773afcf10d11919a90c006b94a4178da1d18e5769"
dependencies = [
"sm_macro",
]
[[package]]
name = "sm_macro"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba245bc9067435452e4d8b9af04509929a9e99ce7273c82c2b8551e7f09ee861"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"syn 0.15.44",
]
[[package]] [[package]]
name = "socket2" name = "socket2"
version = "0.3.17" version = "0.3.17"
@ -1318,15 +1491,26 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "syn"
version = "0.15.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"unicode-xid 0.1.0",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.54" version = "1.0.54"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44" checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 1.0.24",
"quote", "quote 1.0.7",
"unicode-xid", "unicode-xid 0.2.1",
] ]
[[package]] [[package]]
@ -1376,9 +1560,9 @@ version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56" checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 1.0.24",
"quote", "quote 1.0.7",
"syn", "syn 1.0.54",
] ]
[[package]] [[package]]
@ -1390,6 +1574,17 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.1.0" version = "1.1.0"
@ -1435,9 +1630,9 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 1.0.24",
"quote", "quote 1.0.7",
"syn", "syn 1.0.54",
] ]
[[package]] [[package]]
@ -1540,6 +1735,12 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.1" version = "0.2.1"
@ -1561,11 +1762,11 @@ dependencies = [
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "0.8.1" version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [ dependencies = [
"rand", "getrandom 0.2.2",
"serde", "serde",
] ]
@ -1615,6 +1816,12 @@ version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.69" version = "0.2.69"
@ -1636,9 +1843,9 @@ dependencies = [
"bumpalo", "bumpalo",
"lazy_static", "lazy_static",
"log", "log",
"proc-macro2", "proc-macro2 1.0.24",
"quote", "quote 1.0.7",
"syn", "syn 1.0.54",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -1660,7 +1867,7 @@ version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084"
dependencies = [ dependencies = [
"quote", "quote 1.0.7",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
] ]
@ -1670,9 +1877,9 @@ version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 1.0.24",
"quote", "quote 1.0.7",
"syn", "syn 1.0.54",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]

View File

@ -11,7 +11,6 @@ anyhow = "1.0"
clap = "2.33" clap = "2.33"
env_logger = "0.7" env_logger = "0.7"
futures = "0.3" futures = "0.3"
log = "0.4"
reqwest = { version = "0.10", features = ["json", "stream"] } reqwest = { version = "0.10", features = ["json", "stream"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
@ -20,3 +19,5 @@ thiserror = "1.0"
tokio = { version = "0.2", features = ["macros", "rt-threaded", "fs", "process"] } tokio = { version = "0.2", features = ["macros", "rt-threaded", "fs", "process"] }
url = { version = "2.1", features = ["serde"] } url = { version = "2.1", features = ["serde"] }
reqwest-retry = { path = "../agent/reqwest-retry"} reqwest-retry = { path = "../agent/reqwest-retry"}
onefuzz-telemetry = { path = "../agent/onefuzz-telemetry" }
uuid = "0.8"

View File

@ -3,12 +3,14 @@
use crate::proxy; use crate::proxy;
use anyhow::Result; use anyhow::Result;
use onefuzz_telemetry::{set_appinsights_clients, EventData};
use reqwest_retry::SendRetry; use reqwest_retry::SendRetry;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{fs::File, io::BufReader, path::PathBuf}; use std::{fs::File, io::BufReader, path::PathBuf};
use storage_queue::QueueClient; use storage_queue::QueueClient;
use thiserror::Error; use thiserror::Error;
use url::Url; use url::Url;
use uuid::Uuid;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum ProxyError { pub enum ProxyError {
@ -40,6 +42,9 @@ pub struct Forward {
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)] #[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
pub struct ConfigData { pub struct ConfigData {
pub instance_id: Uuid,
pub instrumentation_key: Option<Uuid>,
pub telemetry_key: Option<Uuid>,
pub region: String, pub region: String,
pub url: Url, pub url: Url,
pub notification: Url, pub notification: Url,
@ -68,6 +73,12 @@ impl Config {
let data: ConfigData = let data: ConfigData =
serde_json::from_reader(r).map_err(|source| ProxyError::ParseError { source })?; serde_json::from_reader(r).map_err(|source| ProxyError::ParseError { source })?;
set_appinsights_clients(data.instrumentation_key, data.telemetry_key);
onefuzz_telemetry::set_property(EventData::Region(data.region.to_owned()));
onefuzz_telemetry::set_property(EventData::Version(env!("ONEFUZZ_VERSION").to_string()));
onefuzz_telemetry::set_property(EventData::InstanceId(data.instance_id));
Ok(Self { Ok(Self {
config_path, config_path,
data, data,

View File

@ -2,7 +2,7 @@
// Licensed under the MIT License. // Licensed under the MIT License.
#[macro_use] #[macro_use]
extern crate log; extern crate onefuzz_telemetry;
#[macro_use] #[macro_use]
extern crate anyhow; extern crate anyhow;
#[macro_use] #[macro_use]
@ -10,31 +10,39 @@ extern crate clap;
mod config; mod config;
mod proxy; mod proxy;
use anyhow::Result; use anyhow::Result;
use clap::{App, Arg, SubCommand}; use clap::{App, Arg, SubCommand};
use config::{Config, ProxyError::MissingArg}; use config::{Config, ProxyError::MissingArg};
use std::io::Write; use std::{
io::{stdout, Write},
time::Instant,
};
use tokio::{
runtime::Runtime,
time::{delay_for, Duration},
};
const MINIMUM_NOTIFY_INTERVAL: tokio::time::Duration = std::time::Duration::from_secs(120); const MINIMUM_NOTIFY_INTERVAL: Duration = Duration::from_secs(120);
const POLL_INTERVAL: tokio::time::Duration = tokio::time::Duration::from_secs(5); const POLL_INTERVAL: Duration = Duration::from_secs(5);
async fn run(mut proxy_config: Config) -> Result<()> { async fn run(mut proxy_config: Config) -> Result<()> {
let mut last_updated = std::time::Instant::now(); let mut last_notified = Instant::now();
loop { loop {
info!("checking updates"); info!("checking updates");
if proxy_config.update().await? { proxy_config.update().await?;
last_updated = std::time::Instant::now();
} else if last_updated + MINIMUM_NOTIFY_INTERVAL < std::time::Instant::now() { if last_notified + MINIMUM_NOTIFY_INTERVAL < Instant::now() {
proxy_config.notify().await?; proxy_config.notify().await?;
last_updated = std::time::Instant::now(); last_notified = Instant::now();
} }
tokio::time::delay_for(POLL_INTERVAL).await; delay_for(POLL_INTERVAL).await;
} }
} }
fn main() -> Result<()> { fn main() -> Result<()> {
env_logger::init(); env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
let license_cmd = SubCommand::with_name("licenses").about("display third-party licenses"); let license_cmd = SubCommand::with_name("licenses").about("display third-party licenses");
@ -57,7 +65,7 @@ fn main() -> Result<()> {
let matches = app.get_matches(); let matches = app.get_matches();
if matches.subcommand_matches("licenses").is_some() { if matches.subcommand_matches("licenses").is_some() {
std::io::stdout().write_all(include_bytes!("../data/licenses.json"))?; stdout().write_all(include_bytes!("../data/licenses.json"))?;
return Ok(()); return Ok(());
} }
@ -68,6 +76,6 @@ fn main() -> Result<()> {
let proxy = Config::from_file(config_path)?; let proxy = Config::from_file(config_path)?;
info!("parsed initial config"); info!("parsed initial config");
let mut rt = tokio::runtime::Runtime::new()?; let mut rt = Runtime::new()?;
rt.block_on(run(proxy)) rt.block_on(run(proxy))
} }

View File

@ -403,6 +403,9 @@ class ProxyConfig(BaseModel):
notification: str notification: str
region: Region region: Region
forwards: List[Forward] forwards: List[Forward]
instrumentation_key: Optional[str]
telemetry_key: Optional[str]
instance_id: UUID
class ProxyHeartbeat(BaseModel): class ProxyHeartbeat(BaseModel):