Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
e1732296
Commit
e1732296
authored
6 years ago
by
Vitaliy.Bibaev
Browse files
Options
Download
Email Patches
Plain Diff
[stats-collector] Add daily limit for data reporting 15 mb
parent
b1baf37c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
plugins/stats-collector/src/com/intellij/stats/network/service/SimpleRequestService.kt
+3
-3
...om/intellij/stats/network/service/SimpleRequestService.kt
plugins/stats-collector/src/com/intellij/stats/sender/DailyLimitSendingWatcher.kt
+48
-0
...src/com/intellij/stats/sender/DailyLimitSendingWatcher.kt
plugins/stats-collector/src/com/intellij/stats/sender/PersistentSentDataInfo.kt
+19
-0
...r/src/com/intellij/stats/sender/PersistentSentDataInfo.kt
plugins/stats-collector/src/com/intellij/stats/sender/StatisticSenderImpl.kt
+11
-1
...ctor/src/com/intellij/stats/sender/StatisticSenderImpl.kt
plugins/stats-collector/test/sender/DailySendingLimitTest.kt
+36
-0
plugins/stats-collector/test/sender/DailySendingLimitTest.kt
with
117 additions
and
4 deletions
+117
-4
plugins/stats-collector/src/com/intellij/stats/network/service/SimpleRequestService.kt
+
3
-
3
View file @
e1732296
...
...
@@ -40,7 +40,7 @@ class SimpleRequestService: RequestService() {
it
.
setRequestProperty
(
HttpHeaders
.
CONTENT_ENCODING
,
"gzip"
)
}.
connect
{
request
->
request
.
write
(
zippedArray
)
return
@connect
request
.
connection
.
asResponseData
()
return
@connect
request
.
connection
.
asResponseData
(
zippedArray
.
size
)
}
}
catch
(
e
:
HttpRequests
.
HttpStatusException
)
{
...
...
@@ -71,9 +71,9 @@ class SimpleRequestService: RequestService() {
}
}
private
fun
URLConnection
.
asResponseData
():
ResponseData
?
{
private
fun
URLConnection
.
asResponseData
(
sentDataSize
:
Int
?
):
ResponseData
?
{
if
(
this
is
HttpURLConnection
)
{
return
ResponseData
(
this
.
responseCode
,
StringUtil
.
notNullize
(
this
.
responseMessage
,
""
))
return
ResponseData
(
this
.
responseCode
,
StringUtil
.
notNullize
(
this
.
responseMessage
,
""
)
,
sentDataSize
)
}
LOG
.
error
(
"Could not get code and message from http response"
)
...
...
This diff is collapsed.
Click to expand it.
plugins/stats-collector/src/com/intellij/stats/sender/DailyLimitSendingWatcher.kt
0 → 100644
+
48
-
0
View file @
e1732296
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
com.intellij.stats.sender
import
com.intellij.ide.util.PropertiesComponent
import
java.text.SimpleDateFormat
import
java.util.*
class
DailyLimitSendingWatcher
(
private
val
dailyLimit
:
Int
,
private
val
info
:
SentDataInfo
)
{
fun
isLimitReached
():
Boolean
=
info
.
sentToday
(
System
.
currentTimeMillis
())
>=
dailyLimit
fun
dataSent
(
size
:
Int
)
{
info
.
dataSent
(
System
.
currentTimeMillis
(),
size
)
}
abstract
class
SentDataInfo
{
companion
object
{
private
val
FORMAT
=
SimpleDateFormat
(
"yyyyMMdd"
)
}
fun
sentToday
(
timestamp
:
Long
):
Int
{
if
(!
isSameDay
(
timestamp
,
latestSendingTimestamp
))
{
return
0
}
return
sentCount
}
fun
dataSent
(
timestamp
:
Long
,
bytesCount
:
Int
)
{
sentCount
=
sentToday
(
timestamp
)
+
bytesCount
latestSendingTimestamp
=
timestamp
}
private
fun
isSameDay
(
ts1
:
Long
,
ts2
:
Long
):
Boolean
{
fun
Long
.
asString
():
String
=
FORMAT
.
format
(
Date
(
this
))
return
ts1
.
asString
()
==
ts2
.
asString
()
}
protected
abstract
var
sentCount
:
Int
protected
abstract
var
latestSendingTimestamp
:
Long
class
DumbInfo
:
SentDataInfo
()
{
override
var
sentCount
:
Int
=
0
override
var
latestSendingTimestamp
:
Long
=
0
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/stats-collector/src/com/intellij/stats/sender/PersistentSentDataInfo.kt
0 → 100644
+
19
-
0
View file @
e1732296
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
com.intellij.stats.sender
import
com.intellij.ide.util.PropertiesComponent
class
PersistentSentDataInfo
(
private
val
properties
:
PropertiesComponent
)
:
DailyLimitSendingWatcher
.
SentDataInfo
()
{
companion
object
{
private
const
val
SENT_DATA_SIZE_TODAY_PROPERTY
=
"stats.collector.today.sent.data.size"
private
const
val
DATA_SENT_TIMESTAMP_PROPERTY
=
"stats.collector.latest.sending.timestamp"
}
override
var
sentCount
:
Int
get
()
=
properties
.
getInt
(
SENT_DATA_SIZE_TODAY_PROPERTY
,
0
)
set
(
value
)
=
properties
.
setValue
(
SENT_DATA_SIZE_TODAY_PROPERTY
,
value
,
0
)
override
var
latestSendingTimestamp
:
Long
get
()
=
properties
.
getOrInitLong
(
DATA_SENT_TIMESTAMP_PROPERTY
,
0L
)
set
(
value
)
=
properties
.
setValue
(
DATA_SENT_TIMESTAMP_PROPERTY
,
value
.
toString
())
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/stats-collector/src/com/intellij/stats/sender/StatisticSenderImpl.kt
+
11
-
1
View file @
e1732296
...
...
@@ -16,6 +16,7 @@
package
com.intellij.stats.sender
import
com.intellij.ide.util.PropertiesComponent
import
com.intellij.stats.network.service.RequestService
import
com.intellij.stats.network.assertNotEDT
import
com.intellij.stats.storage.FilePathProvider
...
...
@@ -25,12 +26,18 @@ class StatisticSenderImpl(
private
val
requestService
:
RequestService
,
private
val
filePathProvider
:
FilePathProvider
):
StatisticSender
{
companion
object
{
const
val
DAILY_LIMIT
=
15
*
1024
*
1024
// 15 mb
}
private
val
limitWatcher
=
DailyLimitSendingWatcher
(
DAILY_LIMIT
,
PersistentSentDataInfo
(
PropertiesComponent
.
getInstance
()))
override
fun
sendStatsData
(
url
:
String
)
{
assertNotEDT
()
if
(
limitWatcher
.
isLimitReached
())
return
val
filesToSend
=
filePathProvider
.
getDataFiles
()
filesToSend
.
forEach
{
if
(
it
.
length
()
>
0
)
{
if
(
it
.
length
()
>
0
&&
!
limitWatcher
.
isLimitReached
()
)
{
val
isSentSuccessfully
=
sendContent
(
url
,
it
)
if
(
isSentSuccessfully
)
{
it
.
delete
()
...
...
@@ -45,6 +52,9 @@ class StatisticSenderImpl(
private
fun
sendContent
(
url
:
String
,
file
:
File
):
Boolean
{
val
data
=
requestService
.
postZipped
(
url
,
file
)
if
(
data
!=
null
&&
data
.
code
>=
200
&&
data
.
code
<
300
)
{
if
(
data
.
sentDataSize
!=
null
)
{
limitWatcher
.
dataSent
(
data
.
sentDataSize
)
}
return
true
}
return
false
...
...
This diff is collapsed.
Click to expand it.
plugins/stats-collector/test/sender/DailySendingLimitTest.kt
0 → 100644
+
36
-
0
View file @
e1732296
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
sender
import
com.intellij.stats.sender.DailyLimitSendingWatcher
import
com.intellij.testFramework.UsefulTestCase
import
junit.framework.TestCase
class
DailySendingLimitTest
:
UsefulTestCase
()
{
fun
testLimitInfo
()
{
val
info
=
DailyLimitSendingWatcher
.
SentDataInfo
.
DumbInfo
()
TestCase
.
assertEquals
(
0
,
info
.
sentToday
(
10
))
info
.
dataSent
(
10
,
100
)
TestCase
.
assertEquals
(
100
,
info
.
sentToday
(
10
))
info
.
dataSent
(
10
,
1
)
TestCase
.
assertEquals
(
101
,
info
.
sentToday
(
10
))
val
nextDay
:
Long
=
10
+
24
*
60
*
60
*
1000
TestCase
.
assertEquals
(
0
,
info
.
sentToday
(
nextDay
))
info
.
dataSent
(
nextDay
,
1
)
TestCase
.
assertEquals
(
1
,
info
.
sentToday
(
nextDay
))
}
fun
testSendingWatcher
()
{
val
watcher
=
DailyLimitSendingWatcher
(
2500
,
DailyLimitSendingWatcher
.
SentDataInfo
.
DumbInfo
())
TestCase
.
assertFalse
(
watcher
.
isLimitReached
())
watcher
.
dataSent
(
2300
)
TestCase
.
assertFalse
(
watcher
.
isLimitReached
())
watcher
.
dataSent
(
500
)
if
(!
watcher
.
isLimitReached
())
{
println
(
"is it really 12 o'clock?!"
)
watcher
.
dataSent
(
2300
)
watcher
.
dataSent
(
500
)
}
TestCase
.
assertTrue
(
watcher
.
isLimitReached
())
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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
Menu
Projects
Groups
Snippets
Help