Skip to content

Commit 2015b28

Browse files
authored
Merge pull request #26 from oslabs-beta/dev-copy
updated server.js and corrected Chronos constructor errors
2 parents 9581786 + 4a951ea commit 2015b28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1609
-9835
lines changed

chronos_npm_package/chronos.ts

Lines changed: 0 additions & 371 deletions
Original file line numberDiff line numberDiff line change
@@ -1,375 +1,4 @@
1-
// // import hpropagate from 'hpropagate';
2-
// // import postgres from './controllers/postgres';
3-
// // import mongo from './controllers/mongo';
4-
// // import MongoClientWrapper from './wrappers/MongoClientWrapper';
5-
// // import MongoServerWrapper from './wrappers/MongoServerWrapper';
6-
// // import PostgresClientWrapper from './wrappers/PostgresClientWrapper';
7-
// // import PostgresServerWrapper from './wrappers/PostgresServerWrapper';
8-
// // import utilities from './controllers/utilities';
9-
10-
// // /**
11-
// // * **********************************
12-
// // * CMD CONFIG FILE SETUP
13-
// // *
14-
// // * @field microservice {string} REQUIRED
15-
// // * The user specified name for the microservice being tracked
16-
// // *
17-
// // * @field interval {number} DEFAULT 60000
18-
// // * The interval for every microservice health check in milliseconds
19-
// // * This defaults to 60000 ms or 1 minute
20-
// // *
21-
// // * @field database {Object}
22-
// // * Takes two properties
23-
// // * - type {string} Either PostgreSQL or MongoDB
24-
// // * - URI {string} Database uri
25-
// // *
26-
// // * @field notifications {array} OPTIONAL
27-
// // * Varies per notification method
28-
// // * **********************************
29-
// // */
30-
31-
// // class Chronos {
32-
// // constructor(config) {
33-
// // if (config === undefined) {
34-
// // throw new Error('Chronos config is undefined');
35-
// // }
36-
37-
// // // Validate all input fields exist and setup notifications
38-
// // config = utilities.validateInput(config);
39-
// // config = utilities.addNotifications(config);
40-
// // this.config = config;
41-
// // }
42-
43-
// // propagate() {
44-
// // /**
45-
// // * Places an unique x-correlating-id into the headers of each request/response.
46-
// // * This is used for tracking the life cycle of the request until the response
47-
// // */
48-
// // hpropagate({ propagateInResponses: true });
49-
// // }
50-
51-
// // track() {
52-
// // /**
53-
// // * **********************************************
54-
// // * MAIN CONTROLLER
55-
// // * Only supports MongoDB and PostgreSQL for now!
56-
// // * **********************************************
57-
// // */
58-
// // const { database, dockerized } = this.config;
59-
60-
// // /**
61-
// // * If the provided database is Mongo
62-
// // * - Connection is made to MongoDB via the provided URI by the user.
63-
// // *
64-
// // * - 'services' collection will be created if not already and stores every microservice
65-
// // * that is apart of the application.
66-
// // *
67-
// // * - Information is collected if the microservice is containerized
68-
// // *
69-
// // * - 'communications' collection will be created which creates a new document for every
70-
// // * endpoint that the user Request travels through (tracked with hpropograte) for express routes
71-
// // */
72-
// // if (database.type === 'MongoDB') {
73-
// // //mongo is referring to controller function defined locally, not the actual mongodb object
74-
// // mongo.connect(this.config);
75-
// // mongo.services(this.config);
76-
// // dockerized ? mongo.docker(this.config) : mongo.health(this.config);
77-
78-
// // if (database.connection === 'REST') {
79-
// // return mongo.communications(this.config);
80-
// // }
81-
// // } else if (database.type === 'PostgreSQL') {
82-
// // /**
83-
// // * If the provided database is PostgreSQL
84-
// // * - Connection is made to the postgres client via the provided URI by the user.
85-
// // *
86-
// // * - 'services' table will be created if not already and stores every microservice
87-
// // * that is apart of the application.
88-
// // *
89-
// // * - Information is collected if the microservice is containerized
90-
// // *
91-
// // * - 'communications' table will be created which creates a new row entry for every
92-
// // * endpoint that the user Request travels through (tracked with hpropograte)
93-
// // */
94-
// // postgres.connect(this.config);
95-
// // postgres.services(this.config);
96-
// // dockerized ? postgres.docker(this.config) : postgres.health(this.config);
97-
// // if (database.connection === 'REST') {
98-
// // return postgres.communications(this.config);
99-
// // }
100-
// // } else {
101-
// // throw new Error('The only allowed database types are MongoDB and PostgreSQL');
102-
// // }
103-
// // }
104-
105-
// // async kafka() {
106-
// // // Test metrics server connection
107-
// // await utilities.testMetricsQuery(this.config);
108-
109-
// // if (this.config.database.type === 'MongoDB') {
110-
// // mongo.connect(this.config);
111-
// // mongo.serverQuery(this.config);
112-
// // }
113-
114-
// // else if (this.config.database.type === 'PostgreSQL') {
115-
// // postgres.connect(this.config);
116-
// // postgres.serverQuery(this.config);
117-
// // } else {
118-
// // throw new Error('The only allowed database types are MongoDB and PostgreSQL');
119-
// // }
120-
// // }
121-
122-
// // async kubernetes() {
123-
// // // Test metrics server connection
124-
// // await utilities.testMetricsQuery(this.config);
125-
126-
// // if (this.config.database.type === 'MongoDB') {
127-
// // await mongo.connect(this.config);
128-
// // await mongo.storeGrafanaAPIKey(this.config);
129-
// // //await mongo.createGrafanaDashboards(this.config);
130-
// // mongo.serverQuery(this.config);
131-
// // // return mongo.modifyMetrics(this.config);
132-
// // }
133-
134-
// // else if (this.config.database.type === 'PostgreSQL') {
135-
// // postgres.connect(this.config);
136-
// // postgres.serverQuery(this.config);
137-
// // } else {
138-
// // throw new Error('The only allowed database types are MongoDB and PostgreSQL');
139-
// // }
140-
// // }
141-
142-
// // async docker () {
143-
// // await utilities.testMetricsQuery(this.config);
144-
// // if (this.config.database.type === 'MongoDB') {
145-
// // await mongo.connect(this.config);
146-
// // await mongo.storeGrafanaAPIKey(this.config);
147-
// // mongo.serverQuery(this.config);
148-
// // // return mongo.modifyMetrics(this.config);
149-
// // } else if (this.config.database.type === 'PostgreSQL') {
150-
// // postgres.connect(this.config);
151-
// // postgres.serverQuery(this.config);
152-
// // } else {
153-
// // throw new Error('The only allowed database types are MongoDB and PostgreSQL');
154-
// // }
155-
// // }
156-
157-
// // ServerWrapper(server, proto, methods) {
158-
// // /**
159-
// // * Wraps the gRPC server object to automatically write logs to provided DB
160-
// // * @param {*} server
161-
// // * @param {*} proto
162-
// // * @param {*} methods
163-
// // */
164-
// // const { database } = this.config;
165-
// // if (database.type === 'MongoDB') {
166-
// // return new MongoServerWrapper(server, proto, methods, this.config);
167-
// // }
168-
// // if (database.type === 'PostgreSQL') {
169-
// // return new PostgresServerWrapper(server, proto, methods, this.config);
170-
// // }
171-
// // return null;
172-
// // }
173-
174-
// // ClientWrapper(client, service) {
175-
// // /**
176-
// // * Wraps the gRPC client to automatically write logs to provided DB
177-
// // *
178-
// // * @param {*} client
179-
// // * @param {*} service
180-
// // */
181-
// // const { database } = this.config;
182-
// // if (database.type === 'MongoDB') {
183-
// // return new MongoClientWrapper(client, service, this.config);
184-
// // }
185-
// // if (database.type === 'PostgreSQL') {
186-
// // return new PostgresClientWrapper(client, service, this.config);
187-
// // }
188-
// // return null;
189-
// // }
190-
191-
// // link(client, server) {
192-
// // /**
193-
// // * Allows the passthrough of metadata from gRPC server to gRPC client
194-
// // *
195-
// // * @param {*} client
196-
// // * @param {*} servere
197-
// // */
198-
// // client.metadata = server.metadataHolder;
199-
// // }
200-
// // }
201-
202-
// // export default Chronos;
203-
// // chronos.ts
204-
205-
// import hpropagate from 'hpropagate';
206-
// import postgres from './controllers/postgres';
207-
// import mongo from './controllers/mongo';
208-
// import MongoClientWrapper from './wrappers/MongoClientWrapper';
209-
// import MongoServerWrapper from './wrappers/MongoServerWrapper';
210-
// import PostgresClientWrapper from './wrappers/PostgresClientWrapper';
211-
// import PostgresServerWrapper from './wrappers/PostgresServerWrapper';
212-
// import utilities from './controllers/utilities';
213-
214-
// // Optional: Define interfaces for your configuration.
215-
// interface DatabaseConfig {
216-
// type: 'MongoDB' | 'PostgreSQL';
217-
// URI: string;
218-
// connection?: string;
219-
// }
220-
221-
// interface ChronosConfig {
222-
// microservice: string;
223-
// interval: number;
224-
// dockerized?: boolean;
225-
// database: DatabaseConfig;
226-
// notifications?: any; // Update this type as needed.
227-
// }
228-
229-
// class Chronos {
230-
// public config: ChronosConfig;
231-
232-
// constructor(config: ChronosConfig) {
233-
// if (!config) {
234-
// throw new Error('Chronos config is undefined');
235-
// }
236-
// // Validate all input fields exist and setup notifications.
237-
// config = utilities.validateInput(config);
238-
// config = utilities.addNotifications(config);
239-
// this.config = config;
240-
// }
241-
242-
// /**
243-
// * Inserts a unique x-correlating-id into the headers of each request/response.
244-
// */
245-
// propagate(): void {
246-
// hpropagate({ propagateInResponses: true });
247-
// }
248-
249-
// /**
250-
// * Main controller for tracking the microservice.
251-
// */
252-
// track(): any {
253-
// const { database, dockerized } = this.config;
254-
255-
// if (database.type === 'MongoDB') {
256-
// mongo.connect(this.config);
257-
// mongo.services(this.config);
258-
// dockerized ? mongo.docker(this.config) : mongo.health(this.config);
259-
260-
// if (database.connection === 'REST') {
261-
// return mongo.communications(this.config);
262-
// }
263-
// } else if (database.type === 'PostgreSQL') {
264-
// postgres.connect(this.config);
265-
// postgres.services(this.config);
266-
// dockerized ? postgres.docker(this.config) : postgres.health(this.config);
267-
268-
// if (database.connection === 'REST') {
269-
// return postgres.communications(this.config);
270-
// }
271-
// } else {
272-
// throw new Error('The only allowed database types are MongoDB and PostgreSQL');
273-
// }
274-
// }
275-
276-
// /**
277-
// * Kafka-related tasks.
278-
// */
279-
// async kafka(): Promise<void> {
280-
// // If testMetricsQuery is nested under helpers, use utilities.helpers.testMetricsQuery.
281-
// await utilities.helpers.testMetricsQuery(this.config);
282-
283-
// if (this.config.database.type === 'MongoDB') {
284-
// mongo.connect(this.config);
285-
// mongo.serverQuery(this.config);
286-
// } else if (this.config.database.type === 'PostgreSQL') {
287-
// postgres.connect(this.config);
288-
// postgres.serverQuery(this.config);
289-
// } else {
290-
// throw new Error('The only allowed database types are MongoDB and PostgreSQL');
291-
// }
292-
// }
293-
294-
// /**
295-
// * Kubernetes-related tasks.
296-
// */
297-
// async kubernetes(): Promise<void> {
298-
// await utilities.helpers.testMetricsQuery(this.config);
299-
300-
// if (this.config.database.type === 'MongoDB') {
301-
// await mongo.connect(this.config);
302-
// await mongo.storeGrafanaAPIKey(this.config);
303-
// mongo.serverQuery(this.config);
304-
// } else if (this.config.database.type === 'PostgreSQL') {
305-
// postgres.connect(this.config);
306-
// postgres.serverQuery(this.config);
307-
// } else {
308-
// throw new Error('The only allowed database types are MongoDB and PostgreSQL');
309-
// }
310-
// }
311-
312-
// /**
313-
// * Docker-related tasks.
314-
// */
315-
// async docker(): Promise<void> {
316-
// await utilities.helpers.testMetricsQuery(this.config);
317-
318-
// if (this.config.database.type === 'MongoDB') {
319-
// await mongo.connect(this.config);
320-
// await mongo.storeGrafanaAPIKey(this.config);
321-
// mongo.serverQuery(this.config);
322-
// } else if (this.config.database.type === 'PostgreSQL') {
323-
// postgres.connect(this.config);
324-
// postgres.serverQuery(this.config);
325-
// } else {
326-
// throw new Error('The only allowed database types are MongoDB and PostgreSQL');
327-
// }
328-
// }
329-
330-
// /**
331-
// * Wraps the gRPC server to automatically write logs to the provided DB.
332-
// */
333-
// ServerWrapper(server: any, proto: any, methods: any): MongoServerWrapper | PostgresServerWrapper | null {
334-
// const { database } = this.config;
335-
// if (database.type === 'MongoDB') {
336-
// return new MongoServerWrapper(server, proto, methods, this.config);
337-
// }
338-
// if (database.type === 'PostgreSQL') {
339-
// return new PostgresServerWrapper(server, proto, methods, this.config);
340-
// }
341-
// return null;
342-
// }
343-
344-
// /**
345-
// * Wraps the gRPC client to automatically write logs to the provided DB.
346-
// */
347-
// ClientWrapper(client: any, service: any): MongoClientWrapper | PostgresClientWrapper | null {
348-
// const { database } = this.config;
349-
// if (database.type === 'MongoDB') {
350-
// return new MongoClientWrapper(client, service, this.config);
351-
// }
352-
// if (database.type === 'PostgreSQL') {
353-
// return new PostgresClientWrapper(client, service, this.config);
354-
// }
355-
// return null;
356-
// }
357-
358-
// /**
359-
// * Links gRPC client and server metadata.
360-
// */
361-
// link(client: any, server: any): void {
362-
// client.metadata = server.metadataHolder;
363-
// }
364-
// }
365-
366-
// export default Chronos;
367-
// chronos.ts
368-
369-
//
3701
import hpropagate from 'hpropagate';
371-
372-
3732
import postgres from './controllers/postgres.js';
3743
import mongo from './controllers/mongo.js';
3754
import MongoClientWrapper from './wrappers/MongoClientWrapper.js';

0 commit comments

Comments
 (0)