@promster/apollo 1.0.0 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  import { createPlugin, signalIsUp, signalIsNotUp } from './plugin';
2
- import { getSummary, getContentType, Prometheus, defaultRegister, defaultNormalizers } from '@promster/metrics';
3
- export { createPlugin, signalIsUp, signalIsNotUp, getSummary, getContentType, Prometheus, defaultRegister, defaultNormalizers, };
2
+ import { getSummary, getContentType, Prometheus, defaultRegister, defaultNormalizers, timing } from '@promster/metrics';
3
+ export { createPlugin, signalIsUp, signalIsNotUp, getSummary, getContentType, Prometheus, defaultRegister, defaultNormalizers, timing, };
@@ -76,20 +76,23 @@ const createPlugin = ({
76
76
  },
77
77
 
78
78
  async requestDidStart() {
79
- const requestStart = process.hrtime();
79
+ const requestTiming = metrics.timing.start();
80
80
  return {
81
81
  async parsingDidStart(parsingRequestContext) {
82
- const parseStart = process.hrtime();
82
+ const parseTiming = metrics.timing.start();
83
83
  return async error => {
84
- var _graphQlMetrics$graph;
85
-
86
84
  const {
87
- durationS
88
- } = metrics.endMeasurementFrom(parseStart);
85
+ seconds: parseDurationSeconds
86
+ } = parseTiming.end().value();
89
87
  const labels = getDefaultLabelsOrSkipMeasurement(parsingRequestContext);
90
- (_graphQlMetrics$graph = graphQlMetrics.graphQlParseDuration) === null || _graphQlMetrics$graph === void 0 ? void 0 : _graphQlMetrics$graph.forEach(metric => {
91
- metric.observe(labels, durationS);
92
- });
88
+
89
+ if (parseDurationSeconds !== undefined) {
90
+ var _graphQlMetrics$graph;
91
+
92
+ (_graphQlMetrics$graph = graphQlMetrics.graphQlParseDuration) === null || _graphQlMetrics$graph === void 0 ? void 0 : _graphQlMetrics$graph.forEach(metric => {
93
+ metric.observe(labels, parseDurationSeconds);
94
+ });
95
+ }
93
96
 
94
97
  if (error) {
95
98
  var _graphQlMetrics$graph2;
@@ -104,17 +107,20 @@ const createPlugin = ({
104
107
  },
105
108
 
106
109
  async validationDidStart(validationRequestContext) {
107
- const validationStart = process.hrtime();
110
+ const validationTiming = metrics.timing.start();
108
111
  return async error => {
109
- var _graphQlMetrics$graph3;
110
-
111
112
  const {
112
- durationS
113
- } = metrics.endMeasurementFrom(validationStart);
113
+ seconds: validationDurationSeconds
114
+ } = validationTiming.end().value();
114
115
  const labels = getDefaultLabelsOrSkipMeasurement(validationRequestContext);
115
- (_graphQlMetrics$graph3 = graphQlMetrics.graphQlValidationDuration) === null || _graphQlMetrics$graph3 === void 0 ? void 0 : _graphQlMetrics$graph3.forEach(metric => {
116
- metric.observe(labels, durationS);
117
- });
116
+
117
+ if (validationDurationSeconds !== undefined) {
118
+ var _graphQlMetrics$graph3;
119
+
120
+ (_graphQlMetrics$graph3 = graphQlMetrics.graphQlValidationDuration) === null || _graphQlMetrics$graph3 === void 0 ? void 0 : _graphQlMetrics$graph3.forEach(metric => {
121
+ metric.observe(labels, validationDurationSeconds);
122
+ });
123
+ }
118
124
 
119
125
  if (error) {
120
126
  var _graphQlMetrics$graph4;
@@ -133,20 +139,23 @@ const createPlugin = ({
133
139
  willResolveField({
134
140
  info
135
141
  }) {
136
- const fieldResolveStart = process.hrtime();
142
+ const fieldResolveTiming = metrics.timing.start();
137
143
  return error => {
138
- var _graphQlMetrics$graph5;
139
-
140
144
  const {
141
- durationS
142
- } = metrics.endMeasurementFrom(fieldResolveStart);
145
+ seconds: fieldResolveDurationSeconds
146
+ } = fieldResolveTiming.end().value();
143
147
  const defaultLabels = getDefaultLabelsOrSkipMeasurement(executionRequestContext);
144
148
  const labels = Object.assign({}, defaultLabels, {
145
149
  field_name: info.fieldName
146
150
  });
147
- (_graphQlMetrics$graph5 = graphQlMetrics.graphQlResolveFieldDuration) === null || _graphQlMetrics$graph5 === void 0 ? void 0 : _graphQlMetrics$graph5.forEach(metric => {
148
- metric.observe(labels, durationS);
149
- });
151
+
152
+ if (fieldResolveDurationSeconds !== undefined) {
153
+ var _graphQlMetrics$graph5;
154
+
155
+ (_graphQlMetrics$graph5 = graphQlMetrics.graphQlResolveFieldDuration) === null || _graphQlMetrics$graph5 === void 0 ? void 0 : _graphQlMetrics$graph5.forEach(metric => {
156
+ metric.observe(labels, fieldResolveDurationSeconds);
157
+ });
158
+ }
150
159
 
151
160
  if (error) {
152
161
  var _graphQlMetrics$graph6;
@@ -164,15 +173,18 @@ const createPlugin = ({
164
173
  },
165
174
 
166
175
  async willSendResponse(responseRequestContext) {
167
- var _graphQlMetrics$graph7;
168
-
169
176
  const {
170
- durationS
171
- } = metrics.endMeasurementFrom(requestStart);
177
+ seconds: requestDurationSeconds
178
+ } = requestTiming.end().value();
172
179
  const labels = getDefaultLabelsOrSkipMeasurement(responseRequestContext);
173
- (_graphQlMetrics$graph7 = graphQlMetrics.graphQlRequestDuration) === null || _graphQlMetrics$graph7 === void 0 ? void 0 : _graphQlMetrics$graph7.forEach(metric => {
174
- metric.observe(labels, durationS);
175
- });
180
+
181
+ if (requestDurationSeconds !== undefined) {
182
+ var _graphQlMetrics$graph7;
183
+
184
+ (_graphQlMetrics$graph7 = graphQlMetrics.graphQlRequestDuration) === null || _graphQlMetrics$graph7 === void 0 ? void 0 : _graphQlMetrics$graph7.forEach(metric => {
185
+ metric.observe(labels, requestDurationSeconds);
186
+ });
187
+ }
176
188
  }
177
189
 
178
190
  };
@@ -202,6 +214,10 @@ Object.defineProperty(exports, 'getSummary', {
202
214
  enumerable: true,
203
215
  get: function () { return metrics.getSummary; }
204
216
  });
217
+ Object.defineProperty(exports, 'timing', {
218
+ enumerable: true,
219
+ get: function () { return metrics.timing; }
220
+ });
205
221
  exports.createPlugin = createPlugin;
206
222
  exports.signalIsNotUp = signalIsNotUp;
207
223
  exports.signalIsUp = signalIsUp;
@@ -76,20 +76,23 @@ const createPlugin = ({
76
76
  },
77
77
 
78
78
  async requestDidStart() {
79
- const requestStart = process.hrtime();
79
+ const requestTiming = metrics.timing.start();
80
80
  return {
81
81
  async parsingDidStart(parsingRequestContext) {
82
- const parseStart = process.hrtime();
82
+ const parseTiming = metrics.timing.start();
83
83
  return async error => {
84
- var _graphQlMetrics$graph;
85
-
86
84
  const {
87
- durationS
88
- } = metrics.endMeasurementFrom(parseStart);
85
+ seconds: parseDurationSeconds
86
+ } = parseTiming.end().value();
89
87
  const labels = getDefaultLabelsOrSkipMeasurement(parsingRequestContext);
90
- (_graphQlMetrics$graph = graphQlMetrics.graphQlParseDuration) === null || _graphQlMetrics$graph === void 0 ? void 0 : _graphQlMetrics$graph.forEach(metric => {
91
- metric.observe(labels, durationS);
92
- });
88
+
89
+ if (parseDurationSeconds !== undefined) {
90
+ var _graphQlMetrics$graph;
91
+
92
+ (_graphQlMetrics$graph = graphQlMetrics.graphQlParseDuration) === null || _graphQlMetrics$graph === void 0 ? void 0 : _graphQlMetrics$graph.forEach(metric => {
93
+ metric.observe(labels, parseDurationSeconds);
94
+ });
95
+ }
93
96
 
94
97
  if (error) {
95
98
  var _graphQlMetrics$graph2;
@@ -104,17 +107,20 @@ const createPlugin = ({
104
107
  },
105
108
 
106
109
  async validationDidStart(validationRequestContext) {
107
- const validationStart = process.hrtime();
110
+ const validationTiming = metrics.timing.start();
108
111
  return async error => {
109
- var _graphQlMetrics$graph3;
110
-
111
112
  const {
112
- durationS
113
- } = metrics.endMeasurementFrom(validationStart);
113
+ seconds: validationDurationSeconds
114
+ } = validationTiming.end().value();
114
115
  const labels = getDefaultLabelsOrSkipMeasurement(validationRequestContext);
115
- (_graphQlMetrics$graph3 = graphQlMetrics.graphQlValidationDuration) === null || _graphQlMetrics$graph3 === void 0 ? void 0 : _graphQlMetrics$graph3.forEach(metric => {
116
- metric.observe(labels, durationS);
117
- });
116
+
117
+ if (validationDurationSeconds !== undefined) {
118
+ var _graphQlMetrics$graph3;
119
+
120
+ (_graphQlMetrics$graph3 = graphQlMetrics.graphQlValidationDuration) === null || _graphQlMetrics$graph3 === void 0 ? void 0 : _graphQlMetrics$graph3.forEach(metric => {
121
+ metric.observe(labels, validationDurationSeconds);
122
+ });
123
+ }
118
124
 
119
125
  if (error) {
120
126
  var _graphQlMetrics$graph4;
@@ -133,20 +139,23 @@ const createPlugin = ({
133
139
  willResolveField({
134
140
  info
135
141
  }) {
136
- const fieldResolveStart = process.hrtime();
142
+ const fieldResolveTiming = metrics.timing.start();
137
143
  return error => {
138
- var _graphQlMetrics$graph5;
139
-
140
144
  const {
141
- durationS
142
- } = metrics.endMeasurementFrom(fieldResolveStart);
145
+ seconds: fieldResolveDurationSeconds
146
+ } = fieldResolveTiming.end().value();
143
147
  const defaultLabels = getDefaultLabelsOrSkipMeasurement(executionRequestContext);
144
148
  const labels = Object.assign({}, defaultLabels, {
145
149
  field_name: info.fieldName
146
150
  });
147
- (_graphQlMetrics$graph5 = graphQlMetrics.graphQlResolveFieldDuration) === null || _graphQlMetrics$graph5 === void 0 ? void 0 : _graphQlMetrics$graph5.forEach(metric => {
148
- metric.observe(labels, durationS);
149
- });
151
+
152
+ if (fieldResolveDurationSeconds !== undefined) {
153
+ var _graphQlMetrics$graph5;
154
+
155
+ (_graphQlMetrics$graph5 = graphQlMetrics.graphQlResolveFieldDuration) === null || _graphQlMetrics$graph5 === void 0 ? void 0 : _graphQlMetrics$graph5.forEach(metric => {
156
+ metric.observe(labels, fieldResolveDurationSeconds);
157
+ });
158
+ }
150
159
 
151
160
  if (error) {
152
161
  var _graphQlMetrics$graph6;
@@ -164,15 +173,18 @@ const createPlugin = ({
164
173
  },
165
174
 
166
175
  async willSendResponse(responseRequestContext) {
167
- var _graphQlMetrics$graph7;
168
-
169
176
  const {
170
- durationS
171
- } = metrics.endMeasurementFrom(requestStart);
177
+ seconds: requestDurationSeconds
178
+ } = requestTiming.end().value();
172
179
  const labels = getDefaultLabelsOrSkipMeasurement(responseRequestContext);
173
- (_graphQlMetrics$graph7 = graphQlMetrics.graphQlRequestDuration) === null || _graphQlMetrics$graph7 === void 0 ? void 0 : _graphQlMetrics$graph7.forEach(metric => {
174
- metric.observe(labels, durationS);
175
- });
180
+
181
+ if (requestDurationSeconds !== undefined) {
182
+ var _graphQlMetrics$graph7;
183
+
184
+ (_graphQlMetrics$graph7 = graphQlMetrics.graphQlRequestDuration) === null || _graphQlMetrics$graph7 === void 0 ? void 0 : _graphQlMetrics$graph7.forEach(metric => {
185
+ metric.observe(labels, requestDurationSeconds);
186
+ });
187
+ }
176
188
  }
177
189
 
178
190
  };
@@ -202,6 +214,10 @@ Object.defineProperty(exports, 'getSummary', {
202
214
  enumerable: true,
203
215
  get: function () { return metrics.getSummary; }
204
216
  });
217
+ Object.defineProperty(exports, 'timing', {
218
+ enumerable: true,
219
+ get: function () { return metrics.timing; }
220
+ });
205
221
  exports.createPlugin = createPlugin;
206
222
  exports.signalIsNotUp = signalIsNotUp;
207
223
  exports.signalIsUp = signalIsUp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promster/apollo",
3
- "version": "1.0.0",
3
+ "version": "1.0.4",
4
4
  "description": "Apollo server integrations of promster",
5
5
  "main": "dist/promster-apollo.cjs.js",
6
6
  "typings": "dist/promster-apollo.cjs.d.ts",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "repository": {
23
23
  "type": "git",
24
- "url": "https://github.com/tdeekens/flopflip.git",
24
+ "url": "https://github.com/tdeekens/promster.git",
25
25
  "directory": "packages/apollo"
26
26
  },
27
27
  "author": "Tobias Deekens <nerd@tdeekens.name>",
@@ -36,15 +36,15 @@
36
36
  "prometheus"
37
37
  ],
38
38
  "dependencies": {
39
- "@promster/metrics": "^9.0.0",
40
- "apollo-server-plugin-base": "3.4.0",
39
+ "@promster/metrics": "^9.1.3",
40
+ "apollo-server-plugin-base": "3.5.1",
41
41
  "merge-options": "3.0.4",
42
42
  "tslib": "2.3.1"
43
43
  },
44
44
  "devDependencies": {
45
- "apollo-server": "3.5.0",
46
- "graphql": "16.0.1",
47
- "node-fetch": "2.6.6",
45
+ "apollo-server": "3.6.2",
46
+ "graphql": "16.2.0",
47
+ "node-fetch": "2.6.7",
48
48
  "parse-prometheus-text-format": "1.1.1"
49
49
  }
50
50
  }