Skip to content

Commit 1127ad1

Browse files
committed
refactor: migrate LiveSourceLocation.service to Service type
1 parent bc6c836 commit 1127ad1

File tree

5 files changed

+466
-15
lines changed

5 files changed

+466
-15
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Source++, the continuous feedback platform for developers.
3+
* Copyright (C) 2022-2023 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.protocol.instrument.location
18+
19+
import spp.protocol.platform.general.Service
20+
21+
/**
22+
* Represents a location in a live application.
23+
*/
24+
interface LiveLocation {
25+
val service: Service?
26+
val serviceInstance: String?
27+
val commitId: String?
28+
val fileChecksum: String?
29+
val probeId: String?
30+
}

src/main/kotlin/spp/protocol/instrument/location/LiveSourceLocation.kt

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ package spp.protocol.instrument.location
1818

1919
import io.vertx.codegen.annotations.DataObject
2020
import io.vertx.core.json.JsonObject
21+
import spp.protocol.platform.general.Service
2122
import spp.protocol.platform.status.InstanceConnection
2223

2324
/**
24-
* todo: description.
25+
* Represents a location in source code.
2526
*
2627
* @since 0.3.0
2728
* @author [Brandon Fergerson](mailto:bfergerson@apache.org)
@@ -30,23 +31,21 @@ import spp.protocol.platform.status.InstanceConnection
3031
data class LiveSourceLocation @JvmOverloads constructor(
3132
val source: String,
3233
val line: Int = -1,
33-
val service: String? = null, //todo: can use Service
34-
val serviceInstance: String? = null, //todo: fully impl
35-
val commitId: String? = null, //todo: impl
36-
val fileChecksum: String? = null, //todo: impl
37-
//val language: ArtifactLanguage? = null, //todo: impl
38-
val probeId: String? = null,
34+
override val service: Service? = null,
35+
override val serviceInstance: String? = null,
36+
override val commitId: String? = null,
37+
override val fileChecksum: String? = null, //todo: impl
38+
override val probeId: String? = null, //todo: impl
3939
val scope: LocationScope = LocationScope.LINE
40-
) : Comparable<LiveSourceLocation> {
40+
) : LiveLocation, Comparable<LiveSourceLocation> {
4141

4242
constructor(json: JsonObject) : this(
4343
source = json.getString("source"),
4444
line = json.getInteger("line") ?: -1,
45-
service = json.getString("service"),
45+
service = json.getJsonObject("service")?.let { Service(it) },
4646
serviceInstance = json.getString("serviceInstance"),
4747
commitId = json.getString("commitId"),
4848
fileChecksum = json.getString("fileChecksum"),
49-
//language = json.getString("language")?.let { ArtifactLanguage.valueOf(it) }
5049
probeId = json.getString("probeId"),
5150
scope = json.getString("scope")?.let { LocationScope.valueOf(it) } ?: LocationScope.LINE
5251
)
@@ -55,11 +54,10 @@ data class LiveSourceLocation @JvmOverloads constructor(
5554
val json = JsonObject()
5655
json.put("source", source)
5756
json.put("line", line)
58-
json.put("service", service)
57+
json.put("service", service?.toJson())
5958
json.put("serviceInstance", serviceInstance)
6059
json.put("commitId", commitId)
6160
json.put("fileChecksum", fileChecksum)
62-
//json.put("language", language?.name)
6361
json.put("probeId", probeId)
6462
json.put("scope", scope.name)
6563
return json
@@ -78,13 +76,12 @@ data class LiveSourceLocation @JvmOverloads constructor(
7876
if (serviceInstance != other.serviceInstance) return false
7977
if (commitId != other.commitId) return false
8078
if (fileChecksum != other.fileChecksum) return false
81-
//if (language != other.language) return false
8279
if (probeId != other.probeId) return false
8380
return true
8481
}
8582

8683
fun isSameLocation(other: InstanceConnection): Boolean {
87-
if (service != null && service != other.meta["service"]) return false
84+
if (service != null && service.name != other.meta["service"]) return false
8885
if (serviceInstance != null && serviceInstance != other.meta["service_instance"]) return false
8986
if (commitId != null && commitId != other.meta["commit_id"]) return false
9087
if (probeId != null && probeId != other.instanceId) return false
@@ -100,7 +97,6 @@ data class LiveSourceLocation @JvmOverloads constructor(
10097
if (serviceInstance != null) append(", serviceInstance=$serviceInstance")
10198
if (commitId != null) append(", commitId=$commitId")
10299
if (fileChecksum != null) append(", fileChecksum=$fileChecksum")
103-
//if (language != null) append(", language=$language")
104100
if (probeId != null) append(", probeId=$probeId")
105101
if (scope != LocationScope.LINE) append(", scope=$scope")
106102
append(")")

src/main/kotlin/spp/protocol/platform/general/Service.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package spp.protocol.platform.general
1818

1919
import io.vertx.codegen.annotations.DataObject
2020
import io.vertx.core.json.JsonObject
21+
import spp.protocol.platform.general.util.IDManager
2122

2223
/**
2324
* Represents a service.
@@ -52,4 +53,30 @@ data class Service(
5253
json.put("normal", normal)
5354
return json
5455
}
56+
57+
companion object {
58+
fun fromId(id: String): Service {
59+
val definition = IDManager.ServiceID.analysisId(id)
60+
return Service(
61+
id = id,
62+
name = definition.name,
63+
normal = definition.isReal
64+
)
65+
}
66+
67+
fun fromName(name: String): Service {
68+
return Service(
69+
id = IDManager.ServiceID.buildId(name, true),
70+
name = name
71+
)
72+
}
73+
74+
fun fromNameIfPresent(name: String?): Service? {
75+
return if (name != null) {
76+
fromName(name)
77+
} else {
78+
null
79+
}
80+
}
81+
}
5582
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Source++, the continuous feedback platform for developers.
3+
* Copyright (C) 2022-2023 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.protocol.platform.general.util
18+
19+
/**
20+
* Code taken from https://github.com/apache/skywalking/blob/v9.5.0/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/Const.java.
21+
*/
22+
object Const {
23+
const val NONE = 0
24+
const val SERVICE_ID_CONNECTOR = "."
25+
const val SERVICE_ID_PARSER_SPLIT = "\\."
26+
const val ID_CONNECTOR = "_"
27+
const val ID_PARSER_SPLIT = "\\_"
28+
const val RELATION_ID_CONNECTOR = "-"
29+
const val RELATION_ID_PARSER_SPLIT = "\\-"
30+
const val LINE = "-"
31+
const val UNDERSCORE = "_"
32+
const val COMMA = ","
33+
const val SPACE = " "
34+
const val KEY_VALUE_SPLIT = ","
35+
const val ARRAY_SPLIT = "|"
36+
const val ARRAY_PARSER_SPLIT = "\\|"
37+
const val USER_SERVICE_NAME = "User"
38+
const val USER_INSTANCE_NAME = "User"
39+
const val USER_ENDPOINT_NAME = "User"
40+
const val SEGMENT_SPAN_SPLIT = "S"
41+
const val UNKNOWN = "Unknown"
42+
const val EMPTY_STRING = ""
43+
const val POINT = "."
44+
const val DOUBLE_COLONS_SPLIT = "::"
45+
const val BLANK_ENTITY_NAME = "_blank"
46+
47+
object TLS_MODE {
48+
const val NON_TLS = "NONE"
49+
const val M_TLS = "mTLS"
50+
const val TLS = "TLS"
51+
}
52+
}

0 commit comments

Comments
 (0)