Skip to content

Commit 12c8883

Browse files
authored
Merge pull request #105 from digma-ai/feature/endpoint_oftype_consumer
remove suffix '.local' from local hostname if exists.
2 parents dd993cf + ff97235 commit 12c8883

File tree

6 files changed

+72
-33
lines changed

6 files changed

+72
-33
lines changed

ide-common/src/main/java/org/digma/intellij/plugin/common/CommonUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.digma.intellij.plugin.common;
22

3+
import org.apache.commons.lang.StringUtils;
34
import org.ocpsoft.prettytime.PrettyTime;
45

56
import java.net.InetAddress;
@@ -19,6 +20,7 @@ public static String getLocalHostname() {
1920
} catch (UnknownHostException e) {
2021
hostname = hostnameByEnvVar();
2122
}
23+
hostname = StringUtils.removeEnd(hostname, ".local");
2224
return hostname;
2325
}
2426

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,64 @@
11
package org.digma.intellij.plugin.model.rest.insights
22

3+
import javax.swing.Icon
4+
5+
class GroupViewModel(val titleText: String, val labelText: String, val icon: Icon)
6+
7+
class RouteInfo(val shortName: String, val schema: String)
8+
39
class EndpointSchema {
410

511
companion object {
6-
const val HTTP_SCHEMA: String = "epHTTP:"
7-
const val RPC_SCHEMA: String = "epRPC:"
12+
const val HTTP_SCHEMA: String = "epHTTP"
13+
const val RPC_SCHEMA: String = "epRPC"
14+
const val CONSUMER_SCHEMA: String = "epConsumer"
15+
16+
@JvmStatic
17+
fun getRouteInfo(fullRouteName: String): RouteInfo {
18+
val schema = getSchema(fullRouteName);
19+
return RouteInfo(removeSchema(fullRouteName, schema), schema);
20+
}
821

9-
// strips the scheme and returns the rest of the of name
1022
@JvmStatic
11-
fun getShortRouteName(fullRouteName: String): String {
12-
if (fullRouteName.startsWith(HTTP_SCHEMA)) {
13-
return fullRouteName.replace(HTTP_SCHEMA, "");
23+
private fun isOfType(fullRouteName: String, schema: String): Boolean{
24+
return fullRouteName.startsWith("$schema:");
25+
}
26+
@JvmStatic
27+
private fun getSchema(fullRouteName: String): String{
28+
if (isOfType(fullRouteName, HTTP_SCHEMA)) {
29+
return HTTP_SCHEMA
1430
}
15-
if (fullRouteName.startsWith(RPC_SCHEMA)) {
16-
return fullRouteName.replace(RPC_SCHEMA, "");
31+
if (isOfType(fullRouteName, RPC_SCHEMA)) {
32+
return RPC_SCHEMA
1733
}
18-
// did not manage to find relevant Scheme, so returning value as is
19-
return fullRouteName;
34+
if (isOfType(fullRouteName, CONSUMER_SCHEMA)) {
35+
return CONSUMER_SCHEMA
36+
}
37+
return "";
38+
}
39+
40+
@JvmStatic
41+
private fun removeSchema(fullRouteName: String, schema: String): String{
42+
if(schema == ""){
43+
return fullRouteName;
44+
}
45+
return fullRouteName.replace("$schema:", "");
2046
}
2147

2248
@JvmStatic
2349
fun adjustHttpRouteIfNeeded(endpointInsight: EndpointInsight) {
2450
val origValue = endpointInsight.route
25-
if (origValue.startsWith(HTTP_SCHEMA)) {
51+
if (isOfType(origValue, HTTP_SCHEMA)) {
52+
return;
53+
}
54+
if (isOfType(origValue, RPC_SCHEMA)) {
2655
return;
2756
}
28-
if (origValue.startsWith(RPC_SCHEMA)) {
57+
if (isOfType(origValue, CONSUMER_SCHEMA)) {
2958
return;
3059
}
3160
// default behaviour, to be backward compatible, where did not have the scheme part of the route, so adding it as HTTP one
32-
endpointInsight.route = HTTP_SCHEMA + origValue;
61+
endpointInsight.route = HTTP_SCHEMA +":"+ origValue;
3362
}
3463
}
3564
}

model/src/test/kotlin/org/digma/intellij/plugin/model/rest/insights/EndpointSchemaTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
package org.digma.intellij.plugin.model.rest.insights
22

33
import org.digma.intellij.plugin.model.rest.insights.EndpointSchema.Companion.adjustHttpRouteIfNeeded
4-
import org.digma.intellij.plugin.model.rest.insights.EndpointSchema.Companion.getShortRouteName
4+
import org.digma.intellij.plugin.model.rest.insights.EndpointSchema.Companion.getRouteInfo
55
import kotlin.test.Test
66
import kotlin.test.assertEquals
77

88
internal class EndpointSchemaTest {
99

1010
@Test
1111
fun getShortRouteNameShouldWorkForHttpSchema() {
12-
assertEquals("get /hello", getShortRouteName("epHTTP:get /hello"))
12+
assertEquals("get /hello", getRouteInfo("epHTTP:get /hello").shortName)
1313
}
1414

1515
@Test
1616
fun getShortRouteNameShouldWorkForRpcSchema() {
17-
assertEquals("hello.world", getShortRouteName("epRPC:hello.world"))
17+
assertEquals("hello.world", getRouteInfo("epRPC:hello.world").shortName)
1818
}
1919

2020
@Test
2121
fun getShortRouteNameShouldWorkEvenWhenNonRecognizedSchema() {
22-
assertEquals("whats.up.dude", getShortRouteName("whats.up.dude"))
22+
assertEquals("whats.up.dude", getRouteInfo("whats.up.dude").shortName)
2323
}
2424

2525
@Test

src/main/kotlin/org/digma/intellij/plugin/ui/common/Laf.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ object Laf {
8282
@JvmStatic val FILE: Icon = SvgIcon.withColor("/icons/file.svg", Colors.DEFAULT_LABEL_FOREGROUND)
8383
@JvmStatic val TELESCOPE: Icon = SvgIcon.withColor("/icons/telescope.svg", Colors.DEFAULT_LABEL_FOREGROUND)
8484
@JvmStatic val INTERFACE: Icon = SvgIcon.withColor("/icons/interface.svg", Colors.DEFAULT_LABEL_FOREGROUND)
85+
@JvmStatic val MESSAGE: Icon = SvgIcon.withColor("/icons/message.svg", Colors.DEFAULT_LABEL_FOREGROUND)
8586
// Insight item icons
8687
@JvmStatic val QUESTION_MARK = AllIcons.General.QuestionDialog
8788
@JvmStatic val BOTTLENECK = loadAndScaleInsightIcon("/icons/bottleneck.png")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.digma.intellij.plugin.ui.model.insights.InsightGroupListViewItem
77
import org.digma.intellij.plugin.ui.model.insights.InsightGroupType
88
import org.digma.intellij.plugin.ui.model.listview.ListViewItem
99
import java.util.*
10+
import javax.swing.Icon
1011
import kotlin.collections.ArrayList
1112

1213
class InsightsList(project: Project, listViewItems: List<ListViewItem<*>>) :

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.intellij.openapi.project.Project
44
import com.intellij.ui.dsl.builder.RightGap
55
import com.intellij.ui.dsl.builder.panel
66
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
7-
import org.digma.intellij.plugin.model.rest.insights.EndpointSchema
87
import org.digma.intellij.plugin.model.rest.insights.ErrorInsight
98
import org.digma.intellij.plugin.model.rest.insights.HighUsageInsight
109
import org.digma.intellij.plugin.model.rest.insights.HotspotInsight
@@ -21,6 +20,10 @@ import org.digma.intellij.plugin.ui.common.asHtml
2120
import org.digma.intellij.plugin.ui.common.span
2221
import org.digma.intellij.plugin.ui.common.spanBold
2322
import org.digma.intellij.plugin.ui.common.spanGrayed
23+
import org.digma.intellij.plugin.model.rest.insights.*
24+
import org.digma.intellij.plugin.model.rest.insights.EndpointSchema.Companion.CONSUMER_SCHEMA
25+
import org.digma.intellij.plugin.model.rest.insights.EndpointSchema.Companion.HTTP_SCHEMA
26+
import org.digma.intellij.plugin.model.rest.insights.EndpointSchema.Companion.RPC_SCHEMA
2427
import org.digma.intellij.plugin.ui.list.AbstractPanelListCellRenderer
2528
import org.digma.intellij.plugin.ui.list.PanelsLayoutHelper
2629
import org.digma.intellij.plugin.ui.model.insights.InsightGroupType.HttpEndpoint
@@ -73,7 +76,7 @@ class InsightsListCellRenderer : AbstractPanelListCellRenderer() {
7376
private fun buildGroupTitle(value: InsightsList.GroupTitleModel): JPanel {
7477

7578
val panel = when (value.type) {
76-
HttpEndpoint -> httpEndpointGroupTitle(value)
79+
HttpEndpoint -> endpointGroupTitle(value)
7780
Span -> spanGroupTitle(value)
7881
else -> defaultInsightGroupTitle(value)
7982
}
@@ -92,9 +95,9 @@ class InsightsListCellRenderer : AbstractPanelListCellRenderer() {
9295
return groupTitlePanel("Span: ", value.groupId, Laf.Icons.Insight.TELESCOPE)
9396
}
9497

95-
private fun httpEndpointGroupTitle(value: InsightsList.GroupTitleModel): JPanel {
96-
val labelText = headerAsHtml(value)
97-
return groupTitlePanel("REST: ", labelText, Laf.Icons.Insight.INTERFACE)
98+
private fun endpointGroupTitle(value: InsightsList.GroupTitleModel): JPanel {
99+
val groupViewModel = createEndpointGroupViewModel(value.groupId);
100+
return groupTitlePanel(groupViewModel.titleText, groupViewModel.labelText,groupViewModel.icon)
98101
}
99102

100103

@@ -112,16 +115,19 @@ class InsightsListCellRenderer : AbstractPanelListCellRenderer() {
112115
}
113116
}
114117

115-
116-
117-
118-
119-
private fun headerAsHtml(value: InsightsList.GroupTitleModel): String {
120-
val shortRouteName = EndpointSchema.getShortRouteName(value.groupId)
121-
// groupId contains "[get|post] [uri]"
122-
val split = shortRouteName.split(' ')
123-
val httpMethod = split[0].uppercase()
124-
val httpRoute = split[1]
125-
return asHtml("${spanBold("HTTP")} ${span("$httpMethod $httpRoute")}")
118+
private fun createEndpointGroupViewModel(fullRouteName: String): GroupViewModel{
119+
val routeInfo = EndpointSchema.getRouteInfo(fullRouteName);
120+
val endpoint = routeInfo.shortName
121+
if(routeInfo.schema == HTTP_SCHEMA){
122+
val split =endpoint.split(' ')
123+
return GroupViewModel("REST: ", asHtml("${spanBold("HTTP")} ${span("${split[0].uppercase()} ${split[1]}")}"), Laf.Icons.Insight.INTERFACE)
124+
}
125+
if(routeInfo.schema == RPC_SCHEMA){
126+
return GroupViewModel("RPC: ", asHtml(span(endpoint)), Laf.Icons.Insight.INTERFACE)
127+
}
128+
if(routeInfo.schema == CONSUMER_SCHEMA){
129+
return GroupViewModel("CONSUMER: ", asHtml(span(endpoint)), Laf.Icons.Insight.MESSAGE)
130+
}
131+
return GroupViewModel("REST: ", asHtml(""), Laf.Icons.Insight.INTERFACE)
126132
}
127133
}

0 commit comments

Comments
 (0)