Skip to content

Commit 76f397b

Browse files
snakorseElderJames郭刚平
authored
feature: v8 protocol support (#314)
* fix conflict and compatibility of hosting * feature: v8 protocol support * bugfix: UniqueId should support string part * bugfix: StringOrNumValue gethashcode null exception fix. * feature: Component add id value. * optimize: Remove the jar binaries. * optimize: Remove md5 for performance reason. * bugfix: Fix the java bootstrap script error. * bugfix: Component id not being passed to oap server properly. * optimize: Prefer to use the integer value when do transport to reduce the payload. * optimize: Set the HeaderVersions.SW6 as default. * bugfix: Register the CLRStatsService and its dependency into IOC * bugfix: Set HeaderVersions.SW8 as default * Optimize: Remove old protocol related code && Change traceId to string && Support config instance name Co-authored-by: ElderJames <shunjiey@hotmail.com> Co-authored-by: 郭刚平 <gangping.guo@xiaobao100.com>
1 parent 8cb2a1f commit 76f397b

File tree

62 files changed

+636
-1354
lines changed

Some content is hidden

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

62 files changed

+636
-1354
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,6 @@ tools/
265265
*.proto
266266

267267
generated/
268+
generated-v3/
268269

270+
/sample/java-integration-demo/agent

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
[submodule "src/SkyApm.Transport.Grpc.Protocol/protocol"]
33
path = src/SkyApm.Transport.Grpc.Protocol/protocol
44
url = https://github.com/apache/incubator-skywalking-data-collect-protocol
5+
[submodule "src/SkyApm.Transport.Grpc.Protocol/protocol-v3"]
6+
path = src/SkyApm.Transport.Grpc.Protocol/protocol-v3
7+
url = https://github.com/apache/incubator-skywalking-data-collect-protocol

benchmark/SkyApm.Benchmark/SkyApm.Benchmark.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<PackageReference Include="BenchmarkDotNet" Version="0.*" />
1010

1111
<ProjectReference Include="..\..\src\SkyApm.Core\SkyApm.Core.csproj" />
12+
13+
<ProjectReference Include="..\..\src\SkyApm.Utilities.Configuration\SkyApm.Utilities.Configuration.csproj" />
1214
</ItemGroup>
1315

1416
</Project>

benchmark/SkyApm.Benchmark/UniqueIdGenerate.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
using BenchmarkDotNet.Attributes;
2+
using SkyApm.Config;
23
using SkyApm.Tracing;
4+
using SkyApm.Utilities.Configuration;
5+
using System;
6+
using System.Collections;
7+
using System.Linq;
38

49
namespace SkyApm.Benchmark
510
{
611
public class UniqueIdGenerate
712
{
8-
private static readonly IUniqueIdGenerator Generator = new UniqueIdGenerator(new RuntimeEnvironment());
13+
private static readonly IUniqueIdGenerator Generator;
14+
15+
static UniqueIdGenerate()
16+
{
17+
var configFactory = new ConfigurationFactory(null, Enumerable.Empty<IAdditionalConfigurationSource>());
18+
var configAccessor = new ConfigAccessor(configFactory);
19+
Generator = new UniqueIdGenerator(configAccessor);
20+
}
921

1022
[Benchmark]
1123
public void Generate() => Generator.Generate();

benchmark/SkyApm.Benchmark/UniqueIdParse.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

sample/SkyApm.Sample.Backend/skyapm.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"ServiceName": "asp-net-core-backend",
44
"Namespace": "",
55
"HeaderVersions": [
6-
"sw6"
6+
"sw8"
77
],
88
"Sampling": {
99
"SamplePer3Secs": -1,
@@ -15,7 +15,7 @@
1515
},
1616
"Transport": {
1717
"Interval": 3000,
18-
"ProtocolVersion": "v6",
18+
"ProtocolVersion": "v8",
1919
"QueueSize": 30000,
2020
"BatchSize": 3000,
2121
"gRPC": {

sample/SkyApm.Sample.Frontend/Controllers/ValuesController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ public async Task<IActionResult> SayHelloWithExceptionAsync(string name)
6666
return Ok(message);
6767
}
6868

69+
[HttpGet("hellojava")]
70+
public async Task<IActionResult> HelloJava()
71+
{
72+
var message = await new HttpClient().GetStringAsync("http://localhost:8086/sayhello");
73+
return Ok(message);
74+
}
75+
6976
#if NETCOREAPP2_1
7077
#else
7178
[HttpGet("greeter/grpc-net")]

sample/SkyApm.Sample.Frontend/skyapm.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"ServiceName": "asp-net-core-frontend",
44
"Namespace": "",
55
"HeaderVersions": [
6-
"sw6"
6+
"sw8"
77
],
88
"Sampling": {
99
"SamplePer3Secs": -1,
@@ -15,7 +15,7 @@
1515
},
1616
"Transport": {
1717
"Interval": 3000,
18-
"ProtocolVersion": "v6",
18+
"ProtocolVersion": "v8",
1919
"QueueSize": 30000,
2020
"BatchSize": 3000,
2121
"gRPC": {

sample/SkyApm.Sample.GenericHost/SkyApm.Sample.GenericHost.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
1212
</Content>
1313
</ItemGroup>
14-
1514
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
1615
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.0" />
1716
</ItemGroup>

src/SkyApm.Abstractions/Common/Components.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ namespace SkyApm.Common
2020
{
2121
public static class Components
2222
{
23-
public static readonly StringOrIntValue ASPNETCORE= new StringOrIntValue("AspNetCore");
23+
public static readonly StringOrIntValue ASPNETCORE= new StringOrIntValue(3001, "AspNetCore");
2424

25-
public static readonly StringOrIntValue HTTPCLIENT = new StringOrIntValue("HttpClient");
25+
public static readonly StringOrIntValue HTTPCLIENT = new StringOrIntValue(2, "HttpClient");
2626

27-
public static readonly StringOrIntValue ENTITYFRAMEWORKCORE = new StringOrIntValue("EntityFrameworkCore");
27+
public static readonly StringOrIntValue ENTITYFRAMEWORKCORE = new StringOrIntValue(3002, "EntityFrameworkCore");
2828

29-
public static readonly StringOrIntValue SQLCLIENT = new StringOrIntValue("SqlClient");
29+
public static readonly StringOrIntValue SQLCLIENT = new StringOrIntValue(3003, "SqlClient");
3030

31-
public static readonly StringOrIntValue CAP = new StringOrIntValue("CAP");
31+
public static readonly StringOrIntValue CAP = new StringOrIntValue(3004, "CAP");
3232

33-
public static readonly StringOrIntValue ENTITYFRAMEWORKCORE_SQLITE = new StringOrIntValue("EntityFrameworkCore.Sqlite");
33+
public static readonly StringOrIntValue ENTITYFRAMEWORKCORE_SQLITE = new StringOrIntValue(3011, "EntityFrameworkCore.Sqlite");
3434

35-
public static readonly StringOrIntValue POMELO_ENTITYFRAMEWORKCORE_MYSQL = new StringOrIntValue("Pomelo.EntityFrameworkCore.MySql");
35+
public static readonly StringOrIntValue POMELO_ENTITYFRAMEWORKCORE_MYSQL = new StringOrIntValue(3012, "Pomelo.EntityFrameworkCore.MySql");
3636

37-
public static readonly StringOrIntValue NPGSQL_ENTITYFRAMEWORKCORE_POSTGRESQL = new StringOrIntValue("Npgsql.EntityFrameworkCore.PostgreSQL");
37+
public static readonly StringOrIntValue NPGSQL_ENTITYFRAMEWORKCORE_POSTGRESQL = new StringOrIntValue(3013, "Npgsql.EntityFrameworkCore.PostgreSQL");
3838

39-
public static readonly StringOrIntValue ASPNET = new StringOrIntValue("AspNet");
39+
public static readonly StringOrIntValue ASPNET = new StringOrIntValue(3015, "AspNet");
4040

41-
public static readonly StringOrIntValue SMART_SQL = new StringOrIntValue("SmartSql");
41+
public static readonly StringOrIntValue SMART_SQL = new StringOrIntValue(3016, "SmartSql");
4242

43-
public static readonly StringOrIntValue GRPC = new StringOrIntValue("GRPC");
43+
public static readonly StringOrIntValue GRPC = new StringOrIntValue(23, "GRPC");
4444
}
4545
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Licensed to the SkyAPM under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The SkyAPM licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
using System;
20+
21+
namespace SkyApm.Common
22+
{
23+
public struct StringOrNumValue<T> : IEquatable<StringOrNumValue<T>> where T : struct
24+
{
25+
private readonly Nullable<T> _numValue;
26+
private readonly string _stringValue;
27+
28+
public StringOrNumValue(T value)
29+
{
30+
_numValue = value;
31+
_stringValue = null;
32+
}
33+
34+
public bool HasValue => HasNumValue || HasStringValue;
35+
36+
public bool HasNumValue => _numValue != null;
37+
38+
public bool HasStringValue => _stringValue != null;
39+
40+
public StringOrNumValue(string value)
41+
{
42+
_numValue = null;
43+
_stringValue = value;
44+
}
45+
46+
public StringOrNumValue(T numValue, string stringValue)
47+
{
48+
_numValue = numValue;
49+
_stringValue = stringValue;
50+
}
51+
52+
public T GetNumValue() => _numValue ?? default(T);
53+
54+
public string GetStringValue() => _stringValue;
55+
56+
public (string, T) GetValue()
57+
{
58+
return (_stringValue, _numValue ?? default(T));
59+
}
60+
61+
public override string ToString()
62+
{
63+
if (HasNumValue) return _numValue.ToString();
64+
return _stringValue;
65+
}
66+
67+
public bool Equals(StringOrNumValue<T> other)
68+
{
69+
return _numValue.Equals(other._numValue) && _stringValue == other._stringValue;
70+
}
71+
72+
public override bool Equals(object obj)
73+
{
74+
return obj is StringOrNumValue<T> other && Equals(other);
75+
}
76+
77+
public override int GetHashCode()
78+
{
79+
unchecked
80+
{
81+
var hashCode = _numValue.GetHashCode();
82+
if(_stringValue != null)
83+
hashCode = (hashCode * 397) ^ _stringValue.GetHashCode();
84+
return hashCode;
85+
}
86+
}
87+
88+
public static implicit operator StringOrNumValue<T>(string value) => new StringOrNumValue<T>(value);
89+
public static implicit operator StringOrNumValue<T>(T value) => new StringOrNumValue<T>(value);
90+
public static bool operator ==(StringOrNumValue<T> left, StringOrNumValue<T> right) => left.Equals(right);
91+
public static bool operator !=(StringOrNumValue<T> left, StringOrNumValue<T> right) => !left.Equals(right);
92+
}
93+
}

src/SkyApm.Abstractions/Config/InstrumentConfig.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ public class InstrumentConfig
2929
public string ApplicationCode { get; set; }
3030

3131
public string ServiceName { get; set; }
32-
32+
33+
public string ServiceInstanceName { get; set; }
34+
35+
3336
public string[] HeaderVersions { get; set; }
3437
}
3538

3639
public static class HeaderVersions
3740
{
38-
public static string SW3 { get; } = "sw3";
39-
40-
public static string SW6 { get; } = "sw6";
41+
public static string SW8 { get; } = "sw8";
4142
}
4243
}

src/SkyApm.Abstractions/Config/TransportConfig.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ public class TransportConfig
3333
/// </summary>
3434
public int BatchSize { get; set; } = 3000;
3535

36-
public string ProtocolVersion { get; set; } = ProtocolVersions.V6;
36+
public string ProtocolVersion { get; set; } = ProtocolVersions.V8;
3737
}
3838

3939
public static class ProtocolVersions
4040
{
41-
public static string V5 { get; } = "v5";
42-
43-
public static string V6 { get; } = "v6";
41+
public static string V8 { get; } = "v8";
4442
}
4543
}

src/SkyApm.Abstractions/IRuntimeEnvironment.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,8 @@ namespace SkyApm
2323
{
2424
public interface IRuntimeEnvironment
2525
{
26-
NullableValue ServiceId { get; }
27-
28-
NullableValue ServiceInstanceId { get; }
29-
3026
bool Initialized { get; }
3127

32-
Guid InstanceId { get; }
33-
3428
IEnvironmentProvider Environment { get; }
3529
}
3630
}

src/SkyApm.Abstractions/Tracing/ICarrier.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,22 @@ public interface ICarrier
2626

2727
bool? Sampled { get; }
2828

29-
UniqueId TraceId { get; }
29+
string TraceId { get; }
3030

31-
UniqueId ParentSegmentId { get; }
31+
string ParentSegmentId { get; }
3232

3333
int ParentSpanId { get; }
3434

35-
int ParentServiceInstanceId { get; }
36-
37-
int EntryServiceInstanceId { get; }
38-
35+
string ParentServiceId { get; }
36+
37+
string ParentServiceInstanceId { get; }
38+
39+
string EntryServiceInstanceId { get; }
40+
3941
StringOrIntValue NetworkAddress { get; }
40-
42+
4143
StringOrIntValue EntryEndpoint { get; }
42-
44+
4345
StringOrIntValue ParentEndpoint { get; }
4446
}
4547
}

src/SkyApm.Abstractions/Tracing/IUniqueIdGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ namespace SkyApm.Tracing
2020
{
2121
public interface IUniqueIdGenerator
2222
{
23-
UniqueId Generate();
23+
string Generate();
2424
}
2525
}

src/SkyApm.Abstractions/Tracing/IUniqueIdParser.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)