Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Add support for datadog as a metric source (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
gempesaw authored Apr 20, 2021
1 parent a8ddc72 commit 247d0c6
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Referee currently supports
- New Relic Insights
- Prometheus
- SignalFx
- Datadog

To add a new integration you must implement the [MetricSourceIntegration](/packages/client/src/metricSources/MetricSourceIntegration.ts) interface and then add it to the [enabled metric sources](/packages/client/src/metricSources/index.tsx).

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CanaryMetricSetQueryConfig } from '../../domain/Kayenta';

/**
* {@see: https://github.com/spinnaker/kayenta/blob/master/kayenta-datadog/src/main/java/com/netflix/kayenta/canary/providers/metrics/DatadogCanaryMetricSetQueryConfig.java}
*/
export default interface DatadogCanaryMetricSetQueryConfig extends CanaryMetricSetQueryConfig {
customInlineTemplate: string
}
41 changes: 41 additions & 0 deletions packages/client/src/metricSources/Datadog/DatadogMetricModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as React from 'react';
import { AbstractMetricModal } from '../../components/config/AbstractMetricModal';
import { DATADOG_SERVICE_TYPE } from './index';
import { InlineTextGroup } from '../../layout/InlineTextGroup';
import { validateCanaryMetricConfig } from '../../validation/configValidators';
import { CanaryMetricConfig } from '../../domain/Kayenta';
import { ValidationResultsWrapper } from '../../domain/Referee';
import DatadogCanaryMetricSetQueryConfig from './DatadogCanaryMetricSetQueryConfig';

export default class DatadogMetricModal extends AbstractMetricModal<DatadogCanaryMetricSetQueryConfig> {
validateCanaryMetricConfig(existingMetric: CanaryMetricConfig, type: string): ValidationResultsWrapper {
return validateCanaryMetricConfig(existingMetric, type, true);
}

getQueryInitialState(): DatadogCanaryMetricSetQueryConfig {
return {
type: DATADOG_SERVICE_TYPE,
customInlineTemplate: '',
};
}

getMetricSourceSpecificJsx(): JSX.Element {
return (
<div>
<InlineTextGroup
onBlur={() => {
this.touch('customInlineTemplate');
}}
touched={this.state.touched.customInlineTemplate}
error={this.state.errors['query.customInlineTemplate']}
id="customInlineTemplate"
label="Datadog Query"
value={this.state.metric.query.customInlineTemplate}
onChange={e => this.updateQueryObject('customInlineTemplate', e.target.value)}
placeHolderText="sum:requests.error{${scope}}.as_count() / sum:requests.total{${scope}}.as_count()"
subText="Custom datadog query; use ${scope} as a placeholder for your tags."
/>
</div>
);
}
}
24 changes: 24 additions & 0 deletions packages/client/src/metricSources/Datadog/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import { MetricSourceIntegration } from '../MetricSourceIntegration';
import { MetricModalProps } from '../../components/config/AbstractMetricModal';
import DatadogMetricModal from './DatadogMetricModal';
import DatadogCanaryMetricSetQueryConfig from './DatadogCanaryMetricSetQueryConfig';
import { string } from 'yup';

export const DATADOG_SERVICE_TYPE: string = 'datadog';

const schema = {
customInlineTemplate: string()
.trim()
.required()
};

const modalFactory = (props: MetricModalProps) => React.createElement(DatadogMetricModal, props);

const Datadog: MetricSourceIntegration<DatadogCanaryMetricSetQueryConfig> = {
type: DATADOG_SERVICE_TYPE,
createMetricsModal: modalFactory,
canaryMetricSetQueryConfigSchema: schema
};

export default Datadog;
4 changes: 3 additions & 1 deletion packages/client/src/metricSources/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MetricSourceIntegration } from './MetricSourceIntegration';
import NewRelic from './NewRelic';
import SignalFx from './SignalFx';
import Prometheus from './Prometheus';
import Datadog from './Datadog';

const MIN_TO_MS_CONVERSION: number = 60000;
/**
Expand All @@ -12,7 +13,8 @@ const MIN_TO_MS_CONVERSION: number = 60000;
const enabledMetricSources: MetricSourceIntegration<CanaryMetricSetQueryConfig>[] = [
NewRelic,
SignalFx,
Prometheus
Prometheus,
Datadog
];

/**
Expand Down

0 comments on commit 247d0c6

Please sign in to comment.