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

feature/APPEALS-26109 #19382

Merged
merged 18 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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 app/controllers/metrics/v2/logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def create
if (metric.metric_type === 'error')
error_info = {
name: metric.metric_name,
message: metric.metric_message,
class: metric.metric_class,
attrs: metric.metric_attributes,
created_at: metric.created_at,
Expand Down
2 changes: 1 addition & 1 deletion app/models/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def css_id
def self.default_object(klass, params, user)
{
uuid: params[:uuid],
user: user || User.new(full_name: "Stand in user for testing", css_id: SecureRandom.uuid, station_id: 'Metrics'),
user: user || RequestStore.store[:current_user] || User.system_user,
metric_name: params[:name] || METRIC_TYPES[:log],
metric_class: klass&.try(:name) || klass&.class.name || self.name,
metric_group: params[:group] || METRIC_GROUPS[:service],
Expand Down
2 changes: 1 addition & 1 deletion app/services/metrics_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# see https://dropwizard.github.io/metrics/3.1.0/getting-started/ for abstractions on metric types
class MetricsService
def self.record(description, service: nil, name: "unknown", caller: nil)
return nil unless FeatureToggle.enabled?(:metrics_monitoring, user: current_user)

return_value = nil
app = RequestStore[:application] || "other"
Expand Down Expand Up @@ -106,6 +105,7 @@ def self.record(description, service: nil, name: "unknown", caller: nil)
private

def self.store_record_metric(uuid, params, caller)
return nil unless FeatureToggle.enabled?(:metrics_monitoring, user: RequestStore[:current_user])

name ="caseflow.server.metric.#{params[:name]&.downcase.gsub(/::/, '.')}"
params = {
Expand Down
9 changes: 7 additions & 2 deletions app/views/metrics/dashboard/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ body {
.inner_div {
max-height: 2000px;
overflow-y: auto;

/* ::-webkit-scrollbar {
transform: rotateX(180deg);
} */
Expand All @@ -22,8 +21,14 @@ body {
.metric_table {
transform: rotateX(180deg);
}

</style>

<script>
window.addEventListener('DOMContentLoaded', () => {
document.getElementsByClassName('metric_table')[0].scrollIntoView(false);
})
</script>

</head>
<h1>Metrics Dashboard</h1>
<h2>Shows metrics created in past hour</h2>
Expand Down
86 changes: 24 additions & 62 deletions client/app/reader/PdfFile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ export class PdfFile extends React.PureComponent {

this.props.clearDocumentLoadError(this.props.file);

if (this.props.featureToggles.readerGetDocumentLogging) {
return this.getDocumentWithLogging(requestOptions);
}

return this.getDocument(requestOptions);
}

Expand All @@ -71,6 +67,8 @@ export class PdfFile extends React.PureComponent {
* different domain (eFolder), and still need to pass our credentials to authenticate.
*/
getDocument = (requestOptions) => {
const logId = uuid.v4();

return ApiUtil.get(this.props.file, requestOptions).
then((resp) => {
const metricData = {
Expand All @@ -82,11 +80,28 @@ export class PdfFile extends React.PureComponent {
}
};

this.loadingTask = PDFJS.getDocument({ data: resp.body });
const promise = this.loadingTask.promise;
/* The feature toggle reader_get_document_logging adds the progress of the file being loaded in console */
if (this.props.featureToggles.readerGetDocumentLogging) {
const src = {
data: resp.body,
verbosity: 5,
stopAtErrors: false,
pdfBug: true,
};

this.loadingTask = PDFJS.getDocument(src);

this.loadingTask.onProgress = (progress) => {
// eslint-disable-next-line no-console
console.log(`${logId} : Progress of ${this.props.file} reached ${progress.loaded} / ${progress.total}`);
};
} else {
this.loadingTask = PDFJS.getDocument({ data: resp.body });
}

return recordAsyncMetrics(promise, metricData,
return recordAsyncMetrics(this.loadingTask.promise, metricData,
this.props.featureToggles.metricsRecordPDFJSGetDocument);

}, (reason) => this.onRejected(reason, 'getDocument')).
then((pdfDocument) => {
this.pdfDocument = pdfDocument;
Expand All @@ -104,15 +119,14 @@ export class PdfFile extends React.PureComponent {
return this.props.setPdfDocument(this.props.file, this.pdfDocument);
}, (reason) => this.onRejected(reason, 'setPdfDocument')).
catch((error) => {
const id = uuid.v4();
const data = {
file: this.props.file
};
const message = `${id} : GET ${this.props.file} : ${error}`;
const message = `${logId} : GET ${this.props.file} : ${error}`;

console.error(message);
storeMetrics(
id,
logId,
data,
{ message,
type: 'error',
Expand All @@ -124,58 +138,6 @@ export class PdfFile extends React.PureComponent {
});
}

/**
* This version of the method has additional logging and debugging configuration
* It is behind the feature toggle reader_get_document_logging
*
* We have to set withCredentials to true since we're requesting the file from a
* different domain (eFolder), and still need to pass our credentials to authenticate.
*/
getDocumentWithLogging = (requestOptions) => {
const logId = uuid.v4();

return ApiUtil.get(this.props.file, requestOptions).
then((resp) => {
const src = {
data: resp.body,
verbosity: 5,
stopAtErrors: false,
pdfBug: true,
};

this.loadingTask = PDFJS.getDocument(src);

this.loadingTask.onProgress = (progress) => {
// eslint-disable-next-line no-console
console.log(`${logId} : Progress of ${this.props.file} reached ${progress}`);
// eslint-disable-next-line no-console
console.log(`${logId} : Progress of ${this.props.file} reached ${progress.loaded} / ${progress.total}`);
};

return this.loadingTask.promise;
}, (reason) => this.onRejected(reason, 'getDocument')).
then((pdfDocument) => {
this.pdfDocument = pdfDocument;

return this.getPages(pdfDocument);
}, (reason) => this.onRejected(reason, 'getPages')).
then((pages) => this.setPageDimensions(pages)
, (reason) => this.onRejected(reason, 'setPageDimensions')).
then(() => {
if (this.loadingTask.destroyed) {
return this.pdfDocument.destroy();
}
this.loadingTask = null;

return this.props.setPdfDocument(this.props.file, this.pdfDocument);
}, (reason) => this.onRejected(reason, 'setPdfDocument')).
catch((error) => {
console.error(`${logId} : GET ${this.props.file} : ${error}`);
this.loadingTask = null;
this.props.setDocumentLoadError(this.props.file);
});
}

onRejected = (reason, step) => {
console.error(`${uuid.v4()} : GET ${this.props.file} : STEP ${step} : ${reason}`);
throw reason;
Expand Down
48 changes: 26 additions & 22 deletions client/app/reader/PdfPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { bindActionCreators } from 'redux';
import { PDF_PAGE_HEIGHT, PDF_PAGE_WIDTH, SEARCH_BAR_HEIGHT, PAGE_DIMENSION_SCALE, PAGE_MARGIN } from './constants';
import { pageNumberOfPageIndex } from './utils';
import * as PDFJS from 'pdfjs-dist';
import { collectHistogram, recordMetrics, recordAsyncMetrics, storeMetrics } from '../util/Metrics';
import { recordMetrics, recordAsyncMetrics, storeMetrics } from '../util/Metrics';

import { css } from 'glamor';
import classNames from 'classnames';
Expand Down Expand Up @@ -225,16 +225,6 @@ export class PdfPage extends React.PureComponent {
},
};

const textMetricData = {
message: 'Storing PDF page text',
product: 'pdfjs.document.pages',
type: 'performance',
data: {
file: this.props.file,
documentId: this.props.documentId,
},
};

const pageAndTextFeatureToggle = this.props.featureToggles.metricsPdfStorePages;
const document = this.props.pdfDocument;
const pageIndex = pageNumberOfPageIndex(this.props.pageIndex);
Expand All @@ -243,6 +233,16 @@ export class PdfPage extends React.PureComponent {
pageResult.then((page) => {
this.page = page;

const textMetricData = {
message: 'Storing PDF page text',
product: 'pdfjs.document.pages',
type: 'performance',
data: {
file: this.props.file,
documentId: this.props.documentId,
},
};

const readerRenderText = {
uuid: uuidv4(),
message: 'Searching within Reader document text',
Expand All @@ -263,18 +263,22 @@ export class PdfPage extends React.PureComponent {
});

this.drawPage(page).then(() => {
collectHistogram({
group: 'front_end',
name: 'pdf_page_render_time_in_ms',
value: this.measureTimeStartMs ? performance.now() - this.measureTimeStartMs : 0,
appName: 'Reader',
attrs: {
documentId: this.props.documentId,
overscan: this.props.windowingOverscan,
documentType: this.props.documentType,
pageCount: this.props.pdfDocument.numPages
const data = {
overscan: this.props.windowingOverscan,
documentType: this.props.documentType,
pageCount: this.props.pdfDocument.numPages
};

storeMetrics(
this.props.documentId,
data,
{
message: 'pdf_page_render_time_in_ms',
type: 'performance',
product: 'reader',
start: this.measureTimeStartMs ? performance.now() - this.measureTimeStartMs : 0
}
});
);
});
}).catch((error) => {
const id = uuid.v4();
Expand Down
Loading