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
5af0ec2d
Commit
5af0ec2d
authored
Apr 10, 2018
by
Liuhaoyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Init ServiceManager
parent
54b7c0b9
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
290 additions
and
24 deletions
+290
-24
IBootService.cs
src/SkyWalking.Abstractions/Boot/IBootService.cs
+3
-5
ServiceManager.cs
src/SkyWalking.Core/Boot/ServiceManager.cs
+80
-0
ContextManager.cs
src/SkyWalking.Core/Context/ContextManager.cs
+117
-0
IgnoredTracerContext.cs
src/SkyWalking.Core/Context/IgnoredTracerContext.cs
+75
-0
TracingContext.cs
src/SkyWalking.Core/Context/TracingContext.cs
+2
-5
DictionaryManager.cs
src/SkyWalking.Core/Dictionary/DictionaryManager.cs
+1
-1
Found.cs
src/SkyWalking.Core/Dictionary/Found.cs
+1
-1
NetworkAddressDictionary.cs
src/SkyWalking.Core/Dictionary/NetworkAddressDictionary.cs
+1
-1
NotFound.cs
src/SkyWalking.Core/Dictionary/NotFound.cs
+1
-1
OperationNameDictionary.cs
src/SkyWalking.Core/Dictionary/OperationNameDictionary.cs
+1
-1
SamplingService.cs
src/SkyWalking.Core/Sampling/SamplingService.cs
+8
-9
No files found.
src/SkyWalking.Abstractions/Boot/IBootService.cs
View file @
5af0ec2d
...
...
@@ -16,14 +16,12 @@
*
*/
using
System
.Threading.Tasks
;
using
System
;
namespace
SkyWalking.Boot
{
public
interface
IBootService
public
interface
IBootService
:
IDisposable
{
Task
Executing
();
Task
Executed
();
void
Init
();
}
}
\ No newline at end of file
src/SkyWalking.Core/Boot/ServiceManager.cs
0 → 100644
View file @
5af0ec2d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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
System.Linq
;
using
System.Runtime.CompilerServices
;
namespace
SkyWalking.Boot
{
public
class
ServiceManager
:
IDisposable
{
private
static
readonly
ServiceManager
_instance
=
new
ServiceManager
();
public
static
ServiceManager
Instance
=>
_instance
;
private
readonly
Dictionary
<
Type
,
object
>
_services
=
new
Dictionary
<
Type
,
object
>();
private
ServiceManager
()
{
}
private
Type
[]
FindServiceTypes
()
{
return
typeof
(
ServiceManager
).
Assembly
.
GetTypes
().
Where
(
x
=>
typeof
(
IBootService
).
IsAssignableFrom
(
x
))
.
ToArray
();
}
public
object
GetService
(
Type
serviceType
)
{
_services
.
TryGetValue
(
serviceType
,
out
var
instance
);
return
instance
;
}
public
T
GetService
<
T
>()
{
return
(
T
)
GetService
(
typeof
(
T
));
}
[
MethodImpl
(
MethodImplOptions
.
Synchronized
)]
public
void
Init
()
{
var
types
=
FindServiceTypes
();
foreach
(
var
type
in
types
)
{
if
(
Activator
.
CreateInstance
(
type
)
is
IBootService
service
)
{
service
.
Init
();
_services
.
Add
(
type
,
service
);
}
}
}
[
MethodImpl
(
MethodImplOptions
.
Synchronized
)]
public
void
Dispose
()
{
foreach
(
var
item
in
_services
.
Values
)
{
var
service
=
item
as
IBootService
;
service
?.
Dispose
();
}
}
}
}
\ No newline at end of file
src/SkyWalking.Core/Context/ContextManager.cs
0 → 100644
View file @
5af0ec2d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.Threading
;
using
SkyWalking.Boot
;
using
SkyWalking.Config
;
using
SkyWalking.Context.Trace
;
using
SkyWalking.Dictionarys
;
using
SkyWalking.Sampling
;
namespace
SkyWalking.Context
{
/// <summary>
/// Context manager controls the whole context of tracing. Since .NET server application runs as same as Java,
/// We also provide the CONTEXT propagation based on ThreadLocal mechanism.
/// Meaning, each segment also related to singe thread.
/// </summary>
public
class
ContextManager
:
ITracingContextListener
,
IBootService
{
private
static
readonly
ThreadLocal
<
ITracerContext
>
_context
=
new
ThreadLocal
<
ITracerContext
>();
private
static
ITracerContext
GetOrCreateContext
(
String
operationName
,
bool
forceSampling
)
{
if
(!
_context
.
IsValueCreated
)
{
if
(
string
.
IsNullOrEmpty
(
operationName
))
{
// logger.debug("No operation name, ignore this trace.");
_context
.
Value
=
new
IgnoredTracerContext
();
}
else
{
if
(!
DictionaryUtil
.
IsNull
(
RemoteDownstreamConfig
.
Agent
.
ApplicationId
)
&&
DictionaryUtil
.
IsNull
(
RemoteDownstreamConfig
.
Agent
.
ApplicationInstanceId
))
{
var
suffixIdx
=
operationName
.
LastIndexOf
(
'.'
);
if
(
suffixIdx
>
-
1
&&
AgentConfig
.
IgnoreSuffix
.
Contains
(
operationName
.
Substring
(
suffixIdx
)))
{
_context
.
Value
=
new
IgnoredTracerContext
();
}
else
{
var
sampler
=
ServiceManager
.
Instance
.
GetService
<
SamplingService
>();
if
(
forceSampling
||
sampler
.
TrySampling
())
{
_context
.
Value
=
new
TracingContext
();
}
else
{
_context
.
Value
=
new
IgnoredTracerContext
();
}
}
}
else
{
_context
.
Value
=
new
IgnoredTracerContext
();
}
}
}
return
_context
.
Value
;
}
private
static
ITracerContext
Context
=>
_context
.
Value
;
public
static
string
GlobalTraceId
{
get
{
if
(
_context
.
IsValueCreated
)
{
return
_context
.
Value
.
GetReadableGlobalTraceId
();
}
return
"N/A"
;
}
}
public
static
IContextSnapshot
Capture
=>
_context
.
Value
?.
Capture
;
public
static
ISpan
CreateEntrySpan
(
string
operationName
,
IContextCarrier
carrier
)
{
//todo samplingService
return
null
;
}
public
void
AfterFinished
(
ITraceSegment
traceSegment
)
{
}
public
void
Dispose
()
{
}
public
void
Init
()
{
throw
new
NotImplementedException
();
}
}
}
src/SkyWalking.
Abstractions/Context/ContextManager
.cs
→
src/SkyWalking.
Core/Context/IgnoredTracerContext
.cs
View file @
5af0ec2d
...
...
@@ -16,36 +16,60 @@
*
*/
using
System
;
using
S
ystem.Threading
;
using
S
kyWalking.Context.Trace
;
namespace
SkyWalking.Context
{
/// <summary>
/// Context manager controls the whole context of tracing. Since .NET server application runs as same as Java,
/// We also provide the CONTEXT propagation based on ThreadLocal mechanism.
/// Meaning, each segment also related to singe thread.
/// </summary>
public
static
class
ContextManager
public
class
IgnoredTracerContext
:
ITracerContext
{
private
static
readonly
NoopSpan
noopSpan
=
new
NoopSpan
();
private
int
_stackDepth
;
public
void
Inject
(
IContextCarrier
carrier
)
{
}
public
void
Extract
(
IContextCarrier
carrier
)
{
}
public
IContextSnapshot
Capture
{
get
;
}
public
ISpan
ActiveSpan
{
get
;
}
public
void
Continued
(
IContextSnapshot
snapshot
)
{
private
static
readonly
ThreadLocal
<
ITracerContext
>
CONTEXT
=
new
ThreadLocal
<
ITracerContext
>();
}
p
rivate
static
ITracerContext
GetOrCreate
(
String
operationName
,
bool
forceSampling
)
p
ublic
string
GetReadableGlobalTraceId
(
)
{
if
(!
CONTEXT
.
IsValueCreated
)
return
string
.
Empty
;
}
public
ISpan
CreateEntrySpan
(
string
operationName
)
{
return
null
;
_stackDepth
++;
return
noopSpan
;
}
else
public
ISpan
CreateLocalSpan
(
string
operationName
)
{
return
null
;
_stackDepth
++;
return
noopSpan
;
}
public
ISpan
CreateExitSpan
(
string
operationName
,
string
remotePeer
)
{
_stackDepth
++;
return
noopSpan
;
}
public
static
IContextSnapshot
Capture
(
)
public
void
StopSpan
(
ISpan
span
)
{
return
null
;
_stackDepth
--
;
}
}
}
\ No newline at end of file
src/SkyWalking.Core/Context/TracingContext.cs
View file @
5af0ec2d
...
...
@@ -17,13 +17,10 @@
*/
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq.Expressions
;
using
System.Runtime.InteropServices
;
using
SkyWalking.Boot
;
using
SkyWalking.Context.Trace
;
using
SkyWalking.Dictionary
;
using
SkyWalking.Dictionarys
;
using
SkyWalking.Sampling
;
using
SkyWalking.Utils
;
...
...
@@ -40,7 +37,7 @@ namespace SkyWalking.Context
public
TracingContext
()
{
_sampler
=
new
SamplingService
();
_sampler
=
ServiceManager
.
Instance
.
GetService
<
SamplingService
>
();
_segment
=
new
TraceSegment
();
_activeSpanStacks
=
new
Stack
<
ISpan
>();
}
...
...
src/SkyWalking.Core/Dictionary/DictionaryManager.cs
View file @
5af0ec2d
...
...
@@ -16,7 +16,7 @@
*
*/
namespace
SkyWalking.Dictionary
namespace
SkyWalking.Dictionary
s
{
public
class
DictionaryManager
{
...
...
src/SkyWalking.Core/Dictionary/Found.cs
View file @
5af0ec2d
...
...
@@ -18,7 +18,7 @@
using
SkyWalking.Dictionarys
;
namespace
SkyWalking.Dictionary
namespace
SkyWalking.Dictionary
s
{
public
class
Found
:
PossibleFound
{
...
...
src/SkyWalking.Core/Dictionary/NetworkAddressDictionary.cs
View file @
5af0ec2d
...
...
@@ -21,7 +21,7 @@ using SkyWalking.Config;
using
SkyWalking.Dictionarys
;
using
SkyWalking.NetworkProtocol
;
namespace
SkyWalking.Dictionary
namespace
SkyWalking.Dictionary
s
{
public
class
NetworkAddressDictionary
{
...
...
src/SkyWalking.Core/Dictionary/NotFound.cs
View file @
5af0ec2d
...
...
@@ -18,7 +18,7 @@
using
SkyWalking.Dictionarys
;
namespace
SkyWalking.Dictionary
namespace
SkyWalking.Dictionary
s
{
public
class
NotFound
:
PossibleFound
{
...
...
src/SkyWalking.Core/Dictionary/OperationNameDictionary.cs
View file @
5af0ec2d
...
...
@@ -25,7 +25,7 @@ using SkyWalking.Config;
using
SkyWalking.Dictionarys
;
using
SkyWalking.NetworkProtocol
;
namespace
SkyWalking.Dictionary
namespace
SkyWalking.Dictionary
s
{
public
class
OperationNameDictionary
{
...
...
src/SkyWalking.Core/Sampling/SamplingService.cs
View file @
5af0ec2d
...
...
@@ -16,29 +16,28 @@
*
*/
using
System.Threading.Tasks
;
namespace
SkyWalking.Sampling
{
public
class
SamplingService
:
ISampler
{
public
Task
Executing
()
public
bool
TrySampling
()
{
return
Task
.
CompletedTask
;
return
true
;
}
public
Task
Execut
ed
()
public
void
ForceSampl
ed
()
{
return
Task
.
CompletedTask
;
}
public
bool
TrySampling
()
public
void
Dispose
()
{
return
true
;
throw
new
System
.
NotImplementedException
()
;
}
public
void
ForceSampled
()
public
void
Init
()
{
throw
new
System
.
NotImplementedException
();
}
}
}
\ 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