Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
d5e6053f
Unverified
Commit
d5e6053f
authored
Feb 17, 2019
by
Lemon
Committed by
GitHub
Feb 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `IAdditionalConfigurationSource` to load the agent-config from the config center. (#151)
parent
6793d430
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
140 additions
and
32 deletions
+140
-32
ServiceCollectionExtensions.cs
...pm.Agent.AspNet/Extensions/ServiceCollectionExtensions.cs
+5
-4
ServiceCollectionExtensions.cs
...gent.AspNetCore/Extensions/ServiceCollectionExtensions.cs
+1
-0
ConfigAccessor.cs
src/SkyApm.Utilities.Configuration/ConfigAccessor.cs
+5
-28
ConfigurationFactory.cs
src/SkyApm.Utilities.Configuration/ConfigurationFactory.cs
+75
-0
IAdditionalConfigurationSource.cs
...Utilities.Configuration/IAdditionalConfigurationSource.cs
+27
-0
IConfigurationFactory.cs
src/SkyApm.Utilities.Configuration/IConfigurationFactory.cs
+27
-0
No files found.
src/SkyApm.Agent.AspNet/Extensions/ServiceCollectionExtensions.cs
View file @
d5e6053f
...
...
@@ -47,7 +47,8 @@ namespace SkyApm.Agent.AspNet.Extensions
services
.
AddSingleton
<
IConfigAccessor
,
ConfigAccessor
>();
services
.
AddSingleton
<
IEnvironmentProvider
,
HostingEnvironmentProvider
>();
services
.
AddSingleton
<
InstrumentRequestCallback
>();
services
.
AddSingleton
<
IConfigurationFactory
,
ConfigurationFactory
>();
services
.
AddSingleton
<
ITracingContext
,
Tracing
.
TracingContext
>();
services
.
AddSingleton
<
ICarrierPropagator
,
CarrierPropagator
>();
services
.
AddSingleton
<
ICarrierFormatter
,
Sw3CarrierFormatter
>();
...
...
@@ -61,19 +62,19 @@ namespace SkyApm.Agent.AspNet.Extensions
services
.
AddSingleton
<
IUniqueIdParser
,
UniqueIdParser
>();
services
.
AddSingleton
<
ISegmentContextMapper
,
SegmentContextMapper
>();
services
.
AddSingleton
<
IBase64Formatter
,
Base64Formatter
>();
services
.
AddSingleton
<
SimpleCountSamplingInterceptor
>();
services
.
AddSingleton
<
ISamplingInterceptor
>(
p
=>
p
.
GetService
<
SimpleCountSamplingInterceptor
>());
services
.
AddSingleton
<
IExecutionService
>(
p
=>
p
.
GetService
<
SimpleCountSamplingInterceptor
>());
services
.
AddSingleton
<
ISamplingInterceptor
,
RandomSamplingInterceptor
>();
services
.
AddSingleton
<
ISkyApmClientV5
,
SkyApmClientV5
>();
services
.
AddSingleton
<
ISegmentReporter
,
SegmentReporter
>();
services
.
AddSingleton
<
ConnectionManager
>();
services
.
AddSingleton
<
IPingCaller
,
PingCaller
>();
services
.
AddSingleton
<
IServiceRegister
,
ServiceRegister
>();
services
.
AddSingleton
<
IExecutionService
,
ConnectService
>();
services
.
AddSingleton
<
ILoggerFactory
,
DefaultLoggerFactory
>();
return
services
;
}
...
...
src/SkyApm.Agent.AspNetCore/Extensions/ServiceCollectionExtensions.cs
View file @
d5e6053f
...
...
@@ -57,6 +57,7 @@ namespace SkyApm.Agent.AspNetCore
services
.
AddSingleton
<
IRuntimeEnvironment
>(
RuntimeEnvironment
.
Instance
);
services
.
AddSingleton
<
TracingDiagnosticProcessorObserver
>();
services
.
AddSingleton
<
IConfigAccessor
,
ConfigAccessor
>();
services
.
AddSingleton
<
IConfigurationFactory
,
ConfigurationFactory
>();
services
.
AddSingleton
<
IHostedService
,
InstrumentationHostedService
>();
services
.
AddSingleton
<
IEnvironmentProvider
,
HostingEnvironmentProvider
>();
services
.
AddTracing
().
AddSampling
().
AddGrpcTransport
().
AddLogging
();
...
...
src/SkyApm.Utilities.Configuration/ConfigAccessor.cs
View file @
d5e6053f
...
...
@@ -22,40 +22,15 @@ using System.Reflection;
using
Microsoft.Extensions.Configuration
;
using
SkyApm.Config
;
// ReSharper disable StringLiteralTypo
namespace
SkyApm.Utilities.Configuration
{
public
class
ConfigAccessor
:
IConfigAccessor
{
private
const
string
CONFIG_FILE_PATH_COMPATIBLE
=
"SKYWALKING__CONFIG__PATH"
;
private
const
string
CONFIG_FILE_PATH
=
"SKYAPM__CONFIG__PATH"
;
private
readonly
IConfiguration
_configuration
;
public
ConfigAccessor
(
I
EnvironmentProvider
environmentProvider
)
public
ConfigAccessor
(
I
ConfigurationFactory
factory
)
{
var
builder
=
new
ConfigurationBuilder
();
builder
.
AddSkyWalkingDefaultConfig
();
builder
.
AddJsonFile
(
"appsettings.json"
,
true
).
AddJsonFile
(
$"appsettings.
{
environmentProvider
.
EnvironmentName
}
.json"
,
true
);
builder
.
AddJsonFile
(
"skywalking.json"
,
true
).
AddJsonFile
(
$"skywalking.
{
environmentProvider
.
EnvironmentName
}
.json"
,
true
);
builder
.
AddJsonFile
(
"skyapm.json"
,
true
).
AddJsonFile
(
$"skyapm.
{
environmentProvider
.
EnvironmentName
}
.json"
,
true
);
if
(!
string
.
IsNullOrEmpty
(
Environment
.
GetEnvironmentVariable
(
CONFIG_FILE_PATH_COMPATIBLE
)))
{
builder
.
AddJsonFile
(
Environment
.
GetEnvironmentVariable
(
CONFIG_FILE_PATH_COMPATIBLE
),
false
);
}
if
(!
string
.
IsNullOrEmpty
(
Environment
.
GetEnvironmentVariable
(
CONFIG_FILE_PATH
)))
{
builder
.
AddJsonFile
(
Environment
.
GetEnvironmentVariable
(
CONFIG_FILE_PATH
),
false
);
}
builder
.
AddEnvironmentVariables
();
_configuration
=
builder
.
Build
();
_configuration
=
factory
.
Create
();
}
public
T
Get
<
T
>()
where
T
:
class
,
new
()
...
...
@@ -72,7 +47,9 @@ namespace SkyApm.Utilities.Configuration
return
_configuration
.
GetSection
(
config
.
GetSections
()).
GetValue
<
T
>(
key
);
}
//hign performance
/// <summary>
/// high performance
/// </summary>
private
static
class
New
<
T
>
where
T
:
new
()
{
public
static
readonly
Func
<
T
>
Instance
=
Expression
.
Lambda
<
Func
<
T
>>
...
...
src/SkyApm.Utilities.Configuration/ConfigurationFactory.cs
0 → 100644
View file @
d5e6053f
/*
* Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using
System
;
using
System.Collections.Generic
;
using
Microsoft.Extensions.Configuration
;
// ReSharper disable StringLiteralTypo
namespace
SkyApm.Utilities.Configuration
{
public
class
ConfigurationFactory
:
IConfigurationFactory
{
private
const
string
CONFIG_FILE_PATH_COMPATIBLE
=
"SKYWALKING__CONFIG__PATH"
;
private
const
string
CONFIG_FILE_PATH
=
"SKYAPM__CONFIG__PATH"
;
private
readonly
IEnvironmentProvider
_environmentProvider
;
private
readonly
IEnumerable
<
IAdditionalConfigurationSource
>
_additionalConfigurations
;
public
ConfigurationFactory
(
IEnvironmentProvider
environmentProvider
,
IEnumerable
<
IAdditionalConfigurationSource
>
additionalConfigurations
)
{
_environmentProvider
=
environmentProvider
;
_additionalConfigurations
=
additionalConfigurations
;
}
public
IConfiguration
Create
()
{
var
builder
=
new
ConfigurationBuilder
();
builder
.
AddSkyWalkingDefaultConfig
();
builder
.
AddJsonFile
(
"appsettings.json"
,
true
)
.
AddJsonFile
(
$"appsettings.
{
_environmentProvider
.
EnvironmentName
}
.json"
,
true
);
builder
.
AddJsonFile
(
"skywalking.json"
,
true
)
.
AddJsonFile
(
$"skywalking.
{
_environmentProvider
.
EnvironmentName
}
.json"
,
true
);
builder
.
AddJsonFile
(
"skyapm.json"
,
true
)
.
AddJsonFile
(
$"skyapm.
{
_environmentProvider
.
EnvironmentName
}
.json"
,
true
);
if
(!
string
.
IsNullOrEmpty
(
Environment
.
GetEnvironmentVariable
(
CONFIG_FILE_PATH_COMPATIBLE
)))
{
builder
.
AddJsonFile
(
Environment
.
GetEnvironmentVariable
(
CONFIG_FILE_PATH_COMPATIBLE
),
false
);
}
if
(!
string
.
IsNullOrEmpty
(
Environment
.
GetEnvironmentVariable
(
CONFIG_FILE_PATH
)))
{
builder
.
AddJsonFile
(
Environment
.
GetEnvironmentVariable
(
CONFIG_FILE_PATH
),
false
);
}
builder
.
AddEnvironmentVariables
();
foreach
(
var
additionalConfiguration
in
_additionalConfigurations
)
{
additionalConfiguration
.
Load
(
builder
);
}
return
builder
.
Build
();
}
}
}
\ No newline at end of file
src/SkyApm.Utilities.Configuration/IAdditionalConfigurationSource.cs
0 → 100644
View file @
d5e6053f
/*
* Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using
Microsoft.Extensions.Configuration
;
namespace
SkyApm.Utilities.Configuration
{
public
interface
IAdditionalConfigurationSource
{
void
Load
(
ConfigurationBuilder
builder
);
}
}
\ No newline at end of file
src/SkyApm.Utilities.Configuration/IConfigurationFactory.cs
0 → 100644
View file @
d5e6053f
/*
* Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using
Microsoft.Extensions.Configuration
;
namespace
SkyApm.Utilities.Configuration
{
public
interface
IConfigurationFactory
{
IConfiguration
Create
();
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment