Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Exporter/Prometheus: Enforce strictNullChecks and noUnusedLocals (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored Mar 13, 2019
1 parent 5dfea38 commit 096eb70
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
2 changes: 0 additions & 2 deletions examples/stats/exporter/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ lineReader.on('line', function (line) {

globalStats.record([{
measure: mLineLengths,
tags,
value: processedLine.length
}], tags);

globalStats.record([{
measure: mLatencyMs,
tags,
value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
}], tags);
} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/opencensus-core/src/stats/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export interface View {
* Returns a snapshot of an AggregationData for that tags/labels values.
* @param tagValues The desired data's tag values.
*/
getSnapshot(tagValues: TagValue[]): AggregationData;
getSnapshot(tagValues: Array<TagValue|null>): AggregationData;
/** Gets the view's tag keys */
getColumns(): TagKey[];
/** Gets view`s metric */
Expand Down
2 changes: 1 addition & 1 deletion packages/opencensus-core/src/stats/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class BaseView implements View {
* @param tags The desired data's tags
* @returns {AggregationData}
*/
getSnapshot(tagValues: TagValue[]): AggregationData {
getSnapshot(tagValues: Array<TagValue|null>): AggregationData {
return this.tagValueAggregationMap[this.encodeTagValues(tagValues)];
}

Expand Down
6 changes: 4 additions & 2 deletions packages/opencensus-exporter-prometheus/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# OpenCensus Prometheus Exporter for Node.js
# OpenCensus Prometheus Stats Exporter
[![Gitter chat][gitter-image]][gitter-url] ![Node Version][node-img] [![NPM Published Version][npm-img]][npm-url] ![dependencies Status][dependencies-status] ![devDependencies Status][devdependencies-status] ![Apache License][license-image]

The OpenCensus Prometheus Exporter allows the user to send collected stats with [OpenCensus Core](https://github.com/census-instrumentation/opencensus-core) to Prometheus.
The OpenCensus Prometheus Stats Exporter allows the user to send collected stats with [OpenCensus Core](https://github.com/census-instrumentation/opencensus-core) to Prometheus.

[Prometheus](https://prometheus.io/) is a monitoring system that collects metrics, by scraping exposed endpoints at regular intervals, evaluating rule expressions. It can also trigger alerts if certain conditions are met. For assistance setting up Prometheus, [Click here](https://opencensus.io/codelabs/prometheus/#0) for a guided codelab.

This package is still at an early stage of development, and is subject to change.

Expand Down
10 changes: 6 additions & 4 deletions packages/opencensus-exporter-prometheus/src/prometheus-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class PrometheusStatsExporter implements StatsEventListener {
private prefix: string;
private port: number;
private app = express();
private server: http.Server;
private server?: http.Server;
// Registry instance from Prometheus to keep the metrics
private registry = new Registry();

Expand Down Expand Up @@ -105,7 +105,10 @@ export class PrometheusStatsExporter implements StatsEventListener {
const labels: labelValues = {};
columns.forEach((tagKey) => {
if (tags.has(tagKey)) {
labels[tagKey.name] = tags.get(tagKey).value;
const tagValue = tags.get(tagKey);
if (tagValue) {
labels[tagKey.name] = tagValue.value;
}
}
});
return labels;
Expand Down Expand Up @@ -149,8 +152,7 @@ export class PrometheusStatsExporter implements StatsEventListener {
metric = new Histogram(distribution);
break;
default:
this.logger.error('Aggregation %s is not supported', view.aggregation);
return null;
this.logger.error(`Aggregation ${view.aggregation} is not supported`);
}

this.registry.registerMetric(metric);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import {AggregationType, globalStats, Measure, MeasureUnit, TagMap} from '@opencensus/core';
import * as assert from 'assert';
import * as http from 'http';

import {PrometheusStatsExporter} from '../src/';

describe('Prometheus Stats Exporter', () => {
Expand Down Expand Up @@ -48,7 +47,7 @@ describe('Prometheus Stats Exporter', () => {
it('should create a count aggregation', (done) => {
const view = globalStats.createView(
'ocnodemetrics/countview', measure, AggregationType.COUNT, tagKeys,
'A count aggregation example', null);
'A count aggregation example');
const measurement = {measure, value: 2};
const measurement2 = {measure, value: 3};
globalStats.registerView(view);
Expand All @@ -75,7 +74,7 @@ describe('Prometheus Stats Exporter', () => {
globalStats.createMeasureDouble('testMeasureDouble', MeasureUnit.UNIT);
const view = globalStats.createView(
'ocnodemetrics/sumview', measure, AggregationType.SUM, tagKeys,
'A sum aggregation example', null);
'A sum aggregation example');
const measurement = {measure, value: 2};
const measurement2 = {measure, value: 3};
globalStats.registerView(view);
Expand All @@ -102,7 +101,7 @@ describe('Prometheus Stats Exporter', () => {
globalStats.createMeasureDouble('testMeasureDouble', MeasureUnit.UNIT);
const view = globalStats.createView(
'ocnodemetrics/sumview1', measure, AggregationType.SUM, tagKeys,
'A sum aggregation example', null);
'A sum aggregation example');
const measurement = {measure, value: 2};
const measurement2 = {measure, value: 3};
globalStats.registerView(view);
Expand All @@ -128,7 +127,7 @@ describe('Prometheus Stats Exporter', () => {
globalStats.createMeasureDouble('testMeasureDouble', MeasureUnit.UNIT);
const view = globalStats.createView(
'ocnodemetrics/lastvalueview', measure, AggregationType.LAST_VALUE,
tagKeys, 'A last value aggregation example', null);
tagKeys, 'A last value aggregation example');
const measurement = {measure, value: 2};
const measurement2 = {measure, value: 3};
globalStats.registerView(view);
Expand Down Expand Up @@ -247,7 +246,7 @@ describe('Prometheus Stats Exporter with prefix option', () => {
it('should create a count aggregation with le labels', (done) => {
const view = globalStats.createView(
'test/key-1', measure, AggregationType.COUNT, tagKeys,
'A count aggregation example', null);
'A count aggregation example');
const measurement = {measure, value: 2};
const measurement2 = {measure, value: 3};
globalStats.registerView(view);
Expand Down
3 changes: 2 additions & 1 deletion packages/opencensus-exporter-prometheus/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"pretty": true,
"module": "commonjs",
"target": "es6",
"strictNullChecks": false
"strictNullChecks": true,
"noUnusedLocals": true
},
"exclude": [
"node_modules"
Expand Down

0 comments on commit 096eb70

Please sign in to comment.