Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
dataplatform
atlas
Commits
9db4d261
Commit
9db4d261
authored
8 years ago
by
apoorvnaik
Committed by
Madhan Neethiraj
8 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1436: (Part 3) ignoreCache and query tuning for MetricsService
Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
ce20d6f5
master
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
69 deletions
+26
-69
MetricsService.java
...c/main/java/org/apache/atlas/services/MetricsService.java
+8
-17
MetricsServiceTest.java
...st/java/org/apache/atlas/services/MetricsServiceTest.java
+16
-50
AdminResource.java
...in/java/org/apache/atlas/web/resources/AdminResource.java
+2
-2
No files found.
repository/src/main/java/org/apache/atlas/services/MetricsService.java
View file @
9db4d261
...
...
@@ -87,8 +87,8 @@ public class MetricsService {
}
@SuppressWarnings
(
"unchecked"
)
public
AtlasMetrics
getMetrics
()
{
if
(!
isCacheValid
())
{
public
AtlasMetrics
getMetrics
(
boolean
ignoreCache
)
{
if
(
ignoreCache
||
!
isCacheValid
())
{
AtlasMetrics
metrics
=
new
AtlasMetrics
();
for
(
MetricQuery
metricQuery
:
MetricQuery
.
values
())
{
...
...
@@ -96,18 +96,7 @@ public class MetricsService {
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Executing query: {}"
,
metricQuery
);
}
if
(
metricQuery
==
MetricQuery
.
ENTITIES_PER_TYPE
)
{
Collection
<
String
>
entityDefNames
=
atlasTypeRegistry
.
getAllEntityDefNames
();
for
(
String
entityDefName
:
entityDefNames
)
{
String
formattedQuery
=
String
.
format
(
metricQuery
.
query
,
entityDefName
);
executeGremlinQuery
(
metrics
,
metricQuery
.
type
,
entityDefName
,
formattedQuery
);
}
}
else
{
executeGremlinQuery
(
metrics
,
metricQuery
.
type
,
metricQuery
.
name
,
metricQuery
.
query
);
}
}
catch
(
ScriptException
e
)
{
LOG
.
error
(
"Gremlin execution failed for metric {}"
,
metricQuery
,
e
);
}
...
...
@@ -130,8 +119,10 @@ public class MetricsService {
if
(
result
instanceof
Number
)
{
metrics
.
addData
(
type
,
name
,
((
Number
)
result
).
intValue
());
}
else
if
(
result
instanceof
List
)
{
for
(
Map
resultMap
:
(
List
<
Map
>)
result
)
{
metrics
.
addData
(
type
,
(
String
)
resultMap
.
get
(
"key"
),
((
Number
)
resultMap
.
get
(
"value"
)).
intValue
());
for
(
Map
<
String
,
Number
>
resultMap
:
(
List
<
Map
<
String
,
Number
>>)
result
)
{
for
(
Map
.
Entry
<
String
,
Number
>
entry
:
resultMap
.
entrySet
())
{
metrics
.
addData
(
type
,
entry
.
getKey
(),
entry
.
getValue
().
intValue
());
}
}
}
else
{
String
returnClassName
=
result
!=
null
?
result
.
getClass
().
getSimpleName
()
:
"null"
;
...
...
@@ -176,10 +167,10 @@ public class MetricsService {
TAGS_COUNT
(
GENERAL
,
METRIC_TAG_COUNT
,
"g.V().has('__type', 'typeSystem').filter({it.'__type.category'.name() == 'TRAIT'}).count()"
),
DELETED_ENTITY_COUNT
(
GENERAL
,
METRIC_ENTITY_DELETED
,
"g.V().has('__superTypeNames', T.in, ['Referenceable']).has('__status', 'DELETED').count()"
),
ENTITIES_PER_TYPE
(
ENTITY
,
METRIC_TYPE_ENTITIES
,
"g.V().has('__typeName', T.in,
['%s']).coun
t()"
),
ENTITIES_PER_TYPE
(
ENTITY
,
METRIC_TYPE_ENTITIES
,
"g.V().has('__typeName', T.in,
g.V().has('__type', 'typeSystem').filter({it.'__type.category'.name() != 'TRAIT'}).'__type.name'.toSet()).groupCount{it.'__typeName'}.cap.toLis
t()"
),
TAGGED_ENTITIES
(
ENTITY
,
METRIC_TAGGED_ENTITIES
,
"g.V().has('__superTypeNames', T.in, ['Referenceable']).has('__traitNames').count()"
),
TAGS_PER_ENTITY
(
TAG
,
METRIC_TAGS_PER_ENTITY
,
"g.V().has('__superTypeNames', T.in, ['Referenceable']).has('__traitNames').transform{[ key: it.'Referenceable.qualifiedName', value: it.'__traitNames'.size()]}.dedup()
.toList()"
),
ENTITIES_WITH_SPECIFIC_TAG
(
TAG
,
METRIC_TAGS_PER_ENTITY
,
"g.V().has('__typeName', T.in, g.V().has('__type', 'typeSystem').filter{it.'__type.category'.name() == 'TRAIT'}.'__type.name'.toSet()).groupCount{it.'__typeName'}.cap
.toList()"
),
;
private
final
String
type
;
...
...
This diff is collapsed.
Click to expand it.
repository/src/test/java/org/apache/atlas/services/MetricsServiceTest.java
View file @
9db4d261
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/
package
org
.
apache
.
atlas
.
services
;
import
org.apache.atlas.AtlasException
;
import
org.apache.atlas.model.metrics.AtlasMetrics
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
...
...
@@ -50,37 +32,20 @@ public class MetricsServiceTest {
private
Number
mockCount
=
10
;
@BeforeClass
public
void
init
()
throws
ScriptException
,
AtlasException
{
Map
<
String
,
Object
>
aMockMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
bMockMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
cMockMap
=
new
HashMap
<>();
aMockMap
.
put
(
"key"
,
"a"
);
aMockMap
.
put
(
"value"
,
1
);
bMockMap
.
put
(
"key"
,
"b"
);
bMockMap
.
put
(
"value"
,
2
);
cMockMap
.
put
(
"key"
,
"c"
);
cMockMap
.
put
(
"value"
,
3
);
mockMapList
.
add
(
aMockMap
);
mockMapList
.
add
(
bMockMap
);
mockMapList
.
add
(
cMockMap
);
public
void
init
()
throws
ScriptException
{
Map
<
String
,
Object
>
mockMap
=
new
HashMap
<>();
mockMap
.
put
(
"a"
,
1
);
mockMap
.
put
(
"b"
,
2
);
mockMap
.
put
(
"c"
,
3
);
mockMapList
.
add
(
mockMap
);
when
(
mockConfig
.
getInt
(
anyString
(),
anyInt
())).
thenReturn
(
5
);
when
(
mockConfig
.
getString
(
anyString
(),
anyString
()))
// we have seven count queries so stubbing 7 counts
.
thenReturn
(
"dummyTestQuery.count()"
)
.
thenReturn
(
"dummyTestQuery.count()"
)
.
thenReturn
(
"dummyTestQuery.count()"
)
.
thenReturn
(
"dummyTestQuery.count()"
)
.
thenReturn
(
"dummyTestQuery.count()"
)
.
thenReturn
(
"dummyTestQuery.count()"
)
.
thenReturn
(
"dummyTestQuery.count()"
)
// The last query is a map
.
thenReturn
(
"dummyTestQuery"
);
assertEquals
(
mockConfig
.
getInt
(
"test"
,
1
),
5
);
when
(
mockConfig
.
getString
(
anyString
(),
anyString
()))
.
thenReturn
(
"count()"
,
"count()"
,
"count()"
,
"count()"
,
"count()"
,
"toList()"
,
"count()"
,
"toList()"
);
when
(
mockTypeRegistry
.
getAllEntityDefNames
()).
thenReturn
(
Arrays
.
asList
(
"a"
,
"b"
,
"c"
));
setupMockGraph
();
metricsService
=
new
MetricsService
(
mockConfig
,
mockGraph
,
mockTypeRegistry
);
}
...
...
@@ -101,19 +66,19 @@ public class MetricsServiceTest {
@Test
public
void
testGetMetrics
()
throws
InterruptedException
,
ScriptException
{
assertNotNull
(
metricsService
);
AtlasMetrics
metrics
=
metricsService
.
getMetrics
();
AtlasMetrics
metrics
=
metricsService
.
getMetrics
(
false
);
assertNotNull
(
metrics
);
Number
aCount
=
metrics
.
getMetric
(
"entity"
,
"a"
);
assertNotNull
(
aCount
);
assertEquals
(
aCount
,
1
0
);
assertEquals
(
aCount
,
1
);
Number
bCount
=
metrics
.
getMetric
(
"entity"
,
"b"
);
assertNotNull
(
bCount
);
assertEquals
(
bCount
,
10
);
assertEquals
(
bCount
,
2
);
Number
cCount
=
metrics
.
getMetric
(
"entity"
,
"c"
);
assertNotNull
(
cCount
);
assertEquals
(
cCount
,
10
);
assertEquals
(
cCount
,
3
);
Number
aTags
=
metrics
.
getMetric
(
"tag"
,
"a"
);
assertNotNull
(
aTags
);
...
...
@@ -130,12 +95,12 @@ public class MetricsServiceTest {
verify
(
mockGraph
,
atLeastOnce
()).
executeGremlinScript
(
anyString
(),
anyBoolean
());
// Subsequent call within the cache timeout window
metricsService
.
getMetrics
();
metricsService
.
getMetrics
(
false
);
verifyZeroInteractions
(
mockGraph
);
// Now test the cache refresh
Thread
.
sleep
(
6000
);
metricsService
.
getMetrics
();
metricsService
.
getMetrics
(
true
);
verify
(
mockGraph
,
atLeastOnce
()).
executeGremlinScript
(
anyString
(),
anyBoolean
());
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
View file @
9db4d261
...
...
@@ -254,12 +254,12 @@ public class AdminResource {
@GET
@Path
(
"metrics"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasMetrics
getMetrics
()
{
public
AtlasMetrics
getMetrics
(
@QueryParam
(
"ignoreCache"
)
boolean
ignoreCache
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AdminResource.getMetrics()"
);
}
AtlasMetrics
metrics
=
metricsService
.
getMetrics
();
AtlasMetrics
metrics
=
metricsService
.
getMetrics
(
ignoreCache
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AdminResource.getMetrics()"
);
...
...
This diff is collapsed.
Click to expand it.
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