Skip to content

Commit

Permalink
HPCC-29546 Code review 1
Browse files Browse the repository at this point in the history
- Renames grafana-access secrets
- Restructures encodeCSV
- Adds encodeCSV unittest
- Implements missing logaccess methods
- Cleans up various style issues
- Attempts to minimize StringBuffer resizes
- Adds sortby support
- Enables csv header reporting

Signed-off-by: Rodrigo Pastrana <[email protected]>
  • Loading branch information
rpastrana committed Jun 27, 2024
1 parent 96d641a commit 4e8473f
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 123 deletions.
9 changes: 5 additions & 4 deletions helm/managed/logging/loki-stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ HPCC logAccess requires access to the Grafana username/password. Those values mu

The secret is expected to be in the 'esp' category, and be named 'grafana-logaccess'. The following key-value pairs are required (key names must be spelled exactly as shown here)

grafana-username - This should contain the Grafana username
grafana-password - This should contain the Grafana password
username - This should contain the Grafana username
password - This should contain the Grafana password

The included 'create-grafana-logaccess-secret.sh' helper can be used to create the necessary secret.

Expand All @@ -114,7 +114,7 @@ Example use:

####

The grafana hpcc logaccess values should provide Grafana connection information, such as the host, and port; the Loki datasource where the logs recide; the k8s namespace under which the logs were created; and the hpcc compnent log format (table|json|xml)
The grafana hpcc logaccess values should provide Grafana connection information, such as the host, and port; the Loki datasource where the logs reside; the k8s namespace under which the logs were created; and the hpcc compnent log format (table|json|xml)

Example use:
global:
Expand All @@ -131,4 +131,5 @@ Example use:
namespace:
name: "hpcc"
logFormat:
type: "json"
type: "json"

Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ usage()
echo ""
echo "Expected directory structure:"
echo "${secretsdir}/"
echo " grafana-password - Should contain Grafana user name"
echo " grafana-username - Should contain Grafana password"
echo " password - Should contain Grafana user name"
echo " username - Should contain Grafana password"
}

while [ "$#" -gt 0 ]; do
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions helm/managed/logging/loki-stack/secrets-templates/password
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Grafana access password goes here>
40 changes: 19 additions & 21 deletions system/jlib/jstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2367,14 +2367,14 @@ StringBuffer &encodeJSON(StringBuffer &s, const char *value)
return encodeJSON(s, strlen(value), value);
}

inline StringBuffer &encodeCSVChar(StringBuffer &s, const char *&ch, unsigned &remaining)
inline StringBuffer & encodeCSVChar(StringBuffer & encodedCSV, char ch)
{
byte next = *ch;
byte next = ch;
switch (next)
{
case '\"':
s.append("\"");
s.append(next);
encodedCSV.append("\"");
encodedCSV.append(next);
break;
//case '\n':
// s.append("\\n");
Expand All @@ -2383,31 +2383,29 @@ inline StringBuffer &encodeCSVChar(StringBuffer &s, const char *&ch, unsigned &r
// s.append("\\r");
// break;
default:
s.append(next);
encodedCSV.append(next);
break;
}
ch++;
remaining--;
return s;
return encodedCSV;
}

StringBuffer &encodeCSV(StringBuffer &s, unsigned size, const char *value)
StringBuffer & encodeCSVColumn(StringBuffer & encodedCSV, unsigned size, const char *rawCSVCol)
{
if (!value)
return s;
s.ensureCapacity(size); // Minimum size that will be written
s.append("\"");
while (size)
encodeCSVChar(s, value, size);
s.append("\"");
return s;
if (!rawCSVCol)
return encodedCSV;
encodedCSV.ensureCapacity(size+2); // Minimum size that will be written
encodedCSV.append("\"");
for (size32_t i = 0; i < size; i++)
encodeCSVChar(encodedCSV, rawCSVCol[i]);
encodedCSV.append("\"");
return encodedCSV;
}

StringBuffer &encodeCSV(StringBuffer &s, const char *value)
StringBuffer & encodeCSVColumn(StringBuffer & encodedCSV, const char *rawCSVCol)
{
if (!value)
return s;
return encodeCSV(s, strlen(value), value);
if (!rawCSVCol)
return encodedCSV;
return encodeCSVColumn(encodedCSV, strlen(rawCSVCol), rawCSVCol);
}

bool checkUnicodeLiteral(char const * str, unsigned length, unsigned & ep, StringBuffer & msg)
Expand Down
5 changes: 4 additions & 1 deletion system/jlib/jstring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,10 @@ inline StringBuffer &delimitJSON(StringBuffer &s, bool addNewline=false, bool es
return s;
}

jlib_decl StringBuffer &encodeCSV(StringBuffer &s, const char *value);
/*
* Encodes a CSV column, not an entire CSV record
*/
jlib_decl StringBuffer &encodeCSVColumn(StringBuffer &s, const char *value);

jlib_decl StringBuffer &encodeJSON(StringBuffer &s, const char *value);
jlib_decl StringBuffer &encodeJSON(StringBuffer &s, unsigned len, const char *value);
Expand Down
Loading

0 comments on commit 4e8473f

Please sign in to comment.