Skip to content

Commit d17fcd5

Browse files
Fix counter at the top of Summary tab (#193)
1 parent 55db773 commit d17fcd5

File tree

6 files changed

+39
-17
lines changed

6 files changed

+39
-17
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/ui/service/SummaryViewService.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import org.digma.intellij.plugin.common.DumbAwareNotifier
99
import org.digma.intellij.plugin.log.Log
1010
import org.digma.intellij.plugin.model.Models
1111
import org.digma.intellij.plugin.model.rest.insights.GlobalInsight
12+
import org.digma.intellij.plugin.model.rest.insights.SpanDurationChangeInsight
13+
import org.digma.intellij.plugin.model.rest.insights.TopErrorFlowsInsight
1214
import org.digma.intellij.plugin.model.rest.usage.UsageStatusResult
1315
import org.digma.intellij.plugin.summary.SummariesProvider
1416
import org.digma.intellij.plugin.ui.model.PanelModel
@@ -78,7 +80,7 @@ class SummaryViewService(project: Project) : AbstractViewService(project) {
7880
val environmentStatuses = summariesProvider.environmentStatuses
7981
model.insights = insights
8082
model.usageStatusResult = UsageStatusResult(emptyList(), environmentStatuses)
81-
model.count = insights.size
83+
model.count = countElementsOnSummaryTab(insights)
8284
updateUi()
8385
}
8486

@@ -112,6 +114,26 @@ class SummaryViewService(project: Project) : AbstractViewService(project) {
112114
override fun getUsageStatus(): UsageStatusResult = usageStatusResult
113115
}
114116

115-
117+
private fun countElementsOnSummaryTab(insights: List<ListViewItem<*>>): Int {
118+
var counter = 0
119+
for (insight in insights) {
120+
when (val model = insight.modelObject) {
121+
is TopErrorFlowsInsight -> {
122+
for (error in model.errors) {
123+
counter ++
124+
}
125+
}
126+
is SpanDurationChangeInsight -> {
127+
for (change in model.spanDurationChanges) {
128+
val changedPercentiles = change.percentiles.filter { needToShowDurationChange(it) }
129+
if (changedPercentiles.isNotEmpty()) {
130+
counter ++
131+
}
132+
}
133+
}
134+
}
135+
}
136+
return counter
137+
}
116138
}
117139

ide-common/src/main/kotlin/org/digma/intellij/plugin/ui/service/ToolWindowTabsHelper.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package org.digma.intellij.plugin.ui.service
33
import com.intellij.openapi.project.Project
44
import com.intellij.openapi.wm.ToolWindow
55
import com.intellij.ui.content.Content
6+
import org.digma.intellij.plugin.model.rest.insights.SpanDurationsPercentile
7+
import kotlin.math.abs
68

79
class ToolWindowTabsHelper(val project: Project) {
810

@@ -62,5 +64,14 @@ class ToolWindowTabsHelper(val project: Project) {
6264
toolWindow.contentManager.setSelectedContent(insightsContent)
6365
}
6466

67+
}
6568

69+
fun needToShowDurationChange(percentile: SpanDurationsPercentile): Boolean {
70+
val tolerationConstant: Long = 10000
71+
72+
if (percentile.previousDuration != null && percentile.changeTime != null) {
73+
val rawDiff: Long = abs(percentile.currentDuration.raw - percentile.previousDuration!!.raw)
74+
return ((rawDiff.toFloat() / percentile.previousDuration!!.raw) > 0.1) && (rawDiff > tolerationConstant)
75+
}
76+
return false
6677
}

src/main/kotlin/org/digma/intellij/plugin/ui/list/PanelList.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ abstract class PanelList(val project: Project, private var model: PanelListModel
9797
if (model.size <= 0)
9898
return
9999

100-
for (i in 0 until model.getSize()) run {
100+
for (i in 0 until model.size) run {
101101
cellRenderer.apply {
102102
val newComp: JPanel = getListCellRendererComponent(project, this@PanelList,
103103
model.getElementAt(i), i, this@PanelList.hasFocus(), panelsLayoutHelper)

src/main/kotlin/org/digma/intellij/plugin/ui/list/insights/SpanPanels.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import org.digma.intellij.plugin.ui.common.spanGrayed
1717
import org.digma.intellij.plugin.ui.list.ListItemActionButton
1818
import org.digma.intellij.plugin.ui.list.PanelsLayoutHelper
1919
import org.digma.intellij.plugin.ui.model.TraceSample
20+
import org.digma.intellij.plugin.ui.service.needToShowDurationChange
2021
import org.ocpsoft.prettytime.PrettyTime
2122
import org.threeten.extra.AmountFormats
2223
import java.awt.BorderLayout
@@ -103,17 +104,6 @@ fun percentileRowPanel(percentile: SpanDurationsPercentile, panelsLayoutHelper:
103104
return durationsPanel
104105
}
105106

106-
fun needToShowDurationChange(percentile: SpanDurationsPercentile): Boolean {
107-
val tolerationConstant: Long = 10000
108-
109-
if (percentile.previousDuration != null && percentile.changeTime != null) {
110-
val rawDiff: Long = abs(percentile.currentDuration.raw - percentile.previousDuration!!.raw)
111-
return ((rawDiff.toFloat() / percentile.previousDuration!!.raw) > 0.1) && (rawDiff > tolerationConstant)
112-
}
113-
114-
return false
115-
}
116-
117107
// if cannot create the button then would return null
118108
fun buildButtonToJaeger(
119109
project: Project, linkCaption: String, spanName: String, traceSamples: List<TraceSample>

src/main/kotlin/org/digma/intellij/plugin/ui/list/summaries/SummaryPanelList.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import org.digma.intellij.plugin.model.rest.insights.SpanDurationChangeInsight
88
import org.digma.intellij.plugin.model.rest.insights.TopErrorFlowsInsight
99
import org.digma.intellij.plugin.ui.list.AbstractPanelListModel
1010
import org.digma.intellij.plugin.ui.list.PanelList
11-
import org.digma.intellij.plugin.ui.list.insights.needToShowDurationChange
1211
import org.digma.intellij.plugin.ui.model.listview.ListViewItem
12+
import org.digma.intellij.plugin.ui.service.needToShowDurationChange
1313
import java.util.Collections
1414

1515
class SummaryPanelList(project: Project, listViewItems: List<ListViewItem<*>>) : PanelList(project, Model(listViewItems)) {

src/main/kotlin/org/digma/intellij/plugin/ui/list/summaries/SummaryPanelListCellRenderer.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ private fun buildError(model: TopErrorFlowsInsight.Error, project: Project): JPa
8787
}
8888

8989
private fun getCharacteristic(model: TopErrorFlowsInsight.Error): JPanel {
90-
val maxScore = model.scoreMovingAvg.coerceAtLeast(model.scoreRecency).coerceAtLeast(model.scoreTrendSlope)
91-
val text = when (maxScore) {
90+
val text = when (model.scoreMovingAvg.coerceAtLeast(model.scoreRecency).coerceAtLeast(model.scoreTrendSlope)) {
9291
model.scoreRecency -> "Recent"
9392
model.scoreMovingAvg -> "Frequent"
9493
model.scoreTrendSlope -> "Escalating"

0 commit comments

Comments
 (0)