Skip to content

Commit

Permalink
fix: Add type as label to histograms (#145)
Browse files Browse the repository at this point in the history
Co-authored-by: Trygve Lie <[email protected]>
  • Loading branch information
trygve-lie and Trygve Lie authored Jul 6, 2020
1 parent c698db8 commit a829a72
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 37 deletions.
9 changes: 5 additions & 4 deletions lib/handlers/alias.delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const AliasDel = class AliasDel {
'Histogram measuring time taken in @eik/core AliasDel handler method',
labels: {
success: true,
type: 'unknown',
},
buckets: [
0.005,
Expand Down Expand Up @@ -76,7 +77,7 @@ const AliasDel = class AliasDel {
if (!org) {
this._log.info(`alias:del - Hostname does not match a configured organization - ${url.hostname}`);
const e = new HttpError.InternalServerError();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand All @@ -87,7 +88,7 @@ const AliasDel = class AliasDel {
`alias:del - Alias does not exists - Org: ${org} - Type: ${type} - Name: ${name} - Alias: ${alias}`,
);
const e = new HttpError.NotFound();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand All @@ -102,7 +103,7 @@ const AliasDel = class AliasDel {
);
this._log.trace(error);
const e = new HttpError.BadGateway();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
return e;
}

Expand All @@ -114,7 +115,7 @@ const AliasDel = class AliasDel {
outgoing.cacheControl = this._cacheControl;
outgoing.statusCode = 204;

end({ labels: { status: outgoing.statusCode } });
end({ labels: { status: outgoing.statusCode, type } });

return outgoing;
}
Expand Down
9 changes: 5 additions & 4 deletions lib/handlers/alias.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const AliasGet = class AliasGet {
'Histogram measuring time taken in @eik/core AliasGet handler method',
labels: {
success: true,
type: 'unknown',
},
buckets: [
0.005,
Expand Down Expand Up @@ -60,7 +61,7 @@ const AliasGet = class AliasGet {
} catch (error) {
this._log.debug(`alias:get - Validation failed - ${error.message}`);
const e = new HttpError.NotFound();
end({ labels: { success: false, status: 404 } });
end({ labels: { success: false, status: e.status } });
throw e;
}

Expand All @@ -70,7 +71,7 @@ const AliasGet = class AliasGet {
if (!org) {
this._log.info(`alias:get - Hostname does not match a configured organization - ${url.hostname}`);
const e = new HttpError.InternalServerError();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand All @@ -87,13 +88,13 @@ const AliasGet = class AliasGet {

this._log.debug(`alias:get - Alias found - Pathname: ${path}`);

end({ labels: { status: outgoing.statusCode } });
end({ labels: { status: outgoing.statusCode, type } });

return outgoing;
} catch (error) {
this._log.debug(`alias:get - Alias not found - Pathname: ${path}`);
const e = new HttpError.NotFound();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}
}
Expand Down
7 changes: 4 additions & 3 deletions lib/handlers/alias.post.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const AliasPost = class AliasPost {
'Histogram measuring time taken in @eik/core AliasPost handler method',
labels: {
success: true,
type: 'unknown',
},
buckets: [
0.005,
Expand Down Expand Up @@ -136,7 +137,7 @@ const AliasPost = class AliasPost {
if (!org) {
this._log.info(`alias:post - Hostname does not match a configured organization - ${url.hostname}`);
const e = new HttpError.InternalServerError();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand All @@ -156,7 +157,7 @@ const AliasPost = class AliasPost {
`alias:post - Alias does not exists - Org: ${org} - Type: ${type} - Name: ${name} - Alias: ${alias}`,
);
const e = new HttpError.NotFound();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand All @@ -167,7 +168,7 @@ const AliasPost = class AliasPost {
outgoing.statusCode = 303;
outgoing.location = createURIToAlias(incoming);

end({ labels: { status: outgoing.statusCode } });
end({ labels: { status: outgoing.statusCode, type } });

return outgoing;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/handlers/alias.put.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const AliasPut = class AliasPut {
'Histogram measuring time taken in @eik/core AliasPut handler method',
labels: {
success: true,
type: 'unknown',
},
buckets: [
0.005,
Expand Down Expand Up @@ -135,7 +136,7 @@ const AliasPut = class AliasPut {
if (!org) {
this._log.info(`alias:put - Hostname does not match a configured organization - ${url.hostname}`);
const e = new HttpError.InternalServerError();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand All @@ -155,7 +156,7 @@ const AliasPut = class AliasPut {
`alias:put - Alias exists - Org: ${org} - Type: ${type} - Name: ${name} - Alias: ${alias}`,
);
const e = new HttpError.Conflict();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand All @@ -166,7 +167,7 @@ const AliasPut = class AliasPut {
outgoing.statusCode = 303;
outgoing.location = createURIToAlias(incoming);

end({ labels: { status: outgoing.statusCode } });
end({ labels: { status: outgoing.statusCode, type } });

return outgoing;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/handlers/auth.post.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const AuthPost = class AuthPost {
'Histogram measuring time taken in @eik/core AuthPost handler method',
labels: {
success: true,
type: 'unknown',
},
buckets: [
0.005,
Expand Down Expand Up @@ -86,7 +87,7 @@ const AuthPost = class AuthPost {
if (!org) {
this._log.info(`auth:post - Hostname does not match a configured organization - ${url.hostname}`);
const e = new HttpError.InternalServerError();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type: 'auth' } });
throw e;
}

Expand All @@ -102,7 +103,7 @@ const AuthPost = class AuthPost {
outgoing.mimeType = 'application/json';
outgoing.body = obj;

end({ labels: { status: outgoing.statusCode } });
end({ labels: { status: outgoing.statusCode, type: 'auth' } });

return outgoing;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/handlers/map.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const MapGet = class MapGet {
'Histogram measuring time taken in @eik/core MapGet handler method',
labels: {
success: true,
type: 'unknown',
},
buckets: [
0.005,
Expand Down Expand Up @@ -69,7 +70,7 @@ const MapGet = class MapGet {
if (!org) {
this._log.info(`map:get - Hostname does not match a configured organization - ${url.hostname}`);
const e = new HttpError.InternalServerError();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type: 'map' } });
throw e;
}

Expand Down Expand Up @@ -98,15 +99,15 @@ const MapGet = class MapGet {

this._log.debug(`map:get - Import map found - Pathname: ${path}`);

end({ labels: { status: outgoing.statusCode } });
end({ labels: { status: outgoing.statusCode, type: 'map' } });

return outgoing;
} catch (error) {
this._log.debug(
`map:get - Import map not found - Pathname: ${path}`,
);
const e = new HttpError.NotFound();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type: 'map' } });
throw e;
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/handlers/map.put.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const MapPut = class MapPut {
'Histogram measuring time taken in @eik/core MapPut handler method',
labels: {
success: true,
type: 'unknown'
},
buckets: [
0.005,
Expand Down Expand Up @@ -187,7 +188,7 @@ const MapPut = class MapPut {
if (!org) {
this._log.info(`map:put - Hostname does not match a configured organization - ${url.hostname}`);
const e = new HttpError.InternalServerError();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type: 'map' } });
throw e;
}

Expand All @@ -208,7 +209,7 @@ const MapPut = class MapPut {
`map:put - Semver version is lower than previous version of the package - Org: ${org} - Name: ${name} - Version: ${version}`,
);
const e = new HttpError.Conflict();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type: 'map' } });
throw e;
}

Expand All @@ -219,7 +220,7 @@ const MapPut = class MapPut {
await this._writeVersions(incoming, versions);
} catch (error) {
const e = new HttpError.BadGateway();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type: 'map' } });
throw e;
}

Expand All @@ -228,7 +229,7 @@ const MapPut = class MapPut {
outgoing.statusCode = 303;
outgoing.location = createURIPathToImportMap(incoming);

end({ labels: { status: outgoing.statusCode } });
end({ labels: { status: outgoing.statusCode, type: 'map' } });

return outgoing;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/handlers/pkg.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const PkgGet = class PkgGet {
'Histogram measuring time taken in @eik/core PkgGet handler method',
labels: {
success: true,
type: 'unknown'
},
buckets: [
0.005,
Expand Down Expand Up @@ -72,7 +73,7 @@ const PkgGet = class PkgGet {
if (!org) {
this._log.info(`pkg:get - Hostname does not match a configured organization - ${url.hostname}`);
const e = new HttpError.InternalServerError();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand Down Expand Up @@ -109,13 +110,13 @@ const PkgGet = class PkgGet {

this._log.debug(`pkg:get - Asset found - Pathname: ${path}`);

end({ labels: { status: outgoing.statusCode } });
end({ labels: { status: outgoing.statusCode, type } });

return outgoing;
} catch (error) {
this._log.debug(`pkg:get - Asset not found - Pathname: ${path}`);
const e = new HttpError.NotFound();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/handlers/pkg.log.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const PkgLog = class PkgLog {
'Histogram measuring time taken in @eik/core PkgLog handler method',
labels: {
success: true,
type: 'unknown',
},
buckets: [
0.005,
Expand Down Expand Up @@ -59,7 +60,7 @@ const PkgLog = class PkgLog {
} catch (error) {
this._log.debug(`pkg:log - Validation failed - ${error.message}`);
const e = new HttpError.NotFound();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand All @@ -69,7 +70,7 @@ const PkgLog = class PkgLog {
if (!org) {
this._log.info(`pkg:log - Hostname does not match a configured organization - ${url.hostname}`);
const e = new HttpError.InternalServerError();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand Down Expand Up @@ -98,13 +99,13 @@ const PkgLog = class PkgLog {

this._log.debug(`pkg:log - Package log found - Pathname: ${path}`);

end({ labels: { status: outgoing.statusCode } });
end({ labels: { status: outgoing.statusCode, type } });

return outgoing;
} catch (error) {
this._log.debug(`pkg:log - Package log found - Pathname: ${path}`);
const e = new HttpError.NotFound();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/handlers/pkg.put.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const PkgPut = class PkgPut {
'Histogram measuring time taken in @eik/core PkgPut handler method',
labels: {
success: true,
type: 'unknown',
},
buckets: [
0.005,
Expand Down Expand Up @@ -148,7 +149,7 @@ const PkgPut = class PkgPut {
if (!org) {
this._log.info(`pkg:put - Hostname does not match a configured organization - ${url.hostname}`);
const e = new HttpError.InternalServerError();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand All @@ -169,7 +170,7 @@ const PkgPut = class PkgPut {
`pkg:put - Semver version is lower than previous version of the package - Org: ${org} - Type: ${type} - Name: ${name} - Version: ${version}`,
);
const e = new HttpError.Conflict();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand All @@ -180,7 +181,7 @@ const PkgPut = class PkgPut {
await this._writeVersions(incoming, versions);
} catch (error) {
const e = new HttpError.BadGateway();
end({ labels: { success: false, status: e.status } });
end({ labels: { success: false, status: e.status, type } });
throw e;
}

Expand All @@ -189,7 +190,7 @@ const PkgPut = class PkgPut {
outgoing.statusCode = 303;
outgoing.location = createURIPathToPkgLog(pkg);

end({ labels: { status: outgoing.statusCode } });
end({ labels: { status: outgoing.statusCode, type } });

return outgoing;
}
Expand Down
Loading

0 comments on commit a829a72

Please sign in to comment.