You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/07/05 15:59:00 UTC

[GitHub] [nifi] exceptionfactory commented on a change in pull request #5195: NIFI-8752: Automatic diagnostic at NiFi restart/stop

exceptionfactory commented on a change in pull request #5195:
URL: https://github.com/apache/nifi/pull/5195#discussion_r664026479



##########
File path: nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/util/DiagnosticProperties.java
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.nifi.bootstrap.util;
+
+import org.apache.nifi.properties.BootstrapProperties;
+import org.apache.nifi.util.NiFiBootstrapUtils;
+import org.apache.nifi.util.file.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DiagnosticProperties {
+
+    private static final Logger logger = LoggerFactory.getLogger(DiagnosticProperties.class);
+
+    private static final String ALLOWED_PROP_NAME = "nifi.diag.allowed";
+    private static final boolean ALLOWED_DEFAULT_VALUE = true;
+
+    private static final String DIR_PROP_NAME = "nifi.diag.dir";
+    private static final String DIR_DEFAULT_VALUE = "./diagnostics";
+
+    private static final String MAX_FILE_COUNT_PROP_NAME = "nifi.diag.filecount.max";
+    private static final int MAX_FILE_COUNT_DEFAULT_VALUE = Integer.MAX_VALUE;
+
+    private static final String MAX_SIZE_PROP_NAME = "nifi.diag.size.max.byte";
+    private static final int MAX_SIZE_DEFAULT_VALUE = Integer.MAX_VALUE;
+
+    private static final String VERBOSE_PROP_NAME = "nifi.diag.verbose";
+    private static final boolean VERBOSE_DEFAULT_VALUE = false;
+
+    private final String dirPath;
+    private final int maxFileCount;
+    private final int maxSizeInBytes;
+    private final boolean verbose;
+    private final boolean allowed;
+
+    public DiagnosticProperties() throws IOException {
+        BootstrapProperties properties = NiFiBootstrapUtils.loadBootstrapProperties();
+        this.dirPath = properties.getProperty(DIR_PROP_NAME, DIR_DEFAULT_VALUE);
+        this.maxFileCount = getPropertyAsInt(properties.getProperty(MAX_FILE_COUNT_PROP_NAME), MAX_FILE_COUNT_DEFAULT_VALUE);
+        this.maxSizeInBytes = getPropertyAsInt(properties.getProperty(MAX_SIZE_PROP_NAME), MAX_SIZE_DEFAULT_VALUE);
+        this.verbose = getPropertyAsBoolean(properties.getProperty(VERBOSE_PROP_NAME), VERBOSE_DEFAULT_VALUE);
+        this.allowed = getPropertyAsBoolean(properties.getProperty(ALLOWED_PROP_NAME), ALLOWED_DEFAULT_VALUE);
+        createDiagDir();
+    }
+
+    public Path getOldestFile() throws IOException {

Review comment:
       This class combines both configuration properties and evaluation methods, which does not follow the pattern of most existing NiFi properties.  Recommend refactoring the approach to separate file and directory evaluation from configuration properties.




-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org