github-advanced-security[bot] commented on code in PR #16472: URL: https://github.com/apache/druid/pull/16472#discussion_r1616708075
########## processing/src/test/java/org/apache/druid/java/util/metrics/cgroups/DiskTest.java: ########## @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.java.util.metrics.cgroups; + +import com.google.common.collect.ImmutableMap; +import org.apache.druid.java.util.common.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.util.Map; + +public class DiskTest +{ + @Rule + public ExpectedException expectedException = ExpectedException.none(); Review Comment: ## Deprecated method or constructor invocation Invoking [ExpectedException.none](1) should be avoided because it has been deprecated. [Show more details](https://github.com/apache/druid/security/code-scanning/7404) ########## processing/src/main/java/org/apache/druid/java/util/metrics/CgroupCpuMonitor.java: ########## @@ -20,23 +20,56 @@ package org.apache.druid.java.util.metrics; import com.google.common.collect.ImmutableMap; +import org.apache.druid.java.util.common.logger.Logger; import org.apache.druid.java.util.emitter.service.ServiceEmitter; import org.apache.druid.java.util.emitter.service.ServiceMetricEvent; import org.apache.druid.java.util.metrics.cgroups.CgroupDiscoverer; import org.apache.druid.java.util.metrics.cgroups.Cpu; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.Map; public class CgroupCpuMonitor extends FeedDefiningMonitor { + private static final Logger LOG = new Logger(CgroupCpuMonitor.class); + private static final Long DEFAULT_USER_HZ = 100L; + public static final String TOTAL_USAGE_METRIC = "cgroup/cpu/usage/total/percentage"; + public static final String USER_USAGE_METRIC = "cgroup/cpu/usage/user/percentage"; + public static final String SYS_USAGE_METRIC = "cgroup/cpu/usage/sys/percentage"; + private static final String TOTAL = "total"; + private static final String USER = "user"; + private static final String SYSTEM = "system"; final CgroupDiscoverer cgroupDiscoverer; final Map<String, String[]> dimensions; + private Long userHz; + private KeyedDiff jiffies = new KeyedDiff(); + private long prevJiffiesSnapshotAt = 0; public CgroupCpuMonitor(CgroupDiscoverer cgroupDiscoverer, final Map<String, String[]> dimensions, String feed) { super(feed); this.cgroupDiscoverer = cgroupDiscoverer; this.dimensions = dimensions; + try { + Process process = Runtime.getRuntime().exec("getconf CLK_TCK"); Review Comment: ## Executing a command with a relative path Command with a relative path 'getconf' is executed. [Show more details](https://github.com/apache/druid/security/code-scanning/7406) ########## processing/src/main/java/org/apache/druid/java/util/metrics/CgroupCpuMonitor.java: ########## @@ -20,23 +20,56 @@ package org.apache.druid.java.util.metrics; import com.google.common.collect.ImmutableMap; +import org.apache.druid.java.util.common.logger.Logger; import org.apache.druid.java.util.emitter.service.ServiceEmitter; import org.apache.druid.java.util.emitter.service.ServiceMetricEvent; import org.apache.druid.java.util.metrics.cgroups.CgroupDiscoverer; import org.apache.druid.java.util.metrics.cgroups.Cpu; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.Map; public class CgroupCpuMonitor extends FeedDefiningMonitor { + private static final Logger LOG = new Logger(CgroupCpuMonitor.class); + private static final Long DEFAULT_USER_HZ = 100L; + public static final String TOTAL_USAGE_METRIC = "cgroup/cpu/usage/total/percentage"; + public static final String USER_USAGE_METRIC = "cgroup/cpu/usage/user/percentage"; + public static final String SYS_USAGE_METRIC = "cgroup/cpu/usage/sys/percentage"; + private static final String TOTAL = "total"; + private static final String USER = "user"; + private static final String SYSTEM = "system"; final CgroupDiscoverer cgroupDiscoverer; final Map<String, String[]> dimensions; + private Long userHz; + private KeyedDiff jiffies = new KeyedDiff(); + private long prevJiffiesSnapshotAt = 0; public CgroupCpuMonitor(CgroupDiscoverer cgroupDiscoverer, final Map<String, String[]> dimensions, String feed) { super(feed); this.cgroupDiscoverer = cgroupDiscoverer; this.dimensions = dimensions; + try { + Process process = Runtime.getRuntime().exec("getconf CLK_TCK"); + userHz = Long.parseLong(new BufferedReader(new InputStreamReader( + process.getInputStream(), + StandardCharsets.UTF_8 + )).readLine()); Review Comment: ## Potential input resource leak This InputStreamReader is not always closed on method exit. [Show more details](https://github.com/apache/druid/security/code-scanning/7405) ########## processing/src/test/java/org/apache/druid/java/util/metrics/CgroupDiskMonitorTest.java: ########## @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.java.util.metrics; + +import com.google.common.collect.ImmutableMap; +import org.apache.druid.java.util.common.FileUtils; +import org.apache.druid.java.util.metrics.cgroups.CgroupDiscoverer; +import org.apache.druid.java.util.metrics.cgroups.ProcCgroupDiscoverer; +import org.apache.druid.java.util.metrics.cgroups.TestUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.io.IOException; + +public class CgroupDiskMonitorTest +{ + @Rule + public ExpectedException expectedException = ExpectedException.none(); Review Comment: ## Deprecated method or constructor invocation Invoking [ExpectedException.none](1) should be avoided because it has been deprecated. [Show more details](https://github.com/apache/druid/security/code-scanning/7403) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
