Skip to content

Commit d7b87ce

Browse files
authored
LocalForwarderChannel (#723)
* added proto files to src folder. added protobuf codegen plugin to build * set package for protobuf java files * removed unneeded files; excluded *.proto from jar * removed c# related file * removed some extra spaces * first pass at refactoring for channel implementation * javadoc for type param; updated tests * finished pull up of common methods to ATelemetryChannel. updated build so IntelliJ can see generated code. removed method overload from interface (bad practice...) implemented simple LocalForwarderTelemetryTransmitter and Factory (doesn't have the retry logic like the InProcess Factory) * ignore generated files. updated build file to shadow services provided with grpc libraries. * Surfaces type and envelope names for classes; Also surfaces BaseData version number. Deprecated *Telemetry classes who's *Data classes were also deprecated. Some additional fields were surfaced which were previously hidden. * if using localforwarder, force sdk quickpulse to be disabled. Fixed some bug with QuickPulse grabbing CPU data before the first datum is initialized; i.e. skip if null. Changed logic so a Nop channel is used if a custom channel is misconfigured and cannot be initialized. * fixed case for key to be consistent with other SDKs * added cleanup code to make thread shutdown more reliable. * implemented channel with transformation functions from internal model to proto model. * recognize if the given name is the default channel. * Instead of disabling telemetry, just log a warning about channel configuration. This should still work if the channel is set after configuration. Use singleton for nop channel and don't actually set channel in TelemetryConfiguration, just return NopTelemetryChannel instance. Updated test to check for nop channel instead of null. * set stddev to 0.0 in this helper method * stubbed in test classes. exposed some methods for testing * added tests for transformation functions. * use %n instead of \n in format string * extracted the exception transformer functions for stackframe and exceptiondetails to be visiblefortesting corrected one precondition which was casing issues. * wrote tests for the utility functions in the localforwarder transformer functions * extracted transmitter into its own class. wrote test for transmitter. * added assert to fail if timeout is reached * wrote tests for localforwarderchanel. exposed some methods for inserting mocks. removed final from some classes so they could be mocked. * added grpc-test to build and created proper transmitter test. reworked parameters in transmitter constructor to be more easily testable. removed endpoint field since it's not necessary to keep around. * renamed abstract class to fit project conventions * added javadoc * using private lock object instead * we should throw if it fails to configure * ENVELOPE_NAME can be private * MetricTelemetry.ENVELOPE_NAME cannot be private, though... * fix spacing * we only need 1 thread minimum * remove redundant null check * fixed typo * Revert "ENVELOPE_NAME can be private" This reverts commit 0fb0898. * removed unused import * added isInitialized to prevent calling initialize twice * removed additional field in Envelope since it's generated. * removed unused import. * fixed tests after refactor * remove enableRetry from ManagedChannel; we don't want to use experimental API * removed commented code in build script * updated TPN * reworked shutdown to be aysnc. added retry to grpcchannel * removed sync * updated changelog * added null check for test scenario
1 parent 8f40f7f commit d7b87ce

File tree

44 files changed

+2576
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2576
-439
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Introduced `CloudContext` to hold replacements, `getRole`/`setRole` and `getRole
1313
`DeviceInfoContextInitializer` will continue to send the deprecated field in `DeviceContext`.
1414
This will be removed in a future release.
1515
Users should use begin using the `CloudInfoContextInitializer` to continue to receive the proper value for `cloud_roleInstance` in telemetry items.
16+
- Adds `LocalForwarderChannel` for use with the LocalForwarder.
1617

1718
# Version 2.1.2
1819
- Fix [#676](https://github.com/Microsoft/ApplicationInsights-Java/issues/676). This fixes the HTTP dependency collection when using NetFlix Zuul Library.

ThirdPartyNotices.txt

Lines changed: 217 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Microsoft Application Insights Java Software Development Kit consists of materia
1818
10. Guava version 12.0.1 (http://code.google.com/p/guava-libraries/)
1919
11. INFOMAS PCM Application Suite version 3.0.4 (https://github.com/rmuller/infomas-asl)
2020
12. JSR-305 version 2.0.1 (http://code.google.com/p/jsr-305/)
21+
13. Protobuf-java version 3.6.1 (https://github.com/protocolbuffers/protobuf)
22+
14. gRPC Stubs version 1.14.0 (https://github.com/grpc/grpc-java)
23+
15. gRPC Protobuf version 1.14.0 (https://github.com/grpc/grpc-java)
24+
16. gRPC Netty-shaded version 1.14.0 (https://github.com/grpc/grpc-java)
2125

2226
%% Apache Commons-codec NOTICES, INFORMATION, AND LICENSE BEGIN HERE
2327
=========================================
@@ -862,4 +866,216 @@ Code generated by the Protocol Buffer compiler is owned by the owner
862866
of the input file used when generating it. This code is not
863867
standalone and requires a support library to be linked with it. This
864868
support library is itself covered by the above license.
865-
=========================================
869+
=========================================
870+
871+
872+
=========================================
873+
gRPC Stubs,
874+
gRPC Protobuf,
875+
gRPC Netty-shaded
876+
877+
Copyright 2014 The gRPC Authors
878+
879+
Apache License
880+
Version 2.0, January 2004
881+
http://www.apache.org/licenses/
882+
883+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
884+
885+
1. Definitions.
886+
887+
"License" shall mean the terms and conditions for use, reproduction,
888+
and distribution as defined by Sections 1 through 9 of this document.
889+
890+
"Licensor" shall mean the copyright owner or entity authorized by
891+
the copyright owner that is granting the License.
892+
893+
"Legal Entity" shall mean the union of the acting entity and all
894+
other entities that control, are controlled by, or are under common
895+
control with that entity. For the purposes of this definition,
896+
"control" means (i) the power, direct or indirect, to cause the
897+
direction or management of such entity, whether by contract or
898+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
899+
outstanding shares, or (iii) beneficial ownership of such entity.
900+
901+
"You" (or "Your") shall mean an individual or Legal Entity
902+
exercising permissions granted by this License.
903+
904+
"Source" form shall mean the preferred form for making modifications,
905+
including but not limited to software source code, documentation
906+
source, and configuration files.
907+
908+
"Object" form shall mean any form resulting from mechanical
909+
transformation or translation of a Source form, including but
910+
not limited to compiled object code, generated documentation,
911+
and conversions to other media types.
912+
913+
"Work" shall mean the work of authorship, whether in Source or
914+
Object form, made available under the License, as indicated by a
915+
copyright notice that is included in or attached to the work
916+
(an example is provided in the Appendix below).
917+
918+
"Derivative Works" shall mean any work, whether in Source or Object
919+
form, that is based on (or derived from) the Work and for which the
920+
editorial revisions, annotations, elaborations, or other modifications
921+
represent, as a whole, an original work of authorship. For the purposes
922+
of this License, Derivative Works shall not include works that remain
923+
separable from, or merely link (or bind by name) to the interfaces of,
924+
the Work and Derivative Works thereof.
925+
926+
"Contribution" shall mean any work of authorship, including
927+
the original version of the Work and any modifications or additions
928+
to that Work or Derivative Works thereof, that is intentionally
929+
submitted to Licensor for inclusion in the Work by the copyright owner
930+
or by an individual or Legal Entity authorized to submit on behalf of
931+
the copyright owner. For the purposes of this definition, "submitted"
932+
means any form of electronic, verbal, or written communication sent
933+
to the Licensor or its representatives, including but not limited to
934+
communication on electronic mailing lists, source code control systems,
935+
and issue tracking systems that are managed by, or on behalf of, the
936+
Licensor for the purpose of discussing and improving the Work, but
937+
excluding communication that is conspicuously marked or otherwise
938+
designated in writing by the copyright owner as "Not a Contribution."
939+
940+
"Contributor" shall mean Licensor and any individual or Legal Entity
941+
on behalf of whom a Contribution has been received by Licensor and
942+
subsequently incorporated within the Work.
943+
944+
2. Grant of Copyright License. Subject to the terms and conditions of
945+
this License, each Contributor hereby grants to You a perpetual,
946+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
947+
copyright license to reproduce, prepare Derivative Works of,
948+
publicly display, publicly perform, sublicense, and distribute the
949+
Work and such Derivative Works in Source or Object form.
950+
951+
3. Grant of Patent License. Subject to the terms and conditions of
952+
this License, each Contributor hereby grants to You a perpetual,
953+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
954+
(except as stated in this section) patent license to make, have made,
955+
use, offer to sell, sell, import, and otherwise transfer the Work,
956+
where such license applies only to those patent claims licensable
957+
by such Contributor that are necessarily infringed by their
958+
Contribution(s) alone or by combination of their Contribution(s)
959+
with the Work to which such Contribution(s) was submitted. If You
960+
institute patent litigation against any entity (including a
961+
cross-claim or counterclaim in a lawsuit) alleging that the Work
962+
or a Contribution incorporated within the Work constitutes direct
963+
or contributory patent infringement, then any patent licenses
964+
granted to You under this License for that Work shall terminate
965+
as of the date such litigation is filed.
966+
967+
4. Redistribution. You may reproduce and distribute copies of the
968+
Work or Derivative Works thereof in any medium, with or without
969+
modifications, and in Source or Object form, provided that You
970+
meet the following conditions:
971+
972+
(a) You must give any other recipients of the Work or
973+
Derivative Works a copy of this License; and
974+
975+
(b) You must cause any modified files to carry prominent notices
976+
stating that You changed the files; and
977+
978+
(c) You must retain, in the Source form of any Derivative Works
979+
that You distribute, all copyright, patent, trademark, and
980+
attribution notices from the Source form of the Work,
981+
excluding those notices that do not pertain to any part of
982+
the Derivative Works; and
983+
984+
(d) If the Work includes a "NOTICE" text file as part of its
985+
distribution, then any Derivative Works that You distribute must
986+
include a readable copy of the attribution notices contained
987+
within such NOTICE file, excluding those notices that do not
988+
pertain to any part of the Derivative Works, in at least one
989+
of the following places: within a NOTICE text file distributed
990+
as part of the Derivative Works; within the Source form or
991+
documentation, if provided along with the Derivative Works; or,
992+
within a display generated by the Derivative Works, if and
993+
wherever such third-party notices normally appear. The contents
994+
of the NOTICE file are for informational purposes only and
995+
do not modify the License. You may add Your own attribution
996+
notices within Derivative Works that You distribute, alongside
997+
or as an addendum to the NOTICE text from the Work, provided
998+
that such additional attribution notices cannot be construed
999+
as modifying the License.
1000+
1001+
You may add Your own copyright statement to Your modifications and
1002+
may provide additional or different license terms and conditions
1003+
for use, reproduction, or distribution of Your modifications, or
1004+
for any such Derivative Works as a whole, provided Your use,
1005+
reproduction, and distribution of the Work otherwise complies with
1006+
the conditions stated in this License.
1007+
1008+
5. Submission of Contributions. Unless You explicitly state otherwise,
1009+
any Contribution intentionally submitted for inclusion in the Work
1010+
by You to the Licensor shall be under the terms and conditions of
1011+
this License, without any additional terms or conditions.
1012+
Notwithstanding the above, nothing herein shall supersede or modify
1013+
the terms of any separate license agreement you may have executed
1014+
with Licensor regarding such Contributions.
1015+
1016+
6. Trademarks. This License does not grant permission to use the trade
1017+
names, trademarks, service marks, or product names of the Licensor,
1018+
except as required for reasonable and customary use in describing the
1019+
origin of the Work and reproducing the content of the NOTICE file.
1020+
1021+
7. Disclaimer of Warranty. Unless required by applicable law or
1022+
agreed to in writing, Licensor provides the Work (and each
1023+
Contributor provides its Contributions) on an "AS IS" BASIS,
1024+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1025+
implied, including, without limitation, any warranties or conditions
1026+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
1027+
PARTICULAR PURPOSE. You are solely responsible for determining the
1028+
appropriateness of using or redistributing the Work and assume any
1029+
risks associated with Your exercise of permissions under this License.
1030+
1031+
8. Limitation of Liability. In no event and under no legal theory,
1032+
whether in tort (including negligence), contract, or otherwise,
1033+
unless required by applicable law (such as deliberate and grossly
1034+
negligent acts) or agreed to in writing, shall any Contributor be
1035+
liable to You for damages, including any direct, indirect, special,
1036+
incidental, or consequential damages of any character arising as a
1037+
result of this License or out of the use or inability to use the
1038+
Work (including but not limited to damages for loss of goodwill,
1039+
work stoppage, computer failure or malfunction, or any and all
1040+
other commercial damages or losses), even if such Contributor
1041+
has been advised of the possibility of such damages.
1042+
1043+
9. Accepting Warranty or Additional Liability. While redistributing
1044+
the Work or Derivative Works thereof, You may choose to offer,
1045+
and charge a fee for, acceptance of support, warranty, indemnity,
1046+
or other liability obligations and/or rights consistent with this
1047+
License. However, in accepting such obligations, You may act only
1048+
on Your own behalf and on Your sole responsibility, not on behalf
1049+
of any other Contributor, and only if You agree to indemnify,
1050+
defend, and hold each Contributor harmless for any liability
1051+
incurred by, or claims asserted against, such Contributor by reason
1052+
of your accepting any such warranty or additional liability.
1053+
1054+
END OF TERMS AND CONDITIONS
1055+
1056+
APPENDIX: How to apply the Apache License to your work.
1057+
1058+
To apply the Apache License to your work, attach the following
1059+
boilerplate notice, with the fields enclosed by brackets "[]"
1060+
replaced with your own identifying information. (Don't include
1061+
the brackets!) The text should be enclosed in the appropriate
1062+
comment syntax for the file format. We also recommend that a
1063+
file or class name and description of purpose be included on the
1064+
same "printed page" as the copyright notice for easier
1065+
identification within third-party archives.
1066+
1067+
Copyright [yyyy] [name of copyright owner]
1068+
1069+
Licensed under the Apache License, Version 2.0 (the "License");
1070+
you may not use this file except in compliance with the License.
1071+
You may obtain a copy of the License at
1072+
1073+
http://www.apache.org/licenses/LICENSE-2.0
1074+
1075+
Unless required by applicable law or agreed to in writing, software
1076+
distributed under the License is distributed on an "AS IS" BASIS,
1077+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1078+
See the License for the specific language governing permissions and
1079+
limitations under the License.
1080+
1081+

azure-application-insights-spring-boot-starter/src/main/java/com/microsoft/applicationinsights/autoconfigure/ApplicationInsightsProperties.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package com.microsoft.applicationinsights.autoconfigure;
2323

2424
import com.microsoft.applicationinsights.autoconfigure.helpers.IkeyResolver;
25+
import com.microsoft.applicationinsights.channel.concrete.TelemetryChannelBase;
2526
import com.microsoft.applicationinsights.channel.concrete.inprocess.InProcessTelemetryChannel;
2627
import com.microsoft.applicationinsights.internal.channel.common.TransmissionFileSystemOutput;
2728
import com.microsoft.applicationinsights.internal.channel.common.TransmissionNetworkOutput;
@@ -199,10 +200,10 @@ static class InProcess {
199200
* 1000.
200201
*/
201202
private int maxTelemetryBufferCapacity =
202-
InProcessTelemetryChannel.DEFAULT_MAX_TELEMETRY_BUFFER_CAPACITY;
203+
TelemetryChannelBase.DEFAULT_MAX_TELEMETRY_BUFFER_CAPACITY;
203204
/** Interval to send telemetry. Must be between 1 and 300. */
204205
private int flushIntervalInSeconds =
205-
InProcessTelemetryChannel.DEFAULT_FLUSH_BUFFER_TIMEOUT_IN_SECONDS;
206+
TelemetryChannelBase.DEFAULT_FLUSH_BUFFER_TIMEOUT_IN_SECONDS;
206207
/**
207208
* Size of disk space that Application Insights can use to store telemetry in case of network
208209
* outage. Must be between 1 and 1000.
@@ -213,7 +214,7 @@ static class InProcess {
213214
private boolean throttling = true;
214215

215216
/** Sets the size of maximum instant retries without delay */
216-
private int maxInstantRetry = InProcessTelemetryChannel.DEFAULT_MAX_INSTANT_RETRY;
217+
private int maxInstantRetry = TelemetryChannelBase.DEFAULT_MAX_INSTANT_RETRY;
217218

218219
public boolean isDeveloperMode() {
219220
return developerMode;

core/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/main/generated

core/build.gradle

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ apply from: "$buildScriptsDir/common-java.gradle"
3535
apply from: "$buildScriptsDir/publishing.gradle"
3636

3737
apply plugin: 'com.google.protobuf'
38+
apply plugin: 'idea'
39+
40+
def sdkVersionFileDir = "$project.buildDir/src/generated/main/resources"
41+
42+
def generatedDir = 'generated'
43+
def generatedPath = "src/main/$generatedDir"
44+
45+
idea {
46+
module {
47+
generatedSourceDirs = [ file(generatedPath) ]
48+
49+
sourceDirs += file('src/main/java')
50+
sourceDirs += file(generatedPath)
51+
}
52+
}
3853

3954
protobuf {
4055
protoc {
@@ -48,13 +63,34 @@ protobuf {
4863
generateProtoTasks {
4964
all().each { task ->
5065
task.builtins {
51-
java { }
66+
java {
67+
outputSubDir = generatedDir
68+
}
5269
}
5370
task.plugins {
54-
grpc { }
71+
grpc {
72+
outputSubDir = generatedDir
73+
}
5574
}
5675
}
5776
}
77+
generatedFilesBaseDir = "${projectDir}/src/"
78+
}
79+
80+
sourceSets {
81+
main {
82+
output.dir(generatedPath, builtBy: 'generateProto')
83+
java {
84+
srcDirs generatedPath
85+
}
86+
resources {
87+
srcDir sdkVersionFileDir
88+
}
89+
}
90+
}
91+
92+
clean {
93+
delete 'src/main/generated'
5894
}
5995

6096
import org.apache.tools.ant.taskdefs.condition.Os
@@ -89,15 +125,18 @@ dependencies {
89125
compile ([group: 'com.google.protobuf', name:'protobuf-java', version:'3.6.1'])
90126
compile ([group: 'io.grpc', name: 'grpc-stub', version: '1.14.0'])
91127
compile ([group: 'io.grpc', name: 'grpc-protobuf', version: '1.14.0'])
128+
runtime ([group: 'io.grpc', name: 'grpc-netty-shaded', version: '1.14.0'])
92129
testCompile group:'org.hamcrest', name:'hamcrest-library', version:'1.3'
93130
testCompile group: 'junit', name: 'junit', version: '4.12'
94131
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.19'
95132
testCompile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
133+
testCompile group: 'io.grpc', name:'grpc-testing', version:'1.14.0'
96134
}
97135

98136
ext.dependenciesPrefix = 'com.microsoft.applicationinsights.core.dependencies'
99137
shadowJar {
100138
classifier=''
139+
mergeServiceFiles()
101140
relocate 'org.apache.http', "${dependenciesPrefix}.http"
102141
relocate 'eu.infomas.annotation', "${dependenciesPrefix}.annotation"
103142
relocate 'org.apache.commons', "${dependenciesPrefix}.apachecommons"
@@ -114,22 +153,13 @@ jar {
114153
enabled = false
115154
}
116155

117-
def sdkVersionFileDir = "$project.buildDir/src/generated/main/resources"
118156
task generateVersionProperties(type: PropsFileGen) {
119157
targetFile = new File(sdkVersionFileDir, "sdk-version.properties")
120158
property "version", project.version
121159
}
122160

123161
processResources.dependsOn generateVersionProperties
124162

125-
sourceSets {
126-
main {
127-
resources {
128-
srcDir sdkVersionFileDir
129-
}
130-
}
131-
}
132-
133163
// region Publishing properties
134164

135165
projectPomName = project.msftAppInsights + " Java SDK Core"

core/src/main/java/com/microsoft/applicationinsights/TelemetryClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public void flush() {
516516
* Gets the channel used by the client.
517517
*/
518518
TelemetryChannel getChannel() {
519-
if (channel == null) {
519+
if (this.channel == null) {
520520
this.channel = configuration.getChannel();
521521
}
522522

0 commit comments

Comments
 (0)