Skip to content

Commit 7d051e9

Browse files
committed
remove suffix '.local' from local hostname if exists.
support endpoint of type consumer
1 parent 3b0054c commit 7d051e9

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
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

model/src/main/kotlin/org/digma/intellij/plugin/model/rest/insights/EndpointSchema.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ class EndpointSchema {
55
companion object {
66
const val HTTP_SCHEMA: String = "epHTTP:"
77
const val RPC_SCHEMA: String = "epRPC:"
8+
const val CONSUMER_SCHEMA: String = "epConsumer:"
89

910
// strips the scheme and returns the rest of the of name
1011
@JvmStatic
11-
fun getShortRouteName(fullRouteName: String): String {
12+
fun getShortRouteName(fullRouteName: String): Pair<String, String> {
1213
if (fullRouteName.startsWith(HTTP_SCHEMA)) {
13-
return fullRouteName.replace(HTTP_SCHEMA, "");
14+
return Pair(fullRouteName.replace(HTTP_SCHEMA, ""), HTTP_SCHEMA);
1415
}
1516
if (fullRouteName.startsWith(RPC_SCHEMA)) {
16-
return fullRouteName.replace(RPC_SCHEMA, "");
17+
return Pair(fullRouteName.replace(RPC_SCHEMA, ""), RPC_SCHEMA);
18+
}
19+
if (fullRouteName.startsWith(CONSUMER_SCHEMA)) {
20+
return Pair(fullRouteName.replace(CONSUMER_SCHEMA, ""), CONSUMER_SCHEMA);
1721
}
1822
// did not manage to find relevant Scheme, so returning value as is
19-
return fullRouteName;
23+
return Pair(fullRouteName, "");
2024
}
2125

2226
@JvmStatic
@@ -28,6 +32,9 @@ class EndpointSchema {
2832
if (origValue.startsWith(RPC_SCHEMA)) {
2933
return;
3034
}
35+
if (origValue.startsWith(CONSUMER_SCHEMA)) {
36+
return;
37+
}
3138
// default behaviour, to be backward compatible, where did not have the scheme part of the route, so adding it as HTTP one
3239
endpointInsight.route = HTTP_SCHEMA + origValue;
3340
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ internal class EndpointSchemaTest {
99

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

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

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

2525
@Test

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import com.intellij.ui.dsl.builder.RightGap
55
import com.intellij.ui.dsl.builder.panel
66
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
77
import org.digma.intellij.plugin.model.rest.insights.*
8+
import org.digma.intellij.plugin.model.rest.insights.EndpointSchema.Companion.CONSUMER_SCHEMA
9+
import org.digma.intellij.plugin.model.rest.insights.EndpointSchema.Companion.HTTP_SCHEMA
10+
import org.digma.intellij.plugin.model.rest.insights.EndpointSchema.Companion.RPC_SCHEMA
811
import org.digma.intellij.plugin.ui.common.*
912
import org.digma.intellij.plugin.ui.list.AbstractPanelListCellRenderer
1013
import org.digma.intellij.plugin.ui.list.PanelsLayoutHelper
@@ -78,8 +81,8 @@ class InsightsListCellRenderer : AbstractPanelListCellRenderer() {
7881
}
7982

8083
private fun httpEndpointGroupTitle(value: InsightsList.GroupTitleModel): JPanel {
81-
val labelText = headerAsHtml(value)
82-
return groupTitlePanel("REST: ", labelText, Laf.Icons.Insight.INTERFACE)
84+
val header = headerAsHtml(value)
85+
return groupTitlePanel(header.first, header.second, Laf.Icons.Insight.INTERFACE)
8386
}
8487

8588

@@ -98,15 +101,21 @@ class InsightsListCellRenderer : AbstractPanelListCellRenderer() {
98101
}
99102

100103

104+
private fun headerAsHtml(value: InsightsList.GroupTitleModel): Pair<String,String> {
105+
val routeInfo = EndpointSchema.getShortRouteName(value.groupId)
106+
val endpoint = routeInfo.first
107+
return when (routeInfo.second) {
108+
HTTP_SCHEMA -> {
109+
val split = endpoint.split(' ')
110+
Pair("REST: ",asHtml("${spanBold("HTTP")} ${span("${split[0].uppercase()} ${split[1]}")}"))
111+
}
112+
RPC_SCHEMA -> Pair("RPC: ",asHtml(span(endpoint)))
113+
CONSUMER_SCHEMA ->{
114+
val split = endpoint.split(' ')
115+
Pair("CONSUMER: ",asHtml(span("${split[0].uppercase()} ${split[1]}")))
116+
}
117+
else -> Pair("REST: ",asHtml(endpoint))
118+
}
101119

102-
103-
104-
private fun headerAsHtml(value: InsightsList.GroupTitleModel): String {
105-
val shortRouteName = EndpointSchema.getShortRouteName(value.groupId)
106-
// groupId contains "[get|post] [uri]"
107-
val split = shortRouteName.split(' ')
108-
val httpMethod = split[0].uppercase()
109-
val httpRoute = split[1]
110-
return asHtml("${spanBold("HTTP")} ${span("$httpMethod $httpRoute")}")
111120
}
112121
}

0 commit comments

Comments
 (0)