Skip to content

Conversation

@jpraychev
Copy link
Collaborator

What this PR does / why we need it:
The PR adds a new field to managed metrics CR called dimensions, the purpose of which is to allow users to define their own dimensions. The PR also removes the old logic that extract type and status from conditions array, because now users can pick the needed conditions that would like to see as dimensions.

Which issue(s) this PR fixes:
Fixes #49

Special notes for your reviewer:
No tests have been introduced with this PR as its purpose is to evaluate the dimension logic first.

Release note:

Copy link
Contributor

@christophrj christophrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jpraychev, thanks for your contribution 👍 I added a couple of comments. Since Metrics and FederatedMetrics both use projections, we should also update FederatedManagedMetrics if we add dimensions/projections to ManagedMetrics to keep things consistent. It feels a little bit like we reduce the value of a ManagedMetric by dropping the status conditions and letting the user defines this by themselves. When would I use a ManagedMetric over a Metric when they are essentially the same from a user perspective? Really interested in your thoughts regarding this.

@Hanni007112
Copy link

Hanni007112 commented Nov 21, 2025

Hello @christophrj and @jpraychev,

I’m currently testing the Metrics Operator for use in a production environment. As I understand it, the key difference is that a ManagedMetric automatically discovers and observes Crossplane-managed resources, whereas a Metric requires you to specify the exact Group/Version/Kind.

I want to track all managed resources across the clusters, including their namespace, name, and status conditions. In the future, I may also need a specific label/annotation, plus the timestamp and message from the status condition.
Right now, if I want to track all managed resources and also export these fields, I am forced to create many Metrics—each with its own GVK.

Allowing users to define their own projections (dimensions) in ManagedMetric wouldn’t take away its advantages. You’d keep the simple configuration for the basic use case of tracking managed resources, while enabling identity and other fields when needed.
So I believe adding projections to ManagedMetric has valuable benefits. But if you want to track specific resources, then Metric is still what you’re looking for (e.g., tracking the ready state of containers).

Yes I also think that dropping the status conditions by default would be confusing and would reduce the value of a ManagedMetric, but I also think that having complete freedom about what gets exported is very important.
So I would propose the introduction of a optional boolean parameter "includeStatusConditions", with a standard value of true. With this the ManagedMetric would be backwards compatible while enabling users like myself to have the much needed freedom of choosing what gets exportet.

@jpraychev
Copy link
Collaborator Author

Hello @christophrj and @jpraychev,

I’m currently testing the Metrics Operator for use in a production environment. As I understand it, the key difference is that a ManagedMetric automatically discovers and observes Crossplane-managed resources, whereas a Metric requires you to specify the exact Group/Version/Kind.

You can specify GVK on both but as far as I know if GVK is specified for managed metrics it will drop everything else that is different than your specified GVK and drop all resources that are not tagged as crossplane/managed.
I haven't tested if you omit the GVK for managed that it will fetch all managed resources but that is my assumption without actually debugging.

I want to track all managed resources across the clusters, including their namespace, name, and status conditions. In the future, I may also need a specific label/annotation, plus the timestamp and message from the status condition. Right now, if I want to track all managed resources and also export these fields, I am forced to create many Metrics—each with its own GVK.

If you track all managed resources through single managed metric, all resources should share the same common fields, such as conditions, namespace, names, etc.

Allowing users to define their own projections (dimensions) in ManagedMetric wouldn’t take away its advantages. You’d keep the simple configuration for the basic use case of tracking managed resources, while enabling identity and other fields when needed. So I believe adding projections to ManagedMetric has valuable benefits. But if you want to track specific resources, then Metric is still what you’re looking for (e.g., tracking the ready state of containers).

Yes I also think that dropping the status conditions by default would be confusing and would reduce the value of a ManagedMetric, but I also think that having complete freedom about what gets exported is very important. So I would propose the introduction of a optional boolean parameter "includeStatusConditions", with a standard value of true. With this the ManagedMetric would be backwards compatible while enabling users like myself to have the much needed freedom of choosing what gets exported.

Sounds fair to toggle on/off status conditions as most of the time, people might want to include them in the metric itself without explicitly specifying them - maybe not all statuses but only ready/synced state.

@Hanni007112
Copy link

You can specify GVK on both but as far as I know if GVK is specified for managed metrics it will drop everything else that is different than your specified GVK and drop all resources that are not tagged as crossplane/managed. I haven't tested if you omit the GVK for managed that it will fetch all managed resources but that is my assumption without actually debugging.

Yes that is the behaviour that i am seeing.

Sounds fair to toggle on/off status conditions as most of the time, people might want to include them in the metric itself without explicitly specifying them - maybe not all statuses but only ready/synced state.

I think that is a good idea.

@christophrj
Copy link
Contributor

instead of a user having to explicitely having to opt-in/out through a boolen flag, I would prefer it being implicitly handled depending on whether a user specifies dimension/projections or not.

  • no projections specified -> keep the old behavior
  • projections specified -> only use these

@jpraychev
Copy link
Collaborator Author

Hi @christophrj

Thinking about it, makes more sense. Let me work on that and update the PR.

@jpraychev jpraychev force-pushed the add-dimensions-managedmetrics branch from 2487993 to 222c8a4 Compare December 16, 2025 12:09
@jpraychev
Copy link
Collaborator Author

Hey @christophrj

Added the old behavior in case dimension field is not specified - if it is, user is responsible to add w/e dimensions they require.

for key, expr := range h.metric.Spec.Dimensions {
s, _, err := nestedPrimitiveValue(*u, expr)
if err != nil {
fmt.Printf("WARN: Could not parse expression '%s' for dimension field '%s'. Error: %v\n", key, expr, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the log.FromContext(ctx) logger Error() instead

dataPoint.AddDimension(t, strconv.FormatBool(state))
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: redundant empty line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ManagedMetric does not return the name of the Managed Resource

3 participants