Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EDStatic refactor and Prometheus FeatureFlag metrics #254

Merged
merged 13 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Free Disk Space Before Build
run: |
echo "Disk space before cleanup:"
df -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /usr/local/.ghcup
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /usr/local/lib/android/sdk/ndk
sudo apt-get clean
echo "Disk space after cleanup:"
df -h
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions WEB-INF/classes/com/cohort/util/File2.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ public static String getWebInfParentDirectory() {
return webInfParentDirectory;
}

public static String getRefDirectory() {
return getWebInfParentDirectory() + "WEB-INF/ref/";
}

public static void setWebInfParentDirectory(String webInfParentDir) {
webInfParentDirectory = webInfParentDir.replace("\\", "/");
}
Expand Down
6 changes: 1 addition & 5 deletions WEB-INF/classes/com/cohort/util/Units2.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.List;
import java.util.Map;
import ucar.units.Unit;
import ucar.units.UnitFormat;

/**
* This class has static methods to convert units from one standard to another. An old local copy of
Expand Down Expand Up @@ -1114,9 +1113,6 @@ public static boolean udunitsAreEquivalent(String ud1, String ud2) {
return udunitsToUcum(ud1).equals(udunitsToUcum(ud2));
}

// ******************************
public static final UnitFormat unitFormat = ucar.units.StandardUnitFormat.instance();

/**
* This tries to return a standardized (lightly canonical) version of a UDUnits string. This is
* mostly about standardizing syntax and converting synonyms to 1 option. This is just a standard
Expand All @@ -1140,7 +1136,7 @@ public static String safeStandardizeUdunits(String udunits) {
*/
public static String safeCanonicalUdunitsString(String udunits) {
try {
Unit units = unitFormat.parse(udunits);
Unit units = ucar.units.StandardUnitFormat.instance().parse(udunits);
return units == null ? null : units.getCanonicalString();
} catch (Exception e) {
return null;
Expand Down
15 changes: 8 additions & 7 deletions WEB-INF/classes/gov/noaa/pfel/coastwatch/TestAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ public static void main(String args[]) throws Throwable {
String2.setupCommonsLogging(-1);

// set log file to <bigParentDir>/logs/TestAll.out
EDStatic.quickRestart = false; // also, this forces EDStatic instantiation when running TestAll
EDStatic.config.quickRestart =
false; // also, this forces EDStatic instantiation when running TestAll
String2.setupLog(
true,
false, // output to system.out and a file:
EDStatic.fullLogsDirectory + "TestAll.log",
EDStatic.config.fullLogsDirectory + "TestAll.log",
false,
1000000000); // append?
EDD.testVerboseOn();
Expand All @@ -71,8 +72,8 @@ public static void main(String args[]) throws Throwable {
// this might cause small problems for a public running erddap
// but Bob only uses this on laptop, with private erddap.
File2.deleteAllFiles(
EDStatic.fullPublicDirectory, true, false); // recursive, deleteEmptySubdirectories
File2.deleteAllFiles(EDStatic.fullCacheDirectory, true, false);
EDStatic.config.fullPublicDirectory, true, false); // recursive, deleteEmptySubdirectories
File2.deleteAllFiles(EDStatic.config.fullCacheDirectory, true, false);

// make it appear that initialLoadDatasets() is not true
EDStatic.majorLoadDatasetsTimeSeriesSB.append("\n");
Expand Down Expand Up @@ -328,7 +329,7 @@ public static void main(String args[]) throws Throwable {

// s = Projects.makeAwsS3FilesDatasets(".*"); //all: .* tests: nrel-pds-wtk\\.yaml,
// silo\\.yaml (has ?Name: but ? doesn't show in EditPlus)
// File2.writeToFileUtf8(EDStatic.bigParentDirectory + "logs/awsS3Files.txt", s);
// File2.writeToFileUtf8(EDStatic.config.bigParentDirectory + "logs/awsS3Files.txt", s);
// String2.log(EDD.testDasDds("radar_vola"));

/*
Expand Down Expand Up @@ -453,7 +454,7 @@ public static void main(String args[]) throws Throwable {
// String2.setClipboardString(s); String2.log(s);

/* //tallyXml
String tfn = EDStatic.fullLogsDirectory + "tallyLterSbsStorageUnitsMV.log";
String tfn = EDStatic.config.fullLogsDirectory + "tallyLterSbsStorageUnitsMV.log";
File2.writeToFileUtf8(tfn,
FileVisitorDNLS.tallyXml(
"/u00/data/points/lterSbc/", "knb-lter-sbc\\.\\d+", false,
Expand Down Expand Up @@ -1215,7 +1216,7 @@ public static void main(String args[]) throws Throwable {
// of testAll

if (errorSB != null && errorSB.length() > 0) {
String fileName = EDStatic.fullLogsDirectory + "/TestAllErrorSB.txt";
String fileName = EDStatic.config.fullLogsDirectory + "/TestAllErrorSB.txt";
String2.log(
File2.writeToFileUtf8(
fileName,
Expand Down
23 changes: 6 additions & 17 deletions WEB-INF/classes/gov/noaa/pfel/coastwatch/sgt/Boundaries.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,13 @@ public class Boundaries {
*/
public static final boolean debug = false;

public static final String REF_DIRECTORY =
File2.getWebInfParentDirectory()
+ // with / separator and / at the end
"WEB-INF/ref/";

/**
* The nationalBoundary and stateBoundary files must be in the refDirectory. "gshhs_?.b"
* (?=f|h|i|l|c) files. The files are from the GSHHS project
* (https://www.ngdc.noaa.gov/mgg/shorelines/gshhs.html 2009-10-28 v2.0). GPL license:
* http://www.soest.hawaii.edu/pwessel/gshhs/README.TXT landMaskDir should have slash at end.
*/
public String directory =
File2.getWebInfParentDirectory()
+ // with / separator and / at the end
"WEB-INF/ref/";
public static final String REF_DIRECTORY = File2.getRefDirectory();

/**
* Since boundary SGTLines are time-consuming to contruct, this caches the last cacheSize used
Expand Down Expand Up @@ -134,10 +126,8 @@ public class Boundaries {
* @param fileNames the 5 file names
* @param fileFormat MATLAB_FORMAT or GMT_FORMAT
*/
public Boundaries(
String id, String directory, ImmutableList<String> fileNames, BoundaryCounter counter) {
public Boundaries(String id, ImmutableList<String> fileNames, BoundaryCounter counter) {
this.id = id;
this.directory = directory;
this.fileNames = fileNames;
this.counter = counter;
}
Expand Down Expand Up @@ -181,7 +171,8 @@ public SGTLine getSgtLine(int resolution, double west, double east, double south
// And the request is usually a large part of whole world. Most paths will be used.
counter.increment(Metrics.BoundaryRequest.coarse);
tCoarse = "*";
sgtLine = readSgtLineDouble(directory + fileNames.get(resolution), west, east, south, north);
sgtLine =
readSgtLineDouble(REF_DIRECTORY + fileNames.get(resolution), west, east, south, north);

} else {

Expand All @@ -202,7 +193,8 @@ public SGTLine getSgtLine(int resolution, double west, double east, double south

// not in cache, make SgtLine
sgtLine =
readSgtLineDouble(directory + fileNames.get(resolution), west, east, south, north);
readSgtLineDouble(
REF_DIRECTORY + fileNames.get(resolution), west, east, south, north);

// cache full?
if (cache.size() == CACHE_SIZE) {
Expand Down Expand Up @@ -691,7 +683,6 @@ public String statsString() {
public static Boundaries getNationalBoundaries() {
return new Boundaries(
"NationalBoundaries",
REF_DIRECTORY,
NATIONAL_FILE_NAMES,
new BoundaryCounter(
"national_boundaries_request_total", "Requests for national boundaries"));
Expand All @@ -701,7 +692,6 @@ public static Boundaries getNationalBoundaries() {
public static Boundaries getStateBoundaries() {
return new Boundaries(
"StateBoundaries",
REF_DIRECTORY,
STATE_FILE_NAMES,
new BoundaryCounter("state_boundaries_request_total", "Requests for state boundaries"));
}
Expand All @@ -710,7 +700,6 @@ public static Boundaries getStateBoundaries() {
public static Boundaries getRivers() {
return new Boundaries(
"Rivers",
REF_DIRECTORY,
RIVER_FILE_NAMES,
new BoundaryCounter("river_boundaries_request_total", "Requests for river boundaries"));
}
Expand Down
5 changes: 1 addition & 4 deletions WEB-INF/classes/gov/noaa/pfel/coastwatch/sgt/GSHHS.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public class GSHHS {
* from the GSHHS project (https://www.ngdc.noaa.gov/mgg/shorelines/gshhs.html). landMaskDir
* should have slash at end.
*/
public static final String gshhsDirectory =
File2.getWebInfParentDirectory()
+ // with / separator and / at the end
"WEB-INF/ref/";
public static final String gshhsDirectory = File2.getRefDirectory();

/**
* Since GeneralPaths are time-consuming to contruct, getGeneralPath caches the last CACHE_SIZE
Expand Down
2 changes: 0 additions & 2 deletions WEB-INF/classes/gov/noaa/pfel/coastwatch/sgt/SgtGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public class SgtGraph {

public static Color DefaultBackgroundColor = new Color(0xCCCCFF); // just the RGB part (no A)
public final int widenOnePoint = 1; // pixels
public static String fullTestCacheDir =
"/erddapBPD/cache/_test/"; // EDStatic resets this if needed

/**
* Constructor. This throws exception if trouble
Expand Down
5 changes: 1 addition & 4 deletions WEB-INF/classes/gov/noaa/pfel/coastwatch/sgt/SgtMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ public class SgtMap {
* (?=f|h|i|l|c) files. The files are from the GSHHS project
* (https://www.ngdc.noaa.gov/mgg/shorelines/gshhs.html). landMaskDir should have slash at end.
*/
public static final String fullRefDirectory =
File2.getWebInfParentDirectory()
+ // with / separator and / at the end
"WEB-INF/ref/";
public static final String fullRefDirectory = File2.getRefDirectory();

// some of this information is in DataSet.properties too, see BAthymFGDC
public static final String etopoFileName = "etopo1_ice_g_i2.bin";
Expand Down
16 changes: 9 additions & 7 deletions WEB-INF/classes/gov/noaa/pfel/coastwatch/sgt/SgtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ public class SgtUtil {

public static final int LEGEND_BELOW = 1;

public static final com.lowagie.text.Rectangle PDF_LANDSCAPE = PageSize.LETTER.rotate();
public static final com.lowagie.text.Rectangle PDF_PORTRAIT = PageSize.LETTER;
public enum PDFPageSize {
LETTER_PORTRAIT,
LETTER_LANDSCAPE,
}

public static final double DEFAULT_AXIS_LABEL_HEIGHT = 0.12;
public static final double DEFAULT_LABEL_HEIGHT =
Expand Down Expand Up @@ -600,11 +602,10 @@ public static void saveAsTransparentPng(
* @return an object[] with 0=g2D, 1=document, 2=pdfContentByte, 3=pdfTemplate
* @throws Exception if trouble
*/
public static Object[] createPdf(
com.lowagie.text.Rectangle pageSize, int bbWidth, int bbHeight, String fullFileName)
public static Object[] createPdf(PDFPageSize size, int bbWidth, int bbHeight, String fullFileName)
throws Exception {
return createPdf(
pageSize, bbWidth, bbHeight, new BufferedOutputStream(new FileOutputStream(fullFileName)));
size, bbWidth, bbHeight, new BufferedOutputStream(new FileOutputStream(fullFileName)));
}

/**
Expand All @@ -619,8 +620,9 @@ public static Object[] createPdf(
* @throws Exception if trouble
*/
public static Object[] createPdf(
com.lowagie.text.Rectangle pageSize, int bbWidth, int bbHeight, OutputStream outputStream)
throws Exception {
PDFPageSize size, int bbWidth, int bbHeight, OutputStream outputStream) throws Exception {
com.lowagie.text.Rectangle pageSize =
size == PDFPageSize.LETTER_PORTRAIT ? PageSize.LETTER : PageSize.LETTER.rotate();
// currently, this uses itext
// see the sample program:
//
Expand Down
10 changes: 5 additions & 5 deletions WEB-INF/classes/gov/noaa/pfel/coastwatch/util/HtmlWidgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,17 +561,17 @@ public static String cssTooltipImageBase64(
// "copy text/image to clipboard" buttons
"\ndata:image/png;base64\n"
+ "<button type=\"button\" onclick=\"javascript:if(navigator.clipboard==undefined){alert('"
+ EDStatic.copyToClipboardNotAvailableAr[language]
+ EDStatic.messages.copyToClipboardNotAvailableAr[language]
+ "');return false};navigator.clipboard.writeText("
+ "document.getElementById('"
+ img2ID
+ "').getAttribute('data-src')"
+ // reuse img2Url data from img2ID.data-src
");\" style=\"cursor: pointer; cursor: hand;\" >"
+ EDStatic.copyTextToClipboardAr[language]
+ EDStatic.messages.copyTextToClipboardAr[language]
+ "</button>\n"
+ "<button type=\"button\" onclick=\"javascript:if(navigator.clipboard==undefined){alert('"
+ EDStatic.copyToClipboardNotAvailableAr[language]
+ EDStatic.messages.copyToClipboardNotAvailableAr[language]
+ "');return false};"
+ " var img = new Image();"
+ " img.onload = () => {"
Expand All @@ -587,7 +587,7 @@ public static String cssTooltipImageBase64(
+ // reuse img2Url data from img2ID.data-src
" return false;\""
+ " style=\"cursor: pointer; cursor: hand;\" >"
+ EDStatic.copyImageToClipboardAr[language]
+ EDStatic.messages.copyImageToClipboardAr[language]
+ "</button>";
}

Expand Down Expand Up @@ -1593,7 +1593,7 @@ public String textField(
* htmlTooltipScript (see above) must be already in the document. See tip().
*
* @param imageRef the reference for the question mark image (e.g.,
* EDStatic.imageDirUrl(loggedInAs, language) + EDStatic.questionMarkImageFile)
* EDStatic.imageDirUrl(loggedInAs, language) + EDStatic.messages.questionMarkImageFile)
* @param alt the alt text to be displayed, e.g., "?" (not yet encoded)
* @param html the html tooltip text, e.g., "Hi,<br>
* there!". It needs explicit br tags to set window width correctly. For plain text, use
Expand Down
4 changes: 2 additions & 2 deletions WEB-INF/classes/gov/noaa/pfel/erddap/ArchiveADataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public String doIt(int language, String args[]) throws Throwable {
GregorianCalendar gcZ = Calendar2.newGCalendarZulu();
String isoTime = Calendar2.formatAsISODateTimeTZ(gcZ);
String compactTime = Calendar2.formatAsCompactDateTime(gcZ) + "Z";
String aadDir = EDStatic.bigParentDirectory + "ArchiveADataset/";
String aadDir = EDStatic.config.bigParentDirectory + "ArchiveADataset/";
File2.makeDirectory(aadDir);
String logFileName = aadDir + "log_" + compactTime + ".txt";
String2.setupLog(
Expand Down Expand Up @@ -212,7 +212,7 @@ public String doIt(int language, String args[]) throws Throwable {
get(
args,
whichArg++,
EDStatic.adminEmail, // default
EDStatic.config.adminEmail, // default
"What is a contact email address for this archive\n"
+ "(it will be written in the READ_ME.txt file in the archive)");

Expand Down
8 changes: 4 additions & 4 deletions WEB-INF/classes/gov/noaa/pfel/erddap/DasDds.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class DasDds {
Writer outFile = null;

public DasDds() {
logFileName = EDStatic.fullLogsDirectory + "DasDds.log";
outFileName = EDStatic.fullLogsDirectory + "DasDds.out";
logFileName = EDStatic.config.fullLogsDirectory + "DasDds.log";
outFileName = EDStatic.config.fullLogsDirectory + "DasDds.out";
}

private void printToBoth(String s) throws IOException {
Expand Down Expand Up @@ -100,8 +100,8 @@ public String doIt(String args[], boolean loop) throws Throwable {
try {

// delete the old log files (pre 1.48 names)
File2.delete(EDStatic.fullLogsDirectory + "DasDdsLog.txt");
File2.delete(EDStatic.fullLogsDirectory + "DasDdsLog.txt.previous");
File2.delete(EDStatic.config.fullLogsDirectory + "DasDdsLog.txt");
File2.delete(EDStatic.config.fullLogsDirectory + "DasDdsLog.txt.previous");

String datasetID = "";
if (args == null) args = new String[0];
Expand Down
Loading