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

Addition of fixed visualizations and speedy upload-objects #107

Merged
merged 53 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ae379c7
testing out this visualization
JasonTheMain Nov 7, 2024
b232f99
don't need a filter
JasonTheMain Nov 8, 2024
73096a1
testing out a more simple visualization
JasonTheMain Nov 12, 2024
2ffeecd
attempt at a generate-ndjson
JasonTheMain Nov 12, 2024
a2fb0cb
need to make file python
JasonTheMain Nov 12, 2024
e99f523
forgot an s
JasonTheMain Nov 12, 2024
5b88e5b
forgot an s
JasonTheMain Nov 12, 2024
d1c3a0c
learning python
JasonTheMain Nov 12, 2024
9533bf4
one file
JasonTheMain Nov 12, 2024
04fb7fb
i don't know if this will work
JasonTheMain Nov 12, 2024
a3e00a6
python fix
JasonTheMain Nov 12, 2024
386a069
updating python file
JasonTheMain Nov 12, 2024
198280e
figuring out python one step at a time
JasonTheMain Nov 12, 2024
f58854d
changing upload sending
JasonTheMain Nov 12, 2024
e73ef36
fix what they expect us to send
JasonTheMain Nov 12, 2024
2ad1238
not flattening
JasonTheMain Nov 12, 2024
9aac58d
changing order
JasonTheMain Nov 12, 2024
924cb0c
typo
JasonTheMain Nov 12, 2024
8e24821
typo
JasonTheMain Nov 12, 2024
27f73bb
typo
JasonTheMain Nov 12, 2024
77605c5
maybe will fix issue
JasonTheMain Nov 12, 2024
0b37e4c
updating searches
JasonTheMain Nov 12, 2024
6f1ec55
removing
JasonTheMain Nov 12, 2024
16544d6
only search
JasonTheMain Nov 12, 2024
ffda88a
only search
JasonTheMain Nov 12, 2024
a31660b
better errors
JasonTheMain Nov 12, 2024
7b56d7e
better errors
JasonTheMain Nov 12, 2024
bd05526
attempting encoding
JasonTheMain Nov 13, 2024
c6e0bf4
trying to force my encoding
JasonTheMain Nov 13, 2024
7c481bb
trying to force my encoding
JasonTheMain Nov 13, 2024
7bd6923
adding title and attempt at using multiline
JasonTheMain Nov 13, 2024
92b4917
trying again
JasonTheMain Nov 13, 2024
2786c18
Merge pull request #105 from cloud-gov/main
JasonTheMain Nov 13, 2024
e25849c
Merge pull request #106 from cloud-gov/main
JasonTheMain Nov 13, 2024
219c158
visualization update
JasonTheMain Nov 13, 2024
566c837
Merge branch 'opensearch_18' of https://github.com/cloud-gov/opensear…
JasonTheMain Nov 13, 2024
36416c4
trying to fix file
JasonTheMain Nov 13, 2024
7d995ca
fixing a comma
JasonTheMain Nov 13, 2024
70b9f7b
trying to make work
JasonTheMain Nov 13, 2024
ac5ce8f
ruby and json
JasonTheMain Nov 13, 2024
5c29370
ruby
JasonTheMain Nov 13, 2024
997cc43
ruby
JasonTheMain Nov 13, 2024
a52b259
ruby
JasonTheMain Nov 13, 2024
fc604d2
ruby
JasonTheMain Nov 13, 2024
bd9731b
hopefully quick fix
JasonTheMain Nov 13, 2024
4153010
next json file
JasonTheMain Nov 13, 2024
926e379
next json file
JasonTheMain Nov 13, 2024
3343099
adding in missing
JasonTheMain Nov 13, 2024
e498e9c
updating with dashboard to finish
JasonTheMain Nov 14, 2024
1a7359d
adding removed files
JasonTheMain Nov 14, 2024
d029908
adding back in
JasonTheMain Nov 14, 2024
f810f53
Update jobs/upload-dashboards-objects/templates/bin/import-objects
JasonTheMain Nov 14, 2024
dbacad2
Apply suggestions from code review
JasonTheMain Nov 14, 2024
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
1 change: 1 addition & 0 deletions jobs/upload-dashboards-objects/spec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ consumes:
templates:
bin/generate-objects: bin/generate-objects
bin/generate-tenants: bin/generate-tenants
bin/generate-ndjson: bin/generate-ndjson
bin/import-objects: bin/import-objects
bin/run: bin/run
bin/pre-start.erb: bin/pre-start
Expand Down
32 changes: 32 additions & 0 deletions jobs/upload-dashboards-objects/templates/bin/generate-ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/var/vcap/packages/python3-requests/venv/bin/python3
import os
import json

folders = [
"/var/vcap/jobs/upload-dashboards-objects/dashboards-objects/dashboard",
"/var/vcap/jobs/upload-dashboards-objects/dashboards-objects/search",
"/var/vcap/jobs/upload-dashboards-objects/dashboards-objects/visualization"
]
output_file = "/var/vcap/jobs/upload-dashboards-objects/dashboard.ndjson"


with open(output_file, 'w', encoding='utf-8') as output:
for folder in folders:
if not os.path.exists(folder):
print(f"Folder not found: {folder}")
continue
for files in os.listdir(folder):
if files.endswith(".json"):
filepath = os.path.join(folder,files)

with open(filepath, 'r') as json_file:
try:
data = json.load(json_file)
except json.JSONDecodeError as e:
print(f"Error with file {files}: {e}")
continue

json.dump(data,output)
output.write("\n")


85 changes: 50 additions & 35 deletions jobs/upload-dashboards-objects/templates/bin/import-objects
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ logging.basicConfig(level=logging.INFO)

if __name__ == "__main__":
session = requests.Session()

ndjson_output_path = "/var/vcap/jobs/upload-dashboards-objects/dashboard.ndjson"
# set CA
ca = '<%= job_dir %>/config/ssl/opensearch.ca'
cert = '<%= job_dir %>/config/ssl/dashboard-web.crt'
Expand All @@ -26,57 +26,72 @@ if __name__ == "__main__":
with open('<%= store_dir %>/org-tenants.txt') as orgs:
for tenant in orgs:
headers = {
'content-type': 'application/json',
'osd-xsrf': 'true',
'x-proxy-roles': 'admin',
'x-proxy-user': 'admin',
'x-forwarded-for': '127.0.0.1',
'securitytenant': tenant.strip(),
'securitytenant': tenant.strip()
}

<% p("dashboards_objects.upload_patterns").each do |pattern| %>
for filename in glob.iglob("<%= pattern.fetch("pattern") %>", recursive=True):
r = session.post(
'{}/api/saved_objects/{}/{}'.format(
logs_url,
os.path.basename(os.path.dirname(filename)),
os.path.basename(os.path.splitext(filename)[0])
with open(ndjson_output_path, 'rb') as ndjson_file:
ndjson_files= {'file':(ndjson_output_path, ndjson_file, 'application/x-ndjson')}
r = session.post(
'{}/api/saved_objects/_import?overwrite=true'.format(
logs_url
),
files=ndjson_files,
headers=headers,
cert=(cert, key),
verify=ca
)
if r.status_code == 200:
logging.info(f'NDJSON FILE {ndjson_output_path} uploaded sucessfully')
elif r.status_code == 409:
put = session.put(
'{}/api/saved_objects/_import?overwrite=true'.format(
logs_url
),
data=open(filename, 'rb'),
headers=headers,
cert=(cert, key),
verify=ca
data=ndjson_file,
headers=headers,
cert=(cert, key),
verify=ca
)
if r.status_code == 409:
put = session.put(
'{}/api/saved_objects/{}/{}'.format(
logs_url,
os.path.basename(os.path.dirname(filename)),
os.path.basename(os.path.splitext(filename)[0])
),
data=open(filename, 'rb'),
headers=headers,
cert=(cert, key),
verify=ca
)
if put.status_code == 200:
logging.info('Object %s Uploaded Successfully', filename)
else:
logging.info('Object %s Failed to Upload', filename)
elif r.status_code == 200:
logging.info('Object %s Uploaded Successfully', filename)
if put.status_code == 200:
logging.info(f'NDJSON FILE {ndjson_output_path} uploaded successfully')
else:
logging.info('Object %s Failed to Upload', filename)
<% end %>
logging.error(f"Failed to upload file {ndjson_output_path}, status code: {put.status_code}")
try:
error_response = put.json()
logging.error(f"Error detils: {error_response}")
except ValueError:
logging.error(f"raw response: {put.text}")
logging.info(f'Failed to upload NDJSON FILE {ndjson_output_path}')
else:
logging.error(f"Failed to upload file {ndjson_output_path}, status code: {r.status_code}")
try:
error_response = r.json()
logging.error(f"Error detils: {error_response}")
except ValueError:
logging.error(f"raw response: {r.text}")
logging.info(f'Failed to upload NDJSON FILE {ndjson_output_path}')

index_headers = {
'content-type': 'application/json',
'osd-xsrf': 'true',
'x-proxy-roles': 'admin',
'x-proxy-user': 'admin',
'x-forwarded-for': '127.0.0.1',
'securitytenant': tenant.strip(),
}
r = session.post(
'{}/api/opensearch-dashboards/settings'.format(logs_url),
data='{"changes":{"defaultIndex":"<%= p('dashboards_objects.default_index') %>"}}',
headers=headers,
headers=index_headers,
cert=(cert, key),
verify=ca
)
if r.status_code == 200:
logging.info('Successfully Set <%= p('dashboards_objects.default_index') %> as Default Index')
else:
logging.info('Failed to Set <%= p('dashboards_objects.default_index') %> as Default Index')

6 changes: 6 additions & 0 deletions jobs/upload-dashboards-objects/templates/bin/pre-start.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ export JOB_DIR=/var/vcap/jobs/$JOB_NAME
if [ -d ${JOB_DIR}/config/ssl ]; then
chown -R vcap:vcap ${JOB_DIR}/config/ssl
fi

export PATH=/var/vcap/packages/python3/bin:$PATH
export PYTHONPATH="/var/vcap/packages/python3/lib/python3.12/site-packages${PYTHONPATH:+:$PYTHONPATH}"
export LD_LIBRARY_PATH="/var/vcap/packages/python3/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

$(dirname $0)/generate-ndjson
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ ENDOFFJSON
%>"
}
},
"type": "dashboard",
"title": "App Errors",
"id": "App-Errors",
"references": [
{
"id": "App-errors-count-in-timeline-(top-5-apps)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ ENDOFFJSON
%>"
}
},
"type": "dashboard",
"title": "App Location",
"id": "App-Location",
"references": [
{
"id": "App-RTR-requests-map",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ ENDOFFJSON
%>"
}
},
"type": "dashboard",
"title": "App Logs",
"id": "App-Logs",
"references": [
{
"id": "App-logs-count-by-source-type-(APP-or-cf-top-5-apps)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ ENDOFFJSON
%>"
}
},
"type": "dashboard",
"title": "App Metrics",
"id": "App-Metrics",
"references": [
{
"id": "App-METRIC-memory-usage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ ENDOFFJSON
%>"
}
},
"type": "dashboard",
"title": "App Overview",
"id": "App-Overview",
"references": [
{
"id": "App-links",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ ENDOFFJSON
%>"
}
},
"type": "dashboard",
"title": "App Performance",
"id": "App-Performance",
"references": [
{
"id": "App-RTR-request-count-(top-10-apps)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
).to_json.gsub(/"/) { '\"' }
%>"
}
}
},
"id": "app-all-errors",
"references": [],
"title": "[app] All - ERRORs",
"type": "search"
}
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"index": "#{p('opensearch_config.app_index_prefix')}*",
"filter": [

],
"highlight": {
"pre_tags": [
Expand All @@ -30,7 +30,7 @@
],
"fields": {
"*": {

}
},
"require_field_match": false,
Expand All @@ -46,5 +46,9 @@
).to_json.gsub(/"/) { '\"' }
%>"
}
}
},
"id": "app-all-messages",
"title": "[app] All Messages",
"references": [],
"type": "search"
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
).to_json.gsub(/"/) { '\"' }
%>"
}
}
},
"id": "app-all-overview",
"references": [],
"title": "[app] All Overview",
"type": "search"
}
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
).to_json.gsub(/"/) { '\"' }
%>"
}
}
},
"id": "app-all",
"references": [],
"title": "[app] All",
"type": "search"
}
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
).to_json.gsub(/"/) { '\"' }
%>"
}
}
},
"id": "app-container-metric-cpu",
"references": [],
"title": "[app] Container Metric cpu",
"type": "search"
}
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
).to_json.gsub(/"/) { '\"' }
%>"
}
}
},
"id": "app-container-metric-disk",
"references": [],
"title": "[app] Container Metric disk",
"type": "search"
}
<% end %>
Loading