-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored PrometheusMetric to Metric
- Loading branch information
Jaakko Heusala
committed
Jan 22, 2024
1 parent
466f6cc
commit 3c6c623
Showing
7 changed files
with
187 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2024. Sendanor <info@sendanor.fi>. All rights reserved. | ||
|
||
import { Entity } from "../entities/types/Entity"; | ||
import { ReadonlyJsonObject } from "../Json"; | ||
import { MetricDTO } from "./MetricDTO"; | ||
import { PrometheusMetricEntity } from "./PrometheusMetricEntity"; | ||
import { MetricCollectionDTO } from "./MetricCollectionDTO"; | ||
|
||
/** | ||
* Presents an interface for SeoEntity. | ||
*/ | ||
export interface MetricCollection extends Entity<MetricCollectionDTO> { | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
valueOf () : ReadonlyJsonObject; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
getDTO () : MetricCollectionDTO; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
toJSON () : ReadonlyJsonObject; | ||
|
||
/** | ||
* Returns CSS styles. | ||
*/ | ||
getCssStyles () : ReadonlyJsonObject; | ||
|
||
|
||
/** | ||
* Get a payload. | ||
*/ | ||
getPayload () : readonly PrometheusMetricEntity[]; | ||
|
||
/** | ||
* Get a payload as DTO. | ||
*/ | ||
getPayloadDTO () : readonly MetricDTO[]; | ||
|
||
/** | ||
* Set a payload. | ||
* | ||
* @param payload | ||
*/ | ||
setPayload (payload : readonly ( MetricDTO | PrometheusMetricEntity )[]) : this; | ||
|
||
/** | ||
* Set a payload. | ||
* | ||
* An alias for `.setPayload(payload)`. | ||
* | ||
* @param payload | ||
*/ | ||
payload (payload : readonly (MetricDTO | PrometheusMetricEntity)[]) : this; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright (c) 2024. Sendanor <info@sendanor.fi>. All rights reserved. | ||
|
||
import { MetricDTO } from "./MetricDTO"; | ||
|
||
export interface MetricCollectionDTO { | ||
readonly payload: readonly MetricDTO[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) 2024. Sendanor <info@sendanor.fi>. All rights reserved. | ||
|
||
import { EntityFactoryImpl } from "../entities/types/EntityFactoryImpl"; | ||
import { VariableType } from "../entities/types/VariableType"; | ||
import { PrometheusMetricEntity } from "./PrometheusMetricEntity"; | ||
import { MetricCollection } from "./MetricCollection"; | ||
import { MetricCollectionDTO } from "./MetricCollectionDTO"; | ||
|
||
export const MetricCollectionEntityFactory = ( | ||
EntityFactoryImpl.create<MetricCollectionDTO, MetricCollection>('MetricCollection') | ||
.add( EntityFactoryImpl.createArrayProperty("payload").setTypes(PrometheusMetricEntity) ) | ||
); | ||
|
||
export const isMetricCollectionDTO = MetricCollectionEntityFactory.createTestFunctionOfDTO(); | ||
|
||
export const isMetricCollection = MetricCollectionEntityFactory.createTestFunctionOfInterface(); | ||
|
||
export const explainMetricCollectionDTO = MetricCollectionEntityFactory.createExplainFunctionOfDTO(); | ||
|
||
export const isMetricCollectionDTOOrUndefined = MetricCollectionEntityFactory.createTestFunctionOfDTOorOneOf(VariableType.UNDEFINED); | ||
|
||
export const explainMetricCollectionDTOOrUndefined = MetricCollectionEntityFactory.createExplainFunctionOfDTOorOneOf(VariableType.UNDEFINED); | ||
|
||
export const BaseMetricCollectionEntity = MetricCollectionEntityFactory.createEntityType(); | ||
|
||
/** | ||
* Metric Collection entity. | ||
*/ | ||
export class MetricCollectionEntity | ||
extends BaseMetricCollectionEntity | ||
implements MetricCollection | ||
{ | ||
|
||
/** | ||
* Creates a Metric Collection entity. | ||
* | ||
* @param value The optional DTO of Metric Collection | ||
*/ | ||
public static create ( | ||
value ?: MetricCollectionDTO, | ||
) : MetricCollectionEntity { | ||
return new MetricCollectionEntity(value); | ||
} | ||
|
||
/** | ||
* Creates a Metric Collection entity from DTO. | ||
* | ||
* @param dto The optional DTO of Metric Collection | ||
*/ | ||
public static createFromDTO ( | ||
dto : MetricCollectionDTO, | ||
) : MetricCollectionEntity { | ||
return new MetricCollectionEntity(dto); | ||
} | ||
|
||
/** | ||
* Normalizes the value as a DTO. | ||
*/ | ||
public static toDTO ( | ||
value: MetricCollectionDTO | MetricCollection | MetricCollectionEntity, | ||
) : MetricCollectionDTO { | ||
if (isMetricCollectionEntity(value)) { | ||
return value.getDTO(); | ||
} else if (isMetricCollection(value)) { | ||
return value.getDTO(); | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
/** | ||
* Construct an entity of MetricCollectionEntity. | ||
*/ | ||
public constructor ( | ||
dto ?: MetricCollectionDTO | undefined, | ||
) { | ||
super(dto); | ||
} | ||
|
||
} | ||
|
||
export function isMetricCollectionEntity ( value: unknown): value is MetricCollectionEntity { | ||
return value instanceof MetricCollectionEntity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
// Copyright (c) 2024. Sendanor <info@sendanor.fi>. All rights reserved. | ||
|
||
import { ReadonlyJsonObject } from "../Json"; | ||
import { PrometheusMetricType } from "./types/PrometheusMetricType"; | ||
import { MetricType } from "./types/MetricType"; | ||
|
||
export interface PrometheusMetricDTO { | ||
export interface MetricDTO { | ||
readonly name ?: string; | ||
readonly help ?: string; | ||
readonly type ?: PrometheusMetricType; | ||
readonly type ?: MetricType; | ||
readonly labels ?: ReadonlyJsonObject; | ||
readonly value ?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters