Skip to content

Commit 08eaa9e

Browse files
committed
support endpoint of type consumer
remove suffix '.local' from local hostname if exists.
2 parents 7d051e9 + dd993cf commit 08eaa9e

File tree

12 files changed

+225
-67
lines changed

12 files changed

+225
-67
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public JComponent getPreferredFocusedComponent() {
4141
@Override
4242
public boolean isModified() {
4343
SettingsState settings = SettingsState.getInstance(project);
44-
return isUrlChanged(settings) || isApiTokenChanged(settings) || isRefreshDelayChanged(settings);
44+
return isUrlChanged(settings) || isApiTokenChanged(settings) || isRefreshDelayChanged(settings) || isJaegerUrlChanged(settings);
4545
}
4646

4747
private boolean isRefreshDelayChanged(SettingsState settings) {
@@ -56,6 +56,10 @@ private boolean isApiTokenChanged(SettingsState settings){
5656
return !Objects.equals(settings.apiToken,mySettingsComponent.getApiToken());
5757
}
5858

59+
private boolean isJaegerUrlChanged(SettingsState settings) {
60+
return !Objects.equals(settings.jaegerUrl, mySettingsComponent.getJaegerUrl());
61+
}
62+
5963
@Override
6064
public void apply() throws ConfigurationException {
6165
SettingsState settings = SettingsState.getInstance(project);
@@ -79,6 +83,7 @@ public void apply() throws ConfigurationException {
7983
settings.apiUrl = mySettingsComponent.getApiUrlText();
8084
settings.apiToken = theApiToken;
8185
settings.refreshDelay = Integer.parseInt(mySettingsComponent.getRefreshDelayText());
86+
settings.jaegerUrl = mySettingsComponent.getJaegerUrl();
8287
settings.fireChanged();
8388
}
8489

@@ -88,6 +93,7 @@ public void reset() {
8893
mySettingsComponent.setApiUrlText(settings.apiUrl);
8994
mySettingsComponent.setApiToken(settings.apiToken);
9095
mySettingsComponent.setRefreshDelayText(String.valueOf(settings.refreshDelay));
96+
mySettingsComponent.setJaegerUrl(settings.jaegerUrl);
9197
}
9298

9399
@Override

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

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2-
31
package org.digma.intellij.plugin.settings;
42

53
import com.intellij.openapi.project.Project;
@@ -19,10 +17,11 @@
1917
*/
2018
public class SettingsComponent {
2119

22-
private JPanel myMainPanel;
20+
private final JPanel myMainPanel;
2321
private final JBTextField myApiUrlText = new JBTextField();
2422
private final JBTextField myApiToken = new JBTextField();
2523
private final JBTextField myRefreshDelay = new JBTextField();
24+
private final JBTextField myJaegerUrlText = new JBTextField();
2625

2726
public SettingsComponent(Project project) {
2827

@@ -32,7 +31,7 @@ public SettingsComponent(Project project) {
3231
@Override
3332
public boolean verify(JComponent input) {
3433
try {
35-
new URL(myApiUrlText.getText());
34+
new URL(myApiUrlText.getText().trim());
3635
myUrlLabel.setForeground(myUrlLabelForeground);
3736
return true;
3837
} catch (MalformedURLException e) {
@@ -48,7 +47,7 @@ public boolean verify(JComponent input) {
4847
@Override
4948
public boolean verify(JComponent input) {
5049
try {
51-
Integer.parseInt(myRefreshDelay.getText());
50+
Integer.parseInt(myRefreshDelay.getText().trim());
5251
myRefreshLabel.setForeground(myRefreshLabelForeground);
5352
return true;
5453
} catch (NumberFormatException e) {
@@ -58,6 +57,25 @@ public boolean verify(JComponent input) {
5857
}
5958
});
6059

60+
var myJaegerUrlLabel = new JBLabel("Jaeger URL: ");
61+
var myJaegerUrlForeground = myUrlLabel.getForeground();
62+
myJaegerUrlText.setInputVerifier(new InputVerifier() {
63+
@Override
64+
public boolean verify(JComponent input) {
65+
if (myJaegerUrlText.getText().isBlank()) {
66+
myJaegerUrlLabel.setForeground(myJaegerUrlForeground);
67+
return true;
68+
}
69+
try {
70+
new URL(myJaegerUrlText.getText().trim());
71+
myJaegerUrlLabel.setForeground(myJaegerUrlForeground);
72+
return true;
73+
} catch (MalformedURLException e) {
74+
myJaegerUrlLabel.setForeground(JBColor.RED);
75+
return false;
76+
}
77+
}
78+
});
6179

6280

6381
var resetButton = new JButton("Reset to defaults");
@@ -67,6 +85,7 @@ public boolean verify(JComponent input) {
6785
.addLabeledComponent(myUrlLabel, myApiUrlText, 1, false)
6886
.addLabeledComponent(new JBLabel("Api token:"), myApiToken, 1, false)
6987
.addLabeledComponent(myRefreshLabel, myRefreshDelay, 1, false)
88+
.addLabeledComponent(myJaegerUrlLabel, myJaegerUrlText, 1, false)
7089
.addComponent(resetButton)
7190
.addComponentFillVertically(new JPanel(), 0)
7291
.getPanel();
@@ -82,34 +101,47 @@ public JComponent getPreferredFocusedComponent() {
82101

83102
@NotNull
84103
public String getApiUrlText() {
85-
return myApiUrlText.getText();
104+
return myApiUrlText.getText().trim();
86105
}
87106

88107
public void setApiUrlText(@NotNull String newText) {
89-
myApiUrlText.setText(newText);
108+
myApiUrlText.setText(newText.trim());
90109
}
91110

92111
@Nullable
93112
public String getApiToken() {
94-
return myApiToken.getText();
113+
return myApiToken.getText().trim();
95114
}
96115

97116
public void setApiToken(@Nullable String newText) {
98-
myApiToken.setText(newText);
117+
if (newText == null) {
118+
myApiToken.setText("");
119+
} else {
120+
myApiToken.setText(newText.trim());
121+
}
122+
}
123+
124+
public String getJaegerUrl() {
125+
return myJaegerUrlText.getText().trim();
126+
}
127+
128+
public void setJaegerUrl(String newText) {
129+
myJaegerUrlText.setText(newText.trim());
99130
}
100131

101132
@NotNull
102133
public String getRefreshDelayText() {
103-
return myRefreshDelay.getText();
134+
return myRefreshDelay.getText().trim();
104135
}
105136

106137
public void setRefreshDelayText(@NotNull String newText) {
107-
myRefreshDelay.setText(newText);
138+
myRefreshDelay.setText(newText.trim());
108139
}
109140

110141
private void resetToDefaults(){
111142
this.setApiUrlText(SettingsState.DEFAULT_API_URL);
112143
this.setApiToken(null);
113144
this.setRefreshDelayText(String.valueOf(SettingsState.DEFAULT_REFRESH_DELAY));
145+
this.setJaegerUrl(SettingsState.DEFAULT_JAEGER_URL);
114146
}
115147
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2-
31
package org.digma.intellij.plugin.settings;
42

53
import com.intellij.openapi.Disposable;
@@ -27,11 +25,13 @@ public class SettingsState implements PersistentStateComponent<SettingsState> ,
2725

2826
public static final String DEFAULT_API_URL = "https://localhost:5051";
2927
public static final int DEFAULT_REFRESH_DELAY = 30;
28+
public static final String DEFAULT_JAEGER_URL = "http://localhost:16686";
3029
public String apiUrl = DEFAULT_API_URL;
31-
3230
public int refreshDelay = DEFAULT_REFRESH_DELAY;
3331
@Nullable
3432
public String apiToken = null;
33+
@Nullable
34+
public String jaegerUrl = DEFAULT_API_URL;
3535
private final List<SettingsChangeListener> listeners = new ArrayList<>();
3636

3737
public static SettingsState getInstance(Project project) {

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

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
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:"
8-
const val CONSUMER_SCHEMA: String = "epConsumer:"
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+
}
921

10-
// strips the scheme and returns the rest of the of name
1122
@JvmStatic
12-
fun getShortRouteName(fullRouteName: String): Pair<String, String> {
13-
if (fullRouteName.startsWith(HTTP_SCHEMA)) {
14-
return Pair(fullRouteName.replace(HTTP_SCHEMA, ""), 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
30+
}
31+
if (isOfType(fullRouteName, RPC_SCHEMA)) {
32+
return RPC_SCHEMA
1533
}
16-
if (fullRouteName.startsWith(RPC_SCHEMA)) {
17-
return Pair(fullRouteName.replace(RPC_SCHEMA, ""), RPC_SCHEMA);
34+
if (isOfType(fullRouteName, CONSUMER_SCHEMA)) {
35+
return CONSUMER_SCHEMA
1836
}
19-
if (fullRouteName.startsWith(CONSUMER_SCHEMA)) {
20-
return Pair(fullRouteName.replace(CONSUMER_SCHEMA, ""), CONSUMER_SCHEMA);
37+
return "";
38+
}
39+
40+
@JvmStatic
41+
private fun removeSchema(fullRouteName: String, schema: String): String{
42+
if(schema == ""){
43+
return fullRouteName;
2144
}
22-
// did not manage to find relevant Scheme, so returning value as is
23-
return Pair(fullRouteName, "");
45+
return fullRouteName.replace("$schema:", "");
2446
}
2547

2648
@JvmStatic

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import java.sql.Timestamp
88
@JsonIgnoreProperties(ignoreUnknown = true)
99
data class SpanDurationsPercentile
1010
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
11-
@ConstructorProperties("percentile", "currentDuration","previousDuration","changeTime","changeVerified")
12-
constructor(val percentile: Float,
13-
val currentDuration: Duration,
14-
val previousDuration: Duration?,
15-
val changeTime: Timestamp?,
16-
val changeVerified: Boolean?)
11+
@ConstructorProperties("percentile", "currentDuration", "previousDuration", "changeTime", "changeVerified", "traceIds")
12+
constructor(
13+
val percentile: Float,
14+
val currentDuration: Duration,
15+
val previousDuration: Duration?,
16+
val changeTime: Timestamp?,
17+
val changeVerified: Boolean?,
18+
val traceIds: List<String>,
19+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.digma.intellij.plugin.ui.model
2+
3+
data class TraceSample(val traceName: String, val traceId: String?) {
4+
5+
fun hasTraceId(): Boolean {
6+
return !traceId.isNullOrBlank()
7+
}
8+
}

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").first)
12+
assertEquals("get /hello", getRouteInfo("epHTTP:get /hello").shortName)
1313
}
1414

1515
@Test
1616
fun getShortRouteNameShouldWorkForRpcSchema() {
17-
assertEquals("hello.world", getShortRouteName("epRPC:hello.world").first)
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").first)
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: 2 additions & 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")
@@ -91,6 +92,7 @@ object Laf {
9192
@JvmStatic val SLOW = loadAndScaleInsightIcon("/icons/slow.png")
9293
@JvmStatic val WAITING_DATA = loadAndScaleInsightIcon("/icons/waiting-data.png")
9394
@JvmStatic val HOTSPOT = loadAndScaleInsightIcon("/icons/target.png")
95+
@JvmStatic val HISTOGRAM = loadAndScaleInsightIcon("/icons/histogram.png")
9496
@JvmStatic val SPAN_DURATION_DROPPED = loadAndScaleIconByWidth("/icons/dropped.png", 8)
9597
@JvmStatic val SPAN_DURATION_ROSE = loadAndScaleIconByWidth("/icons/rose.png", 8)
9698
}

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<*>>) :

0 commit comments

Comments
 (0)