Skip to content

Commit 142b6a9

Browse files
authored
Merge pull request #7 from liurui-software/main1
Handled cardinality related concerns
2 parents 0c4a8d6 + 73e11b1 commit 142b6a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+193
-119
lines changed

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
Changelog
22
==========
33

4-
_2024-12-18_
4+
## OJR Release v0.6.0
55

6-
- Initial release of the OJR
6+
- Handled cardinality related concerns
77

88

9+
## OJR Release v0.5.0
910

11+
- Sorted out configuration related issues

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ We will provide more receivers in the future and welcome contributions. Right no
5555
| otel.service.instance.id | instance | The OTel Service instance ID (optional) | N/A | Instana-01 |
5656
| otel.transport.timeout | instance | The transport timeout in milliseconds (optional) | 10000 | 10000 |
5757
| otel.transport.delay | instance | The transport delay (used for Batch processor) in milliseconds (optional) | 100 | 100 |
58+
| otel.restricted.metrics | instance | The metrics list to be omitted to be sent to backend | N/A | db.sql.elapsed_time,process_cpu_usage |
5859
| prometheus.port | instance | The port of Prometheus endpoint if Prometheus is enabled (optional) | 16543 | 16543 |
5960
| prometheus.host | instance | The host of Prometheus endpoint if Prometheus is enabled (optional) | N/A | localhost |
6061
| prometheus.restricted.metrics | instance | The metrics list to be omitted for Prometheus (optional, separated by ",") | N/A | db.sql.elapsed_time,process_cpu_usage |

ojr-dameng-db/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "com.ojr"
7-
version = "0.5.0"
7+
version = "0.5.1"
88

99
java {
1010
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -28,9 +28,9 @@ dependencies {
2828
implementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating:1.28.0-alpha")
2929
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.2")
3030

31-
implementation(files("libs/ojr-core-0.5.0.jar"))
31+
implementation(files("libs/ojr-core-0.6.0.jar"))
3232
implementation(files("libs/ojr-vault-all-0.4.0.jar"))
33-
implementation(files("libs/ojr-rdb-0.5.0.jar"))
33+
implementation(files("libs/ojr-rdb-0.5.1.jar"))
3434
implementation(files("libs/DmJdbcDriver8.jar"))
3535

3636
testImplementation platform('org.junit:junit-bom:5.11.3')

ojr-dameng-db/libs/ojr-core-0.5.0.jar

-44.5 KB
Binary file not shown.

ojr-dameng-db/libs/ojr-core-0.6.0.jar

45.2 KB
Binary file not shown.
Binary file not shown.

ojr-ibmmq/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "com.ojr"
7-
version = "0.1.0"
7+
version = "0.1.1"
88

99
java {
1010
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -30,7 +30,7 @@ dependencies {
3030
implementation('org.apache.commons:commons-lang3:3.17.0')
3131
implementation('com.ibm.mq:com.ibm.mq.allclient:9.4.1.1')
3232

33-
implementation(files("libs/ojr-core-0.5.0.jar"))
33+
implementation(files("libs/ojr-core-0.6.0.jar"))
3434

3535
testImplementation platform('org.junit:junit-bom:5.11.3')
3636
testImplementation 'org.junit.jupiter:junit-jupiter'

ojr-ibmmq/libs/ojr-core-0.5.0.jar

-44.5 KB
Binary file not shown.

ojr-ibmmq/libs/ojr-core-0.6.0.jar

45.2 KB
Binary file not shown.

ojr-informix-db/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "com.ojr"
7-
version = "0.4.0"
7+
version = "0.4.1"
88

99
java {
1010
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -31,9 +31,9 @@ dependencies {
3131
implementation("org.apache.commons:commons-dbcp2:2.11.0")
3232
implementation("com.ibm.informix:jdbc:4.50.10")
3333

34-
implementation(files("libs/ojr-core-0.5.0.jar"))
34+
implementation(files("libs/ojr-core-0.6.0.jar"))
3535
implementation(files("libs/ojr-vault-all-0.4.0.jar"))
36-
implementation(files("libs/ojr-rdb-0.5.0.jar"))
36+
implementation(files("libs/ojr-rdb-0.5.1.jar"))
3737

3838
testImplementation platform('org.junit:junit-bom:5.11.3')
3939
testImplementation 'org.junit.jupiter:junit-jupiter'
-44.5 KB
Binary file not shown.
45.2 KB
Binary file not shown.
Binary file not shown.

ojr-linux-host/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "com.ojr"
7-
version = "0.4.0"
7+
version = "0.4.1"
88

99
java {
1010
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -28,8 +28,8 @@ dependencies {
2828
implementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating:1.28.0-alpha")
2929
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.2")
3030

31-
implementation(files("libs/ojr-core-0.5.0.jar"))
32-
implementation(files("libs/ojr-host-0.5.0.jar"))
31+
implementation(files("libs/ojr-core-0.6.0.jar"))
32+
implementation(files("libs/ojr-host-0.5.1.jar"))
3333

3434
testImplementation platform('org.junit:junit-bom:5.11.3')
3535
testImplementation 'org.junit.jupiter:junit-jupiter'
-44.5 KB
Binary file not shown.
45.2 KB
Binary file not shown.

ojr-mq-appliance/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "com.ojr"
7-
version = "0.4.0"
7+
version = "0.4.1"
88

99
java {
1010
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -28,8 +28,8 @@ dependencies {
2828
implementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating:1.28.0-alpha")
2929
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.2")
3030

31-
implementation(files("libs/ojr-core-0.5.0.jar"))
32-
implementation(files("libs/ojr-host-0.5.0.jar"))
31+
implementation(files("libs/ojr-core-0.6.0.jar"))
32+
implementation(files("libs/ojr-host-0.5.1.jar"))
3333

3434
testImplementation platform('org.junit:junit-bom:5.11.3')
3535
testImplementation 'org.junit.jupiter:junit-jupiter'
-44.5 KB
Binary file not shown.
45.2 KB
Binary file not shown.

ojr-oceanbase-db/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "com.ojr"
7-
version = "0.4.0"
7+
version = "0.4.1"
88

99
java {
1010
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -29,9 +29,9 @@ dependencies {
2929
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.2")
3030
implementation("mysql:mysql-connector-java:5.1.46")
3131

32-
implementation(files("libs/ojr-core-0.5.0.jar"))
32+
implementation(files("libs/ojr-core-0.6.0.jar"))
3333
implementation(files("libs/ojr-vault-all-0.4.0.jar"))
34-
implementation(files("libs/ojr-rdb-0.5.0.jar"))
34+
implementation(files("libs/ojr-rdb-0.5.1.jar"))
3535

3636
testImplementation platform('org.junit:junit-bom:5.11.3')
3737
testImplementation 'org.junit.jupiter:junit-jupiter'
-44.5 KB
Binary file not shown.
45.2 KB
Binary file not shown.

ojr-snmp-host/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "com.ojr"
7-
version = "0.4.0"
7+
version = "0.4.1"
88

99
java {
1010
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -29,9 +29,9 @@ dependencies {
2929
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.2")
3030
implementation("org.snmp4j:snmp4j-agent:3.8.1")
3131

32-
implementation(files("libs/ojr-core-0.5.0.jar"))
32+
implementation(files("libs/ojr-core-0.6.0.jar"))
3333
implementation(files("libs/ojr-snmp-0.4.0.jar"))
34-
implementation(files("libs/ojr-host-0.5.0.jar"))
34+
implementation(files("libs/ojr-host-0.5.1.jar"))
3535

3636
testImplementation platform('org.junit:junit-bom:5.11.3')
3737
testImplementation 'org.junit.jupiter:junit-jupiter'

ojr-snmp-host/libs/ojr-core-0.5.0.jar

-44.5 KB
Binary file not shown.

ojr-snmp-host/libs/ojr-core-0.6.0.jar

45.2 KB
Binary file not shown.
Binary file not shown.

sdk/ojr-core/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "com.ojr"
7-
version = "0.5.0"
7+
version = "0.6.0"
88

99
java {
1010
sourceCompatibility = JavaVersion.VERSION_1_8

sdk/ojr-core/src/main/java/com/ojr/core/AbstractDc.java

+60-26
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.net.InetAddress;
4444
import java.net.UnknownHostException;
4545
import java.time.Duration;
46+
import java.util.Arrays;
4647
import java.util.Map;
4748
import java.util.concurrent.ConcurrentHashMap;
4849
import java.util.concurrent.Executors;
@@ -70,7 +71,9 @@ public abstract class AbstractDc<Cfg extends BasicDcConfig> implements IDc<Cfg>
7071

7172
private int prometheusPort = DcUtil.DEFAULT_PROMETHEUS_PORT;
7273
private String prometheusHost = DcUtil.DEFAULT_PROMETHEUS_HOST;
73-
private String[] prometricsMetricRestrictions = null;
74+
private String[] prometheusMetricRestrictions = null;
75+
76+
private String[] metricRestrictions = null;
7477

7578
private String serviceName = DcUtil.DEFAULT_OTEL_SERVICE_NAME;
7679
private String serviceInstanceId = null;
@@ -196,33 +199,52 @@ public void setPrometheusHost(String prometheusHost) {
196199
}
197200

198201
@Override
199-
public String[] getPrometricsMetricRestrictions() {
200-
return prometricsMetricRestrictions;
202+
public String[] getPrometheusMetricRestrictions() {
203+
return prometheusMetricRestrictions;
201204
}
202205

203-
@Override
204-
public void setPrometricsMetricRestrictions(String metricRestrictionString) {
206+
private String[] parseMetricRestrictions(String metricRestrictionString) {
207+
String[] restrictions = null;
208+
205209
if (metricRestrictionString != null) {
206-
String[] restrictions = metricRestrictionString.split(",");
207-
prometricsMetricRestrictions = new String[restrictions.length];
208-
for (int i = 0; i < restrictions.length; i++) {
209-
prometricsMetricRestrictions[i] = restrictions[i].trim();
210+
String[] restrictions0 = metricRestrictionString.split(",");
211+
restrictions = new String[restrictions0.length];
212+
for (int i = 0; i < restrictions0.length; i++) {
213+
restrictions[i] = restrictions0[i].trim();
210214
}
211215

212-
} else {
213-
prometricsMetricRestrictions = null;
214216
}
217+
return restrictions;
218+
}
219+
220+
@Override
221+
public void setPrometheusMetricRestrictions(String metricRestrictionString) {
222+
prometheusMetricRestrictions = parseMetricRestrictions(metricRestrictionString);
223+
}
224+
225+
@Override
226+
public void setPrometheusMetricRestrictions(String[] prometricsMetricRestrictions) {
227+
this.prometheusMetricRestrictions = prometricsMetricRestrictions;
228+
}
229+
230+
@Override
231+
public String[] getMetricRestrictions() {
232+
return metricRestrictions;
215233
}
216234

217235
@Override
218-
public void setPrometricsMetricRestrictions(String[] prometricsMetricRestrictions) {
219-
this.prometricsMetricRestrictions = prometricsMetricRestrictions;
236+
public void setMetricRestrictions(String metricRestrictionString) {
237+
metricRestrictions = parseMetricRestrictions(metricRestrictionString);
238+
}
239+
240+
@Override
241+
public void setMetricRestrictions(String[] MetricRestrictions) {
242+
this.metricRestrictions = MetricRestrictions;
220243
}
221244

222245
@Override
223246
public String getHostname() {
224-
if (hostname != null)
225-
return hostname;
247+
if (hostname != null) return hostname;
226248

227249
try {
228250
hostname = InetAddress.getLocalHost().getHostName();
@@ -243,8 +265,7 @@ public void setHostname(String hostname) {
243265

244266
@Override
245267
public long getPid() {
246-
if (pid != null)
247-
return pid;
268+
if (pid != null) return pid;
248269

249270
pid = DcUtil.getPid();
250271
return pid;
@@ -257,8 +278,7 @@ public void setPid(long pid) {
257278

258279
@Override
259280
public String getContainerId() {
260-
if (containerId != null)
261-
return containerId;
281+
if (containerId != null) return containerId;
262282

263283
containerId = new ContainerResource().getContainerId().orElse(DcUtil.N_A);
264284
return containerId;
@@ -289,10 +309,24 @@ public Map<String, Meter> getMeters() {
289309
public void registerMetrics() {
290310
// Iterate through the raw metrics and register each one
291311
for (RawMetric rawMetric : rawMetricsMap.values()) {
292-
DcUtil.registerMetric(meters, rawMetric);
312+
DcUtil.registerMetric(meters, rawMetric, this);
293313
}
294314
}
295315

316+
@Override
317+
public boolean preRecordMetric(RawMetric rawMetric) {
318+
if (metricRestrictions == null) return true;
319+
320+
return !Arrays.asList(metricRestrictions).contains(rawMetric.getName());
321+
}
322+
323+
@Override
324+
public boolean preRecordMetric(String metricName, Number value, Map<String, Object> attributes) {
325+
if (metricRestrictions == null) return true;
326+
327+
return !Arrays.asList(metricRestrictions).contains(metricName);
328+
}
329+
296330
/**
297331
* Retrieves a raw metric by its name.
298332
*
@@ -447,8 +481,7 @@ public LogRecordExporter createOtlpHttpLogRecordExporter(Map<String, String> hea
447481

448482
//private static MetricReader prometheusMetricReader = null;
449483

450-
private static final Predicate<String> dftResAttrsFilterForPrometheus =
451-
(String key) -> DcUtil.OJR_PLUGIN.equals(key) || HostIncubatingAttributes.HOST_NAME.getKey().equals(key);
484+
private static final Predicate<String> dftResAttrsFilterForPrometheus = (String key) -> DcUtil.OJR_PLUGIN.equals(key) || HostIncubatingAttributes.HOST_NAME.getKey().equals(key);
452485

453486
/**
454487
* Returns the filter for resource attributes used when exporting metrics to Prometheus.
@@ -484,7 +517,7 @@ public synchronized OjrPrometheusHttpServer createPrometheusHttpServerIfNotExist
484517
if (prometheusHttpServer != null) {
485518
return prometheusHttpServer; // Return early if the server is already created
486519
}
487-
prometheusHttpServer = new OjrPrometheusHttpServer(prometheusHost, prometheusPort, null, MemoryMode.REUSABLE_DATA, prometricsMetricRestrictions);
520+
prometheusHttpServer = new OjrPrometheusHttpServer(prometheusHost, prometheusPort, null, MemoryMode.REUSABLE_DATA, prometheusMetricRestrictions);
488521
return prometheusHttpServer;
489522
}
490523

@@ -601,9 +634,11 @@ public void readBuiltinParameters(Map<String, Object> properties, Cfg config) {
601634
setBackendUrl((String) properties.getOrDefault(DcUtil.OTEL_BACKEND_URL, DcUtil.DEFAULT_OTEL_BACKEND_URL));
602635
setTransport((String) properties.getOrDefault(DcUtil.OTEL_TRANSPORT, DcUtil.DEFAULT_OTEL_TRANSPORT));
603636

637+
setMetricRestrictions((String) properties.get(DcUtil.OTEL_RESTRICTED_METRICS));
638+
604639
setPrometheusPort((Integer) properties.getOrDefault(DcUtil.PROMETHEUS_PORT, DcUtil.DEFAULT_PROMETHEUS_PORT));
605640
setPrometheusHost((String) properties.get(DcUtil.PROMETHEUS_HOST));
606-
setPrometricsMetricRestrictions((String) properties.get(DcUtil.PROMETHEUS_RESTRICTED_METRICS));
641+
setPrometheusMetricRestrictions((String) properties.get(DcUtil.PROMETHEUS_RESTRICTED_METRICS));
607642

608643
setServiceName((String) properties.getOrDefault(DcUtil.OTEL_SERVICE_NAME, DcUtil.DEFAULT_OTEL_SERVICE_NAME));
609644
setServiceInstanceId((String) properties.get(DcUtil.OTEL_SERVICE_INSTANCE_ID));
@@ -647,8 +682,7 @@ public void initEnv(Map<String, Object> properties, Cfg config) throws Exception
647682
* @return a Resource object containing the attributes.
648683
*/
649684
public Resource retrieveResourceAttributes() {
650-
Resource resource = Resource.create(Attributes.of(ServiceAttributes.SERVICE_NAME, serviceName, TelemetryAttributes.TELEMETRY_SDK_NAME, "ojr",
651-
TelemetryAttributes.TELEMETRY_SDK_LANGUAGE, "java", TelemetryAttributes.TELEMETRY_SDK_VERSION, DcUtil.OCR_VERSION));
685+
Resource resource = Resource.create(Attributes.of(ServiceAttributes.SERVICE_NAME, serviceName, TelemetryAttributes.TELEMETRY_SDK_NAME, "ojr", TelemetryAttributes.TELEMETRY_SDK_LANGUAGE, "java", TelemetryAttributes.TELEMETRY_SDK_VERSION, DcUtil.OCR_VERSION));
652686

653687
ResourceEnricher enricher = new ResourceEnricher(resource);
654688
enricher.enrich(ServiceIncubatingAttributes.SERVICE_INSTANCE_ID, serviceInstanceId);

0 commit comments

Comments
 (0)