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

FilterIncomingMetrics instead of ValidateIncomingMetrics? #48

Closed
Patrick2607 opened this issue May 2, 2023 · 5 comments
Closed

FilterIncomingMetrics instead of ValidateIncomingMetrics? #48

Patrick2607 opened this issue May 2, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@Patrick2607
Copy link
Contributor

Patrick2607 commented May 2, 2023

In src/SparkplugNet/Core/SparkplugBase.KnownMetricStorage.cs, there is the following piece of code that checks whether an incoming message ONLY contains the metrics that are known, else it will throw an exception.

public virtual void ValidateIncomingMetrics(IEnumerable<T> metrics)
{
    foreach (var metric in metrics.Where(metric => !this.ContainsKey(metric.Name)))
    {
        throw new Exception($"Metric {metric.Name} is an unknown metric.");
    }
}

However, in my case, I'm only interested in SOME tags that get send, and I want them to ignore the rest. For instance, let's say I'm interested in the following device metrics:

'temperature', DataType.Float
'enabled', DataType.Boolean

But the device sends the following data:

'temperature', DataType.Float
'pressure', DataType.Float
'count', DataType.Int32
'enabled', DataType.Boolean

Configuring the metrics with only the 'temperature' and 'enabled' will result in a thrown exception. This is unwanted behaviour from my side. Same goes for the Node, I am not interested in the Node data, however, when I don't add the metrics to the known list, it will throw an exception as well. I'd rather have them filtered; similarly to the FilterOutgoingMetrics function in SparkplugBase.KnownMetricStorage.cs. The following function solved my problem:

public virtual IEnumerable<T> FilterIncomingMetrics(IEnumerable<T> metrics)
    => metrics.Where(metric => this.ContainsKey(metric.Name));

Is there a specific reason an exception is thrown in this case? If so, how would I be able to resolve this issue? If not, shall I create a pull request that has an option to validate or filter the incoming metrics?

@SeppPenner SeppPenner self-assigned this May 2, 2023
@SeppPenner SeppPenner added the question Further information is requested label May 2, 2023
@SeppPenner
Copy link
Owner

I need to check if this is possible. I'm still working on validating the V3 spec and fulfilling all requirements.

@Patrick2607
Copy link
Contributor Author

I thought I'd help out and created a possible solution (see #50)

@Patrick2607
Copy link
Contributor Author

I need to check if this is possible. I'm still working on validating the V3 spec and fulfilling all requirements.

Any update/news on the V3 spec?

@SeppPenner SeppPenner added the enhancement New feature or request label Mar 14, 2024
@SeppPenner
Copy link
Owner

I agree now, your proposal to filter the metrics makes more sense. I already work on this. I really try to provide that feature ASAP...

@SeppPenner
Copy link
Owner

Filtering is added, still need to do more tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants