Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow duplicate dimension sets #31

Closed
markkuhn opened this issue Aug 12, 2022 · 1 comment · Fixed by #32
Closed

Disallow duplicate dimension sets #31

markkuhn opened this issue Aug 12, 2022 · 1 comment · Fixed by #32
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@markkuhn
Copy link
Contributor

Related issues:

Currently duplicate dimension set are being allowed:
Example:

var ds1 = new DimensionSet();
ds1.AddDimension("Region", "us-west-1");
var ds2 = new DimensionSet();
ds2.AddDimension("Region", "us-west-2");

metrics.SetDimensions(ds1);
metrics.PutDimensions(ds2);

metrics.PutMetric("Metric1", 1.0);
metrics.Flush();

This creates

{
  "_aws": {
    "Timestamp": 1660330702000,
    "CloudWatchMetrics": [
      {
        "Namespace": "aws-embedded-metrics",
        "Metrics": [
          {
            "Name": "Metric1",
            "Unit": "None"
          }
        ],
        "Dimensions": [
          [
            "Region"
          ],
          [
            "Region"
          ]
        ]
      }
    ],
    "LogGroupName": "DemoApp"
  },
  "Region": "us-west-1",
  "LogGroupName": "DemoApp",
  "Metric1": 1
}

Instead of:

{
  "_aws": {
    "Timestamp": 1660330702000,
    "CloudWatchMetrics": [
      {
        "Namespace": "aws-embedded-metrics",
        "Metrics": [
          {
            "Name": "Metric1",
            "Unit": "None"
          }
        ],
        "Dimensions": [
          [
            "Region"
          ]
        ]
      }
    ],
    "LogGroupName": "DemoApp"
  },
  "Region": "us-west-2",
  "LogGroupName": "DemoApp",
  "Metric1": 1
}
@gordonpn
Copy link
Member

gordonpn commented Aug 12, 2022

Ran two tests:

Test 1:

private static void EmitMetric(ILogger logger, IMetricsLogger metrics)
{


    var ds1 = new DimensionSet();
    ds1.AddDimension("D1", "d1.1");
    var ds2 = new DimensionSet();
    ds2.AddDimension("D1", "d1.2");

    var ds3 = new DimensionSet();
    ds3.AddDimension("D3", "d3.1");
    ds3.AddDimension("D4", "d4.1");

    var ds4 = new DimensionSet();
    ds4.AddDimension("D3", "d3.2");
    ds4.AddDimension("D4", "d4.2");

    metrics.PutDimensions(ds1); // only this line is different
    metrics.PutDimensions(ds2);
    metrics.PutDimensions(ds3);
    metrics.PutDimensions(ds4);

    metrics.PutMetric("Metric1", 1.0);

    metrics.Flush();
}

Test 2:

private static void EmitMetric(ILogger logger, IMetricsLogger metrics)
{


    var ds1 = new DimensionSet();
    ds1.AddDimension("D1", "d1.1");
    var ds2 = new DimensionSet();
    ds2.AddDimension("D1", "d1.2");

    var ds3 = new DimensionSet();
    ds3.AddDimension("D3", "d3.1");
    ds3.AddDimension("D4", "d4.1");

    var ds4 = new DimensionSet();
    ds4.AddDimension("D3", "d3.2");
    ds4.AddDimension("D4", "d4.2");

    metrics.SetDimensions(ds1); // only this line is different
    metrics.PutDimensions(ds2);
    metrics.PutDimensions(ds3);
    metrics.PutDimensions(ds4);

    metrics.PutMetric("Metric1", 1.0);

    metrics.Flush();
}

Output of test 1:

{
  "_aws": {
    "Timestamp": 1660331033988,
    "CloudWatchMetrics": [
      {
        "Namespace": "aws-embedded-metrics",
        "Metrics": [
          {
            "Name": "Metric1",
            "Unit": "None"
          }
        ],
        "Dimensions": [
          [
            "ServiceName",
            "ServiceType",
            "D1",
            "D3",
            "D4"
          ]
        ]
      }
    ],
    "LogGroupName": "DemoApp"
  },
  "ServiceName": "DemoApp",
  "ServiceType": "ConsoleApp",
  "D1": "d1.2",
  "D3": "d3.2",
  "D4": "d4.2",
  "LogGroupName": "DemoApp",
  "Metric1": 1
}

Output of test 2:

{
  "_aws": {
    "Timestamp": 1660331043355,
    "CloudWatchMetrics": [
      {
        "Namespace": "aws-embedded-metrics",
        "Metrics": [
          {
            "Name": "Metric1",
            "Unit": "None"
          }
        ],
        "Dimensions": [
          [
            "D1"
          ],
          [
            "D1"
          ],
          [
            "D3",
            "D4"
          ],
          [
            "D3",
            "D4"
          ]
        ]
      }
    ],
    "LogGroupName": "DemoApp"
  },
  "D1": "d1.1",
  "D3": "d3.1",
  "D4": "d4.1",
  "LogGroupName": "DemoApp",
  "Metric1": 1
}

It seems like when SetDimensions is called first, there is a bug that allows duplicates and does not record the values of the most recent key inserted.

@markkuhn markkuhn self-assigned this Aug 12, 2022
markkuhn added a commit to markkuhn/aws-embedded-metrics-dotnet that referenced this issue Aug 15, 2022
markkuhn added a commit to markkuhn/aws-embedded-metrics-dotnet that referenced this issue Aug 17, 2022
markkuhn added a commit to markkuhn/aws-embedded-metrics-dotnet that referenced this issue Sep 15, 2022
@markkuhn markkuhn linked a pull request Sep 15, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants